xpc_uv.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2008-2009 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) uv-based functions.
  10. *
  11. * Architecture specific implementation of common functions.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/delay.h>
  18. #include <linux/device.h>
  19. #include <linux/cpu.h>
  20. #include <linux/module.h>
  21. #include <linux/err.h>
  22. #include <linux/slab.h>
  23. #include <linux/numa.h>
  24. #include <asm/uv/uv_hub.h>
  25. #include <asm/uv/bios.h>
  26. #include <asm/uv/uv_irq.h>
  27. #include "../sgi-gru/gru.h"
  28. #include "../sgi-gru/grukservices.h"
  29. #include "xpc.h"
  30. static struct xpc_heartbeat_uv *xpc_heartbeat_uv;
  31. #define XPC_ACTIVATE_MSG_SIZE_UV (1 * GRU_CACHE_LINE_BYTES)
  32. #define XPC_ACTIVATE_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
  33. XPC_ACTIVATE_MSG_SIZE_UV)
  34. #define XPC_ACTIVATE_IRQ_NAME "xpc_activate"
  35. #define XPC_NOTIFY_MSG_SIZE_UV (2 * GRU_CACHE_LINE_BYTES)
  36. #define XPC_NOTIFY_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
  37. XPC_NOTIFY_MSG_SIZE_UV)
  38. #define XPC_NOTIFY_IRQ_NAME "xpc_notify"
  39. static int xpc_mq_node = NUMA_NO_NODE;
  40. static struct xpc_gru_mq_uv *xpc_activate_mq_uv;
  41. static struct xpc_gru_mq_uv *xpc_notify_mq_uv;
  42. static int
  43. xpc_setup_partitions_uv(void)
  44. {
  45. short partid;
  46. struct xpc_partition_uv *part_uv;
  47. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  48. part_uv = &xpc_partitions[partid].sn.uv;
  49. mutex_init(&part_uv->cached_activate_gru_mq_desc_mutex);
  50. spin_lock_init(&part_uv->flags_lock);
  51. part_uv->remote_act_state = XPC_P_AS_INACTIVE;
  52. }
  53. return 0;
  54. }
  55. static void
  56. xpc_teardown_partitions_uv(void)
  57. {
  58. short partid;
  59. struct xpc_partition_uv *part_uv;
  60. unsigned long irq_flags;
  61. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  62. part_uv = &xpc_partitions[partid].sn.uv;
  63. if (part_uv->cached_activate_gru_mq_desc != NULL) {
  64. mutex_lock(&part_uv->cached_activate_gru_mq_desc_mutex);
  65. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  66. part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
  67. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  68. kfree(part_uv->cached_activate_gru_mq_desc);
  69. part_uv->cached_activate_gru_mq_desc = NULL;
  70. mutex_unlock(&part_uv->
  71. cached_activate_gru_mq_desc_mutex);
  72. }
  73. }
  74. }
  75. static int
  76. xpc_get_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq, int cpu, char *irq_name)
  77. {
  78. int mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
  79. mq->irq = uv_setup_irq(irq_name, cpu, mq->mmr_blade, mq->mmr_offset,
  80. UV_AFFINITY_CPU);
  81. if (mq->irq < 0)
  82. return mq->irq;
  83. mq->mmr_value = uv_read_global_mmr64(mmr_pnode, mq->mmr_offset);
  84. return 0;
  85. }
  86. static void
  87. xpc_release_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq)
  88. {
  89. uv_teardown_irq(mq->irq);
  90. }
  91. static int
  92. xpc_gru_mq_watchlist_alloc_uv(struct xpc_gru_mq_uv *mq)
  93. {
  94. int ret;
  95. ret = uv_bios_mq_watchlist_alloc(uv_gpa(mq->address),
  96. mq->order, &mq->mmr_offset);
  97. if (ret < 0) {
  98. dev_err(xpc_part, "uv_bios_mq_watchlist_alloc() failed, "
  99. "ret=%d\n", ret);
  100. return ret;
  101. }
  102. mq->watchlist_num = ret;
  103. return 0;
  104. }
  105. static void
  106. xpc_gru_mq_watchlist_free_uv(struct xpc_gru_mq_uv *mq)
  107. {
  108. int ret;
  109. int mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
  110. ret = uv_bios_mq_watchlist_free(mmr_pnode, mq->watchlist_num);
  111. BUG_ON(ret != BIOS_STATUS_SUCCESS);
  112. }
  113. static struct xpc_gru_mq_uv *
  114. xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
  115. irq_handler_t irq_handler)
  116. {
  117. enum xp_retval xp_ret;
  118. int ret;
  119. int nid;
  120. int nasid;
  121. int pg_order;
  122. struct page *page;
  123. struct xpc_gru_mq_uv *mq;
  124. struct uv_IO_APIC_route_entry *mmr_value;
  125. mq = kmalloc(sizeof(struct xpc_gru_mq_uv), GFP_KERNEL);
  126. if (mq == NULL) {
  127. dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() "
  128. "a xpc_gru_mq_uv structure\n");
  129. ret = -ENOMEM;
  130. goto out_0;
  131. }
  132. mq->gru_mq_desc = kzalloc(sizeof(struct gru_message_queue_desc),
  133. GFP_KERNEL);
  134. if (mq->gru_mq_desc == NULL) {
  135. dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() "
  136. "a gru_message_queue_desc structure\n");
  137. ret = -ENOMEM;
  138. goto out_1;
  139. }
  140. pg_order = get_order(mq_size);
  141. mq->order = pg_order + PAGE_SHIFT;
  142. mq_size = 1UL << mq->order;
  143. mq->mmr_blade = uv_cpu_to_blade_id(cpu);
  144. nid = cpu_to_node(cpu);
  145. page = __alloc_pages_node(nid,
  146. GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
  147. pg_order);
  148. if (page == NULL) {
  149. dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
  150. "bytes of memory on nid=%d for GRU mq\n", mq_size, nid);
  151. ret = -ENOMEM;
  152. goto out_2;
  153. }
  154. mq->address = page_address(page);
  155. /* enable generation of irq when GRU mq operation occurs to this mq */
  156. ret = xpc_gru_mq_watchlist_alloc_uv(mq);
  157. if (ret != 0)
  158. goto out_3;
  159. ret = xpc_get_gru_mq_irq_uv(mq, cpu, irq_name);
  160. if (ret != 0)
  161. goto out_4;
  162. ret = request_irq(mq->irq, irq_handler, 0, irq_name, NULL);
  163. if (ret != 0) {
  164. dev_err(xpc_part, "request_irq(irq=%d) returned error=%d\n",
  165. mq->irq, -ret);
  166. goto out_5;
  167. }
  168. nasid = UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpu));
  169. mmr_value = (struct uv_IO_APIC_route_entry *)&mq->mmr_value;
  170. ret = gru_create_message_queue(mq->gru_mq_desc, mq->address, mq_size,
  171. nasid, mmr_value->vector, mmr_value->dest);
  172. if (ret != 0) {
  173. dev_err(xpc_part, "gru_create_message_queue() returned "
  174. "error=%d\n", ret);
  175. ret = -EINVAL;
  176. goto out_6;
  177. }
  178. /* allow other partitions to access this GRU mq */
  179. xp_ret = xp_expand_memprotect(xp_pa(mq->address), mq_size);
  180. if (xp_ret != xpSuccess) {
  181. ret = -EACCES;
  182. goto out_6;
  183. }
  184. return mq;
  185. /* something went wrong */
  186. out_6:
  187. free_irq(mq->irq, NULL);
  188. out_5:
  189. xpc_release_gru_mq_irq_uv(mq);
  190. out_4:
  191. xpc_gru_mq_watchlist_free_uv(mq);
  192. out_3:
  193. free_pages((unsigned long)mq->address, pg_order);
  194. out_2:
  195. kfree(mq->gru_mq_desc);
  196. out_1:
  197. kfree(mq);
  198. out_0:
  199. return ERR_PTR(ret);
  200. }
  201. static void
  202. xpc_destroy_gru_mq_uv(struct xpc_gru_mq_uv *mq)
  203. {
  204. unsigned int mq_size;
  205. int pg_order;
  206. int ret;
  207. /* disallow other partitions to access GRU mq */
  208. mq_size = 1UL << mq->order;
  209. ret = xp_restrict_memprotect(xp_pa(mq->address), mq_size);
  210. BUG_ON(ret != xpSuccess);
  211. /* unregister irq handler and release mq irq/vector mapping */
  212. free_irq(mq->irq, NULL);
  213. xpc_release_gru_mq_irq_uv(mq);
  214. /* disable generation of irq when GRU mq op occurs to this mq */
  215. xpc_gru_mq_watchlist_free_uv(mq);
  216. pg_order = mq->order - PAGE_SHIFT;
  217. free_pages((unsigned long)mq->address, pg_order);
  218. kfree(mq);
  219. }
  220. static enum xp_retval
  221. xpc_send_gru_msg(struct gru_message_queue_desc *gru_mq_desc, void *msg,
  222. size_t msg_size)
  223. {
  224. enum xp_retval xp_ret;
  225. int ret;
  226. while (1) {
  227. ret = gru_send_message_gpa(gru_mq_desc, msg, msg_size);
  228. if (ret == MQE_OK) {
  229. xp_ret = xpSuccess;
  230. break;
  231. }
  232. if (ret == MQE_QUEUE_FULL) {
  233. dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
  234. "error=MQE_QUEUE_FULL\n");
  235. /* !!! handle QLimit reached; delay & try again */
  236. /* ??? Do we add a limit to the number of retries? */
  237. (void)msleep_interruptible(10);
  238. } else if (ret == MQE_CONGESTION) {
  239. dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
  240. "error=MQE_CONGESTION\n");
  241. /* !!! handle LB Overflow; simply try again */
  242. /* ??? Do we add a limit to the number of retries? */
  243. } else {
  244. /* !!! Currently this is MQE_UNEXPECTED_CB_ERR */
  245. dev_err(xpc_chan, "gru_send_message_gpa() returned "
  246. "error=%d\n", ret);
  247. xp_ret = xpGruSendMqError;
  248. break;
  249. }
  250. }
  251. return xp_ret;
  252. }
  253. static void
  254. xpc_process_activate_IRQ_rcvd_uv(void)
  255. {
  256. unsigned long irq_flags;
  257. short partid;
  258. struct xpc_partition *part;
  259. u8 act_state_req;
  260. DBUG_ON(xpc_activate_IRQ_rcvd == 0);
  261. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  262. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  263. part = &xpc_partitions[partid];
  264. if (part->sn.uv.act_state_req == 0)
  265. continue;
  266. xpc_activate_IRQ_rcvd--;
  267. BUG_ON(xpc_activate_IRQ_rcvd < 0);
  268. act_state_req = part->sn.uv.act_state_req;
  269. part->sn.uv.act_state_req = 0;
  270. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  271. if (act_state_req == XPC_P_ASR_ACTIVATE_UV) {
  272. if (part->act_state == XPC_P_AS_INACTIVE)
  273. xpc_activate_partition(part);
  274. else if (part->act_state == XPC_P_AS_DEACTIVATING)
  275. XPC_DEACTIVATE_PARTITION(part, xpReactivating);
  276. } else if (act_state_req == XPC_P_ASR_REACTIVATE_UV) {
  277. if (part->act_state == XPC_P_AS_INACTIVE)
  278. xpc_activate_partition(part);
  279. else
  280. XPC_DEACTIVATE_PARTITION(part, xpReactivating);
  281. } else if (act_state_req == XPC_P_ASR_DEACTIVATE_UV) {
  282. XPC_DEACTIVATE_PARTITION(part, part->sn.uv.reason);
  283. } else {
  284. BUG();
  285. }
  286. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  287. if (xpc_activate_IRQ_rcvd == 0)
  288. break;
  289. }
  290. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  291. }
  292. static void
  293. xpc_handle_activate_mq_msg_uv(struct xpc_partition *part,
  294. struct xpc_activate_mq_msghdr_uv *msg_hdr,
  295. int part_setup,
  296. int *wakeup_hb_checker)
  297. {
  298. unsigned long irq_flags;
  299. struct xpc_partition_uv *part_uv = &part->sn.uv;
  300. struct xpc_openclose_args *args;
  301. part_uv->remote_act_state = msg_hdr->act_state;
  302. switch (msg_hdr->type) {
  303. case XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV:
  304. /* syncing of remote_act_state was just done above */
  305. break;
  306. case XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV: {
  307. struct xpc_activate_mq_msg_activate_req_uv *msg;
  308. /*
  309. * ??? Do we deal here with ts_jiffies being different
  310. * ??? if act_state != XPC_P_AS_INACTIVE instead of
  311. * ??? below?
  312. */
  313. msg = container_of(msg_hdr, struct
  314. xpc_activate_mq_msg_activate_req_uv, hdr);
  315. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  316. if (part_uv->act_state_req == 0)
  317. xpc_activate_IRQ_rcvd++;
  318. part_uv->act_state_req = XPC_P_ASR_ACTIVATE_UV;
  319. part->remote_rp_pa = msg->rp_gpa; /* !!! _pa is _gpa */
  320. part->remote_rp_ts_jiffies = msg_hdr->rp_ts_jiffies;
  321. part_uv->heartbeat_gpa = msg->heartbeat_gpa;
  322. if (msg->activate_gru_mq_desc_gpa !=
  323. part_uv->activate_gru_mq_desc_gpa) {
  324. spin_lock(&part_uv->flags_lock);
  325. part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
  326. spin_unlock(&part_uv->flags_lock);
  327. part_uv->activate_gru_mq_desc_gpa =
  328. msg->activate_gru_mq_desc_gpa;
  329. }
  330. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  331. (*wakeup_hb_checker)++;
  332. break;
  333. }
  334. case XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV: {
  335. struct xpc_activate_mq_msg_deactivate_req_uv *msg;
  336. msg = container_of(msg_hdr, struct
  337. xpc_activate_mq_msg_deactivate_req_uv, hdr);
  338. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  339. if (part_uv->act_state_req == 0)
  340. xpc_activate_IRQ_rcvd++;
  341. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  342. part_uv->reason = msg->reason;
  343. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  344. (*wakeup_hb_checker)++;
  345. return;
  346. }
  347. case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV: {
  348. struct xpc_activate_mq_msg_chctl_closerequest_uv *msg;
  349. if (!part_setup)
  350. break;
  351. msg = container_of(msg_hdr, struct
  352. xpc_activate_mq_msg_chctl_closerequest_uv,
  353. hdr);
  354. args = &part->remote_openclose_args[msg->ch_number];
  355. args->reason = msg->reason;
  356. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  357. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREQUEST;
  358. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  359. xpc_wakeup_channel_mgr(part);
  360. break;
  361. }
  362. case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV: {
  363. struct xpc_activate_mq_msg_chctl_closereply_uv *msg;
  364. if (!part_setup)
  365. break;
  366. msg = container_of(msg_hdr, struct
  367. xpc_activate_mq_msg_chctl_closereply_uv,
  368. hdr);
  369. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  370. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREPLY;
  371. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  372. xpc_wakeup_channel_mgr(part);
  373. break;
  374. }
  375. case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV: {
  376. struct xpc_activate_mq_msg_chctl_openrequest_uv *msg;
  377. if (!part_setup)
  378. break;
  379. msg = container_of(msg_hdr, struct
  380. xpc_activate_mq_msg_chctl_openrequest_uv,
  381. hdr);
  382. args = &part->remote_openclose_args[msg->ch_number];
  383. args->entry_size = msg->entry_size;
  384. args->local_nentries = msg->local_nentries;
  385. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  386. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREQUEST;
  387. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  388. xpc_wakeup_channel_mgr(part);
  389. break;
  390. }
  391. case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV: {
  392. struct xpc_activate_mq_msg_chctl_openreply_uv *msg;
  393. if (!part_setup)
  394. break;
  395. msg = container_of(msg_hdr, struct
  396. xpc_activate_mq_msg_chctl_openreply_uv, hdr);
  397. args = &part->remote_openclose_args[msg->ch_number];
  398. args->remote_nentries = msg->remote_nentries;
  399. args->local_nentries = msg->local_nentries;
  400. args->local_msgqueue_pa = msg->notify_gru_mq_desc_gpa;
  401. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  402. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREPLY;
  403. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  404. xpc_wakeup_channel_mgr(part);
  405. break;
  406. }
  407. case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV: {
  408. struct xpc_activate_mq_msg_chctl_opencomplete_uv *msg;
  409. if (!part_setup)
  410. break;
  411. msg = container_of(msg_hdr, struct
  412. xpc_activate_mq_msg_chctl_opencomplete_uv, hdr);
  413. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  414. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENCOMPLETE;
  415. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  416. xpc_wakeup_channel_mgr(part);
  417. }
  418. fallthrough;
  419. case XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV:
  420. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  421. part_uv->flags |= XPC_P_ENGAGED_UV;
  422. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  423. break;
  424. case XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV:
  425. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  426. part_uv->flags &= ~XPC_P_ENGAGED_UV;
  427. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  428. break;
  429. default:
  430. dev_err(xpc_part, "received unknown activate_mq msg type=%d "
  431. "from partition=%d\n", msg_hdr->type, XPC_PARTID(part));
  432. /* get hb checker to deactivate from the remote partition */
  433. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  434. if (part_uv->act_state_req == 0)
  435. xpc_activate_IRQ_rcvd++;
  436. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  437. part_uv->reason = xpBadMsgType;
  438. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  439. (*wakeup_hb_checker)++;
  440. return;
  441. }
  442. if (msg_hdr->rp_ts_jiffies != part->remote_rp_ts_jiffies &&
  443. part->remote_rp_ts_jiffies != 0) {
  444. /*
  445. * ??? Does what we do here need to be sensitive to
  446. * ??? act_state or remote_act_state?
  447. */
  448. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  449. if (part_uv->act_state_req == 0)
  450. xpc_activate_IRQ_rcvd++;
  451. part_uv->act_state_req = XPC_P_ASR_REACTIVATE_UV;
  452. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  453. (*wakeup_hb_checker)++;
  454. }
  455. }
  456. static irqreturn_t
  457. xpc_handle_activate_IRQ_uv(int irq, void *dev_id)
  458. {
  459. struct xpc_activate_mq_msghdr_uv *msg_hdr;
  460. short partid;
  461. struct xpc_partition *part;
  462. int wakeup_hb_checker = 0;
  463. int part_referenced;
  464. while (1) {
  465. msg_hdr = gru_get_next_message(xpc_activate_mq_uv->gru_mq_desc);
  466. if (msg_hdr == NULL)
  467. break;
  468. partid = msg_hdr->partid;
  469. if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
  470. dev_err(xpc_part, "xpc_handle_activate_IRQ_uv() "
  471. "received invalid partid=0x%x in message\n",
  472. partid);
  473. } else {
  474. part = &xpc_partitions[partid];
  475. part_referenced = xpc_part_ref(part);
  476. xpc_handle_activate_mq_msg_uv(part, msg_hdr,
  477. part_referenced,
  478. &wakeup_hb_checker);
  479. if (part_referenced)
  480. xpc_part_deref(part);
  481. }
  482. gru_free_message(xpc_activate_mq_uv->gru_mq_desc, msg_hdr);
  483. }
  484. if (wakeup_hb_checker)
  485. wake_up_interruptible(&xpc_activate_IRQ_wq);
  486. return IRQ_HANDLED;
  487. }
  488. static enum xp_retval
  489. xpc_cache_remote_gru_mq_desc_uv(struct gru_message_queue_desc *gru_mq_desc,
  490. unsigned long gru_mq_desc_gpa)
  491. {
  492. enum xp_retval ret;
  493. ret = xp_remote_memcpy(uv_gpa(gru_mq_desc), gru_mq_desc_gpa,
  494. sizeof(struct gru_message_queue_desc));
  495. if (ret == xpSuccess)
  496. gru_mq_desc->mq = NULL;
  497. return ret;
  498. }
  499. static enum xp_retval
  500. xpc_send_activate_IRQ_uv(struct xpc_partition *part, void *msg, size_t msg_size,
  501. int msg_type)
  502. {
  503. struct xpc_activate_mq_msghdr_uv *msg_hdr = msg;
  504. struct xpc_partition_uv *part_uv = &part->sn.uv;
  505. struct gru_message_queue_desc *gru_mq_desc;
  506. unsigned long irq_flags;
  507. enum xp_retval ret;
  508. DBUG_ON(msg_size > XPC_ACTIVATE_MSG_SIZE_UV);
  509. msg_hdr->type = msg_type;
  510. msg_hdr->partid = xp_partition_id;
  511. msg_hdr->act_state = part->act_state;
  512. msg_hdr->rp_ts_jiffies = xpc_rsvd_page->ts_jiffies;
  513. mutex_lock(&part_uv->cached_activate_gru_mq_desc_mutex);
  514. again:
  515. if (!(part_uv->flags & XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV)) {
  516. gru_mq_desc = part_uv->cached_activate_gru_mq_desc;
  517. if (gru_mq_desc == NULL) {
  518. gru_mq_desc = kmalloc(sizeof(struct
  519. gru_message_queue_desc),
  520. GFP_ATOMIC);
  521. if (gru_mq_desc == NULL) {
  522. ret = xpNoMemory;
  523. goto done;
  524. }
  525. part_uv->cached_activate_gru_mq_desc = gru_mq_desc;
  526. }
  527. ret = xpc_cache_remote_gru_mq_desc_uv(gru_mq_desc,
  528. part_uv->
  529. activate_gru_mq_desc_gpa);
  530. if (ret != xpSuccess)
  531. goto done;
  532. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  533. part_uv->flags |= XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
  534. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  535. }
  536. /* ??? Is holding a spin_lock (ch->lock) during this call a bad idea? */
  537. ret = xpc_send_gru_msg(part_uv->cached_activate_gru_mq_desc, msg,
  538. msg_size);
  539. if (ret != xpSuccess) {
  540. smp_rmb(); /* ensure a fresh copy of part_uv->flags */
  541. if (!(part_uv->flags & XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV))
  542. goto again;
  543. }
  544. done:
  545. mutex_unlock(&part_uv->cached_activate_gru_mq_desc_mutex);
  546. return ret;
  547. }
  548. static void
  549. xpc_send_activate_IRQ_part_uv(struct xpc_partition *part, void *msg,
  550. size_t msg_size, int msg_type)
  551. {
  552. enum xp_retval ret;
  553. ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
  554. if (unlikely(ret != xpSuccess))
  555. XPC_DEACTIVATE_PARTITION(part, ret);
  556. }
  557. static void
  558. xpc_send_activate_IRQ_ch_uv(struct xpc_channel *ch, unsigned long *irq_flags,
  559. void *msg, size_t msg_size, int msg_type)
  560. {
  561. struct xpc_partition *part = &xpc_partitions[ch->partid];
  562. enum xp_retval ret;
  563. ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
  564. if (unlikely(ret != xpSuccess)) {
  565. if (irq_flags != NULL)
  566. spin_unlock_irqrestore(&ch->lock, *irq_flags);
  567. XPC_DEACTIVATE_PARTITION(part, ret);
  568. if (irq_flags != NULL)
  569. spin_lock_irqsave(&ch->lock, *irq_flags);
  570. }
  571. }
  572. static void
  573. xpc_send_local_activate_IRQ_uv(struct xpc_partition *part, int act_state_req)
  574. {
  575. unsigned long irq_flags;
  576. struct xpc_partition_uv *part_uv = &part->sn.uv;
  577. /*
  578. * !!! Make our side think that the remote partition sent an activate
  579. * !!! mq message our way by doing what the activate IRQ handler would
  580. * !!! do had one really been sent.
  581. */
  582. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  583. if (part_uv->act_state_req == 0)
  584. xpc_activate_IRQ_rcvd++;
  585. part_uv->act_state_req = act_state_req;
  586. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  587. wake_up_interruptible(&xpc_activate_IRQ_wq);
  588. }
  589. static enum xp_retval
  590. xpc_get_partition_rsvd_page_pa_uv(void *buf, u64 *cookie, unsigned long *rp_pa,
  591. size_t *len)
  592. {
  593. s64 status;
  594. enum xp_retval ret;
  595. status = uv_bios_reserved_page_pa((u64)buf, cookie, (u64 *)rp_pa,
  596. (u64 *)len);
  597. if (status == BIOS_STATUS_SUCCESS)
  598. ret = xpSuccess;
  599. else if (status == BIOS_STATUS_MORE_PASSES)
  600. ret = xpNeedMoreInfo;
  601. else
  602. ret = xpBiosError;
  603. return ret;
  604. }
  605. static int
  606. xpc_setup_rsvd_page_uv(struct xpc_rsvd_page *rp)
  607. {
  608. xpc_heartbeat_uv =
  609. &xpc_partitions[sn_partition_id].sn.uv.cached_heartbeat;
  610. rp->sn.uv.heartbeat_gpa = uv_gpa(xpc_heartbeat_uv);
  611. rp->sn.uv.activate_gru_mq_desc_gpa =
  612. uv_gpa(xpc_activate_mq_uv->gru_mq_desc);
  613. return 0;
  614. }
  615. static void
  616. xpc_allow_hb_uv(short partid)
  617. {
  618. }
  619. static void
  620. xpc_disallow_hb_uv(short partid)
  621. {
  622. }
  623. static void
  624. xpc_disallow_all_hbs_uv(void)
  625. {
  626. }
  627. static void
  628. xpc_increment_heartbeat_uv(void)
  629. {
  630. xpc_heartbeat_uv->value++;
  631. }
  632. static void
  633. xpc_offline_heartbeat_uv(void)
  634. {
  635. xpc_increment_heartbeat_uv();
  636. xpc_heartbeat_uv->offline = 1;
  637. }
  638. static void
  639. xpc_online_heartbeat_uv(void)
  640. {
  641. xpc_increment_heartbeat_uv();
  642. xpc_heartbeat_uv->offline = 0;
  643. }
  644. static void
  645. xpc_heartbeat_init_uv(void)
  646. {
  647. xpc_heartbeat_uv->value = 1;
  648. xpc_heartbeat_uv->offline = 0;
  649. }
  650. static void
  651. xpc_heartbeat_exit_uv(void)
  652. {
  653. xpc_offline_heartbeat_uv();
  654. }
  655. static enum xp_retval
  656. xpc_get_remote_heartbeat_uv(struct xpc_partition *part)
  657. {
  658. struct xpc_partition_uv *part_uv = &part->sn.uv;
  659. enum xp_retval ret;
  660. ret = xp_remote_memcpy(uv_gpa(&part_uv->cached_heartbeat),
  661. part_uv->heartbeat_gpa,
  662. sizeof(struct xpc_heartbeat_uv));
  663. if (ret != xpSuccess)
  664. return ret;
  665. if (part_uv->cached_heartbeat.value == part->last_heartbeat &&
  666. !part_uv->cached_heartbeat.offline) {
  667. ret = xpNoHeartbeat;
  668. } else {
  669. part->last_heartbeat = part_uv->cached_heartbeat.value;
  670. }
  671. return ret;
  672. }
  673. static void
  674. xpc_request_partition_activation_uv(struct xpc_rsvd_page *remote_rp,
  675. unsigned long remote_rp_gpa, int nasid)
  676. {
  677. short partid = remote_rp->SAL_partid;
  678. struct xpc_partition *part = &xpc_partitions[partid];
  679. struct xpc_activate_mq_msg_activate_req_uv msg;
  680. part->remote_rp_pa = remote_rp_gpa; /* !!! _pa here is really _gpa */
  681. part->remote_rp_ts_jiffies = remote_rp->ts_jiffies;
  682. part->sn.uv.heartbeat_gpa = remote_rp->sn.uv.heartbeat_gpa;
  683. part->sn.uv.activate_gru_mq_desc_gpa =
  684. remote_rp->sn.uv.activate_gru_mq_desc_gpa;
  685. /*
  686. * ??? Is it a good idea to make this conditional on what is
  687. * ??? potentially stale state information?
  688. */
  689. if (part->sn.uv.remote_act_state == XPC_P_AS_INACTIVE) {
  690. msg.rp_gpa = uv_gpa(xpc_rsvd_page);
  691. msg.heartbeat_gpa = xpc_rsvd_page->sn.uv.heartbeat_gpa;
  692. msg.activate_gru_mq_desc_gpa =
  693. xpc_rsvd_page->sn.uv.activate_gru_mq_desc_gpa;
  694. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  695. XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV);
  696. }
  697. if (part->act_state == XPC_P_AS_INACTIVE)
  698. xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
  699. }
  700. static void
  701. xpc_request_partition_reactivation_uv(struct xpc_partition *part)
  702. {
  703. xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
  704. }
  705. static void
  706. xpc_request_partition_deactivation_uv(struct xpc_partition *part)
  707. {
  708. struct xpc_activate_mq_msg_deactivate_req_uv msg;
  709. /*
  710. * ??? Is it a good idea to make this conditional on what is
  711. * ??? potentially stale state information?
  712. */
  713. if (part->sn.uv.remote_act_state != XPC_P_AS_DEACTIVATING &&
  714. part->sn.uv.remote_act_state != XPC_P_AS_INACTIVE) {
  715. msg.reason = part->reason;
  716. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  717. XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV);
  718. }
  719. }
  720. static void
  721. xpc_cancel_partition_deactivation_request_uv(struct xpc_partition *part)
  722. {
  723. /* nothing needs to be done */
  724. return;
  725. }
  726. static void
  727. xpc_init_fifo_uv(struct xpc_fifo_head_uv *head)
  728. {
  729. head->first = NULL;
  730. head->last = NULL;
  731. spin_lock_init(&head->lock);
  732. head->n_entries = 0;
  733. }
  734. static void *
  735. xpc_get_fifo_entry_uv(struct xpc_fifo_head_uv *head)
  736. {
  737. unsigned long irq_flags;
  738. struct xpc_fifo_entry_uv *first;
  739. spin_lock_irqsave(&head->lock, irq_flags);
  740. first = head->first;
  741. if (head->first != NULL) {
  742. head->first = first->next;
  743. if (head->first == NULL)
  744. head->last = NULL;
  745. head->n_entries--;
  746. BUG_ON(head->n_entries < 0);
  747. first->next = NULL;
  748. }
  749. spin_unlock_irqrestore(&head->lock, irq_flags);
  750. return first;
  751. }
  752. static void
  753. xpc_put_fifo_entry_uv(struct xpc_fifo_head_uv *head,
  754. struct xpc_fifo_entry_uv *last)
  755. {
  756. unsigned long irq_flags;
  757. last->next = NULL;
  758. spin_lock_irqsave(&head->lock, irq_flags);
  759. if (head->last != NULL)
  760. head->last->next = last;
  761. else
  762. head->first = last;
  763. head->last = last;
  764. head->n_entries++;
  765. spin_unlock_irqrestore(&head->lock, irq_flags);
  766. }
  767. static int
  768. xpc_n_of_fifo_entries_uv(struct xpc_fifo_head_uv *head)
  769. {
  770. return head->n_entries;
  771. }
  772. /*
  773. * Setup the channel structures that are uv specific.
  774. */
  775. static enum xp_retval
  776. xpc_setup_ch_structures_uv(struct xpc_partition *part)
  777. {
  778. struct xpc_channel_uv *ch_uv;
  779. int ch_number;
  780. for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
  781. ch_uv = &part->channels[ch_number].sn.uv;
  782. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  783. xpc_init_fifo_uv(&ch_uv->recv_msg_list);
  784. }
  785. return xpSuccess;
  786. }
  787. /*
  788. * Teardown the channel structures that are uv specific.
  789. */
  790. static void
  791. xpc_teardown_ch_structures_uv(struct xpc_partition *part)
  792. {
  793. /* nothing needs to be done */
  794. return;
  795. }
  796. static enum xp_retval
  797. xpc_make_first_contact_uv(struct xpc_partition *part)
  798. {
  799. struct xpc_activate_mq_msg_uv msg;
  800. /*
  801. * We send a sync msg to get the remote partition's remote_act_state
  802. * updated to our current act_state which at this point should
  803. * be XPC_P_AS_ACTIVATING.
  804. */
  805. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  806. XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV);
  807. while (!((part->sn.uv.remote_act_state == XPC_P_AS_ACTIVATING) ||
  808. (part->sn.uv.remote_act_state == XPC_P_AS_ACTIVE))) {
  809. dev_dbg(xpc_part, "waiting to make first contact with "
  810. "partition %d\n", XPC_PARTID(part));
  811. /* wait a 1/4 of a second or so */
  812. (void)msleep_interruptible(250);
  813. if (part->act_state == XPC_P_AS_DEACTIVATING)
  814. return part->reason;
  815. }
  816. return xpSuccess;
  817. }
  818. static u64
  819. xpc_get_chctl_all_flags_uv(struct xpc_partition *part)
  820. {
  821. unsigned long irq_flags;
  822. union xpc_channel_ctl_flags chctl;
  823. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  824. chctl = part->chctl;
  825. if (chctl.all_flags != 0)
  826. part->chctl.all_flags = 0;
  827. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  828. return chctl.all_flags;
  829. }
  830. static enum xp_retval
  831. xpc_allocate_send_msg_slot_uv(struct xpc_channel *ch)
  832. {
  833. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  834. struct xpc_send_msg_slot_uv *msg_slot;
  835. unsigned long irq_flags;
  836. int nentries;
  837. int entry;
  838. size_t nbytes;
  839. for (nentries = ch->local_nentries; nentries > 0; nentries--) {
  840. nbytes = nentries * sizeof(struct xpc_send_msg_slot_uv);
  841. ch_uv->send_msg_slots = kzalloc(nbytes, GFP_KERNEL);
  842. if (ch_uv->send_msg_slots == NULL)
  843. continue;
  844. for (entry = 0; entry < nentries; entry++) {
  845. msg_slot = &ch_uv->send_msg_slots[entry];
  846. msg_slot->msg_slot_number = entry;
  847. xpc_put_fifo_entry_uv(&ch_uv->msg_slot_free_list,
  848. &msg_slot->next);
  849. }
  850. spin_lock_irqsave(&ch->lock, irq_flags);
  851. if (nentries < ch->local_nentries)
  852. ch->local_nentries = nentries;
  853. spin_unlock_irqrestore(&ch->lock, irq_flags);
  854. return xpSuccess;
  855. }
  856. return xpNoMemory;
  857. }
  858. static enum xp_retval
  859. xpc_allocate_recv_msg_slot_uv(struct xpc_channel *ch)
  860. {
  861. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  862. struct xpc_notify_mq_msg_uv *msg_slot;
  863. unsigned long irq_flags;
  864. int nentries;
  865. int entry;
  866. size_t nbytes;
  867. for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
  868. nbytes = nentries * ch->entry_size;
  869. ch_uv->recv_msg_slots = kzalloc(nbytes, GFP_KERNEL);
  870. if (ch_uv->recv_msg_slots == NULL)
  871. continue;
  872. for (entry = 0; entry < nentries; entry++) {
  873. msg_slot = ch_uv->recv_msg_slots +
  874. entry * ch->entry_size;
  875. msg_slot->hdr.msg_slot_number = entry;
  876. }
  877. spin_lock_irqsave(&ch->lock, irq_flags);
  878. if (nentries < ch->remote_nentries)
  879. ch->remote_nentries = nentries;
  880. spin_unlock_irqrestore(&ch->lock, irq_flags);
  881. return xpSuccess;
  882. }
  883. return xpNoMemory;
  884. }
  885. /*
  886. * Allocate msg_slots associated with the channel.
  887. */
  888. static enum xp_retval
  889. xpc_setup_msg_structures_uv(struct xpc_channel *ch)
  890. {
  891. static enum xp_retval ret;
  892. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  893. DBUG_ON(ch->flags & XPC_C_SETUP);
  894. ch_uv->cached_notify_gru_mq_desc = kmalloc(sizeof(struct
  895. gru_message_queue_desc),
  896. GFP_KERNEL);
  897. if (ch_uv->cached_notify_gru_mq_desc == NULL)
  898. return xpNoMemory;
  899. ret = xpc_allocate_send_msg_slot_uv(ch);
  900. if (ret == xpSuccess) {
  901. ret = xpc_allocate_recv_msg_slot_uv(ch);
  902. if (ret != xpSuccess) {
  903. kfree(ch_uv->send_msg_slots);
  904. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  905. }
  906. }
  907. return ret;
  908. }
  909. /*
  910. * Free up msg_slots and clear other stuff that were setup for the specified
  911. * channel.
  912. */
  913. static void
  914. xpc_teardown_msg_structures_uv(struct xpc_channel *ch)
  915. {
  916. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  917. lockdep_assert_held(&ch->lock);
  918. kfree(ch_uv->cached_notify_gru_mq_desc);
  919. ch_uv->cached_notify_gru_mq_desc = NULL;
  920. if (ch->flags & XPC_C_SETUP) {
  921. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  922. kfree(ch_uv->send_msg_slots);
  923. xpc_init_fifo_uv(&ch_uv->recv_msg_list);
  924. kfree(ch_uv->recv_msg_slots);
  925. }
  926. }
  927. static void
  928. xpc_send_chctl_closerequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  929. {
  930. struct xpc_activate_mq_msg_chctl_closerequest_uv msg;
  931. msg.ch_number = ch->number;
  932. msg.reason = ch->reason;
  933. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  934. XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV);
  935. }
  936. static void
  937. xpc_send_chctl_closereply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  938. {
  939. struct xpc_activate_mq_msg_chctl_closereply_uv msg;
  940. msg.ch_number = ch->number;
  941. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  942. XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV);
  943. }
  944. static void
  945. xpc_send_chctl_openrequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  946. {
  947. struct xpc_activate_mq_msg_chctl_openrequest_uv msg;
  948. msg.ch_number = ch->number;
  949. msg.entry_size = ch->entry_size;
  950. msg.local_nentries = ch->local_nentries;
  951. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  952. XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV);
  953. }
  954. static void
  955. xpc_send_chctl_openreply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  956. {
  957. struct xpc_activate_mq_msg_chctl_openreply_uv msg;
  958. msg.ch_number = ch->number;
  959. msg.local_nentries = ch->local_nentries;
  960. msg.remote_nentries = ch->remote_nentries;
  961. msg.notify_gru_mq_desc_gpa = uv_gpa(xpc_notify_mq_uv->gru_mq_desc);
  962. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  963. XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV);
  964. }
  965. static void
  966. xpc_send_chctl_opencomplete_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  967. {
  968. struct xpc_activate_mq_msg_chctl_opencomplete_uv msg;
  969. msg.ch_number = ch->number;
  970. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  971. XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV);
  972. }
  973. static void
  974. xpc_send_chctl_local_msgrequest_uv(struct xpc_partition *part, int ch_number)
  975. {
  976. unsigned long irq_flags;
  977. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  978. part->chctl.flags[ch_number] |= XPC_CHCTL_MSGREQUEST;
  979. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  980. xpc_wakeup_channel_mgr(part);
  981. }
  982. static enum xp_retval
  983. xpc_save_remote_msgqueue_pa_uv(struct xpc_channel *ch,
  984. unsigned long gru_mq_desc_gpa)
  985. {
  986. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  987. DBUG_ON(ch_uv->cached_notify_gru_mq_desc == NULL);
  988. return xpc_cache_remote_gru_mq_desc_uv(ch_uv->cached_notify_gru_mq_desc,
  989. gru_mq_desc_gpa);
  990. }
  991. static void
  992. xpc_indicate_partition_engaged_uv(struct xpc_partition *part)
  993. {
  994. struct xpc_activate_mq_msg_uv msg;
  995. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  996. XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV);
  997. }
  998. static void
  999. xpc_indicate_partition_disengaged_uv(struct xpc_partition *part)
  1000. {
  1001. struct xpc_activate_mq_msg_uv msg;
  1002. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  1003. XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV);
  1004. }
  1005. static void
  1006. xpc_assume_partition_disengaged_uv(short partid)
  1007. {
  1008. struct xpc_partition_uv *part_uv = &xpc_partitions[partid].sn.uv;
  1009. unsigned long irq_flags;
  1010. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  1011. part_uv->flags &= ~XPC_P_ENGAGED_UV;
  1012. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  1013. }
  1014. static int
  1015. xpc_partition_engaged_uv(short partid)
  1016. {
  1017. return (xpc_partitions[partid].sn.uv.flags & XPC_P_ENGAGED_UV) != 0;
  1018. }
  1019. static int
  1020. xpc_any_partition_engaged_uv(void)
  1021. {
  1022. struct xpc_partition_uv *part_uv;
  1023. short partid;
  1024. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  1025. part_uv = &xpc_partitions[partid].sn.uv;
  1026. if ((part_uv->flags & XPC_P_ENGAGED_UV) != 0)
  1027. return 1;
  1028. }
  1029. return 0;
  1030. }
  1031. static enum xp_retval
  1032. xpc_allocate_msg_slot_uv(struct xpc_channel *ch, u32 flags,
  1033. struct xpc_send_msg_slot_uv **address_of_msg_slot)
  1034. {
  1035. enum xp_retval ret;
  1036. struct xpc_send_msg_slot_uv *msg_slot;
  1037. struct xpc_fifo_entry_uv *entry;
  1038. while (1) {
  1039. entry = xpc_get_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list);
  1040. if (entry != NULL)
  1041. break;
  1042. if (flags & XPC_NOWAIT)
  1043. return xpNoWait;
  1044. ret = xpc_allocate_msg_wait(ch);
  1045. if (ret != xpInterrupted && ret != xpTimeout)
  1046. return ret;
  1047. }
  1048. msg_slot = container_of(entry, struct xpc_send_msg_slot_uv, next);
  1049. *address_of_msg_slot = msg_slot;
  1050. return xpSuccess;
  1051. }
  1052. static void
  1053. xpc_free_msg_slot_uv(struct xpc_channel *ch,
  1054. struct xpc_send_msg_slot_uv *msg_slot)
  1055. {
  1056. xpc_put_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list, &msg_slot->next);
  1057. /* wakeup anyone waiting for a free msg slot */
  1058. if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
  1059. wake_up(&ch->msg_allocate_wq);
  1060. }
  1061. static void
  1062. xpc_notify_sender_uv(struct xpc_channel *ch,
  1063. struct xpc_send_msg_slot_uv *msg_slot,
  1064. enum xp_retval reason)
  1065. {
  1066. xpc_notify_func func = msg_slot->func;
  1067. if (func != NULL && cmpxchg(&msg_slot->func, func, NULL) == func) {
  1068. atomic_dec(&ch->n_to_notify);
  1069. dev_dbg(xpc_chan, "msg_slot->func() called, msg_slot=0x%p "
  1070. "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
  1071. msg_slot->msg_slot_number, ch->partid, ch->number);
  1072. func(reason, ch->partid, ch->number, msg_slot->key);
  1073. dev_dbg(xpc_chan, "msg_slot->func() returned, msg_slot=0x%p "
  1074. "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
  1075. msg_slot->msg_slot_number, ch->partid, ch->number);
  1076. }
  1077. }
  1078. static void
  1079. xpc_handle_notify_mq_ack_uv(struct xpc_channel *ch,
  1080. struct xpc_notify_mq_msg_uv *msg)
  1081. {
  1082. struct xpc_send_msg_slot_uv *msg_slot;
  1083. int entry = msg->hdr.msg_slot_number % ch->local_nentries;
  1084. msg_slot = &ch->sn.uv.send_msg_slots[entry];
  1085. BUG_ON(msg_slot->msg_slot_number != msg->hdr.msg_slot_number);
  1086. msg_slot->msg_slot_number += ch->local_nentries;
  1087. if (msg_slot->func != NULL)
  1088. xpc_notify_sender_uv(ch, msg_slot, xpMsgDelivered);
  1089. xpc_free_msg_slot_uv(ch, msg_slot);
  1090. }
  1091. static void
  1092. xpc_handle_notify_mq_msg_uv(struct xpc_partition *part,
  1093. struct xpc_notify_mq_msg_uv *msg)
  1094. {
  1095. struct xpc_partition_uv *part_uv = &part->sn.uv;
  1096. struct xpc_channel *ch;
  1097. struct xpc_channel_uv *ch_uv;
  1098. struct xpc_notify_mq_msg_uv *msg_slot;
  1099. unsigned long irq_flags;
  1100. int ch_number = msg->hdr.ch_number;
  1101. if (unlikely(ch_number >= part->nchannels)) {
  1102. dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received invalid "
  1103. "channel number=0x%x in message from partid=%d\n",
  1104. ch_number, XPC_PARTID(part));
  1105. /* get hb checker to deactivate from the remote partition */
  1106. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  1107. if (part_uv->act_state_req == 0)
  1108. xpc_activate_IRQ_rcvd++;
  1109. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  1110. part_uv->reason = xpBadChannelNumber;
  1111. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  1112. wake_up_interruptible(&xpc_activate_IRQ_wq);
  1113. return;
  1114. }
  1115. ch = &part->channels[ch_number];
  1116. xpc_msgqueue_ref(ch);
  1117. if (!(ch->flags & XPC_C_CONNECTED)) {
  1118. xpc_msgqueue_deref(ch);
  1119. return;
  1120. }
  1121. /* see if we're really dealing with an ACK for a previously sent msg */
  1122. if (msg->hdr.size == 0) {
  1123. xpc_handle_notify_mq_ack_uv(ch, msg);
  1124. xpc_msgqueue_deref(ch);
  1125. return;
  1126. }
  1127. /* we're dealing with a normal message sent via the notify_mq */
  1128. ch_uv = &ch->sn.uv;
  1129. msg_slot = ch_uv->recv_msg_slots +
  1130. (msg->hdr.msg_slot_number % ch->remote_nentries) * ch->entry_size;
  1131. BUG_ON(msg_slot->hdr.size != 0);
  1132. memcpy(msg_slot, msg, msg->hdr.size);
  1133. xpc_put_fifo_entry_uv(&ch_uv->recv_msg_list, &msg_slot->hdr.u.next);
  1134. if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) {
  1135. /*
  1136. * If there is an existing idle kthread get it to deliver
  1137. * the payload, otherwise we'll have to get the channel mgr
  1138. * for this partition to create a kthread to do the delivery.
  1139. */
  1140. if (atomic_read(&ch->kthreads_idle) > 0)
  1141. wake_up_nr(&ch->idle_wq, 1);
  1142. else
  1143. xpc_send_chctl_local_msgrequest_uv(part, ch->number);
  1144. }
  1145. xpc_msgqueue_deref(ch);
  1146. }
  1147. static irqreturn_t
  1148. xpc_handle_notify_IRQ_uv(int irq, void *dev_id)
  1149. {
  1150. struct xpc_notify_mq_msg_uv *msg;
  1151. short partid;
  1152. struct xpc_partition *part;
  1153. while ((msg = gru_get_next_message(xpc_notify_mq_uv->gru_mq_desc)) !=
  1154. NULL) {
  1155. partid = msg->hdr.partid;
  1156. if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
  1157. dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received "
  1158. "invalid partid=0x%x in message\n", partid);
  1159. } else {
  1160. part = &xpc_partitions[partid];
  1161. if (xpc_part_ref(part)) {
  1162. xpc_handle_notify_mq_msg_uv(part, msg);
  1163. xpc_part_deref(part);
  1164. }
  1165. }
  1166. gru_free_message(xpc_notify_mq_uv->gru_mq_desc, msg);
  1167. }
  1168. return IRQ_HANDLED;
  1169. }
  1170. static int
  1171. xpc_n_of_deliverable_payloads_uv(struct xpc_channel *ch)
  1172. {
  1173. return xpc_n_of_fifo_entries_uv(&ch->sn.uv.recv_msg_list);
  1174. }
  1175. static void
  1176. xpc_process_msg_chctl_flags_uv(struct xpc_partition *part, int ch_number)
  1177. {
  1178. struct xpc_channel *ch = &part->channels[ch_number];
  1179. int ndeliverable_payloads;
  1180. xpc_msgqueue_ref(ch);
  1181. ndeliverable_payloads = xpc_n_of_deliverable_payloads_uv(ch);
  1182. if (ndeliverable_payloads > 0 &&
  1183. (ch->flags & XPC_C_CONNECTED) &&
  1184. (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE)) {
  1185. xpc_activate_kthreads(ch, ndeliverable_payloads);
  1186. }
  1187. xpc_msgqueue_deref(ch);
  1188. }
  1189. static enum xp_retval
  1190. xpc_send_payload_uv(struct xpc_channel *ch, u32 flags, void *payload,
  1191. u16 payload_size, u8 notify_type, xpc_notify_func func,
  1192. void *key)
  1193. {
  1194. enum xp_retval ret = xpSuccess;
  1195. struct xpc_send_msg_slot_uv *msg_slot = NULL;
  1196. struct xpc_notify_mq_msg_uv *msg;
  1197. u8 msg_buffer[XPC_NOTIFY_MSG_SIZE_UV];
  1198. size_t msg_size;
  1199. DBUG_ON(notify_type != XPC_N_CALL);
  1200. msg_size = sizeof(struct xpc_notify_mq_msghdr_uv) + payload_size;
  1201. if (msg_size > ch->entry_size)
  1202. return xpPayloadTooBig;
  1203. xpc_msgqueue_ref(ch);
  1204. if (ch->flags & XPC_C_DISCONNECTING) {
  1205. ret = ch->reason;
  1206. goto out_1;
  1207. }
  1208. if (!(ch->flags & XPC_C_CONNECTED)) {
  1209. ret = xpNotConnected;
  1210. goto out_1;
  1211. }
  1212. ret = xpc_allocate_msg_slot_uv(ch, flags, &msg_slot);
  1213. if (ret != xpSuccess)
  1214. goto out_1;
  1215. if (func != NULL) {
  1216. atomic_inc(&ch->n_to_notify);
  1217. msg_slot->key = key;
  1218. smp_wmb(); /* a non-NULL func must hit memory after the key */
  1219. msg_slot->func = func;
  1220. if (ch->flags & XPC_C_DISCONNECTING) {
  1221. ret = ch->reason;
  1222. goto out_2;
  1223. }
  1224. }
  1225. msg = (struct xpc_notify_mq_msg_uv *)&msg_buffer;
  1226. msg->hdr.partid = xp_partition_id;
  1227. msg->hdr.ch_number = ch->number;
  1228. msg->hdr.size = msg_size;
  1229. msg->hdr.msg_slot_number = msg_slot->msg_slot_number;
  1230. memcpy(&msg->payload, payload, payload_size);
  1231. ret = xpc_send_gru_msg(ch->sn.uv.cached_notify_gru_mq_desc, msg,
  1232. msg_size);
  1233. if (ret == xpSuccess)
  1234. goto out_1;
  1235. XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
  1236. out_2:
  1237. if (func != NULL) {
  1238. /*
  1239. * Try to NULL the msg_slot's func field. If we fail, then
  1240. * xpc_notify_senders_of_disconnect_uv() beat us to it, in which
  1241. * case we need to pretend we succeeded to send the message
  1242. * since the user will get a callout for the disconnect error
  1243. * by xpc_notify_senders_of_disconnect_uv(), and to also get an
  1244. * error returned here will confuse them. Additionally, since
  1245. * in this case the channel is being disconnected we don't need
  1246. * to put the msg_slot back on the free list.
  1247. */
  1248. if (cmpxchg(&msg_slot->func, func, NULL) != func) {
  1249. ret = xpSuccess;
  1250. goto out_1;
  1251. }
  1252. msg_slot->key = NULL;
  1253. atomic_dec(&ch->n_to_notify);
  1254. }
  1255. xpc_free_msg_slot_uv(ch, msg_slot);
  1256. out_1:
  1257. xpc_msgqueue_deref(ch);
  1258. return ret;
  1259. }
  1260. /*
  1261. * Tell the callers of xpc_send_notify() that the status of their payloads
  1262. * is unknown because the channel is now disconnecting.
  1263. *
  1264. * We don't worry about putting these msg_slots on the free list since the
  1265. * msg_slots themselves are about to be kfree'd.
  1266. */
  1267. static void
  1268. xpc_notify_senders_of_disconnect_uv(struct xpc_channel *ch)
  1269. {
  1270. struct xpc_send_msg_slot_uv *msg_slot;
  1271. int entry;
  1272. DBUG_ON(!(ch->flags & XPC_C_DISCONNECTING));
  1273. for (entry = 0; entry < ch->local_nentries; entry++) {
  1274. if (atomic_read(&ch->n_to_notify) == 0)
  1275. break;
  1276. msg_slot = &ch->sn.uv.send_msg_slots[entry];
  1277. if (msg_slot->func != NULL)
  1278. xpc_notify_sender_uv(ch, msg_slot, ch->reason);
  1279. }
  1280. }
  1281. /*
  1282. * Get the next deliverable message's payload.
  1283. */
  1284. static void *
  1285. xpc_get_deliverable_payload_uv(struct xpc_channel *ch)
  1286. {
  1287. struct xpc_fifo_entry_uv *entry;
  1288. struct xpc_notify_mq_msg_uv *msg;
  1289. void *payload = NULL;
  1290. if (!(ch->flags & XPC_C_DISCONNECTING)) {
  1291. entry = xpc_get_fifo_entry_uv(&ch->sn.uv.recv_msg_list);
  1292. if (entry != NULL) {
  1293. msg = container_of(entry, struct xpc_notify_mq_msg_uv,
  1294. hdr.u.next);
  1295. payload = &msg->payload;
  1296. }
  1297. }
  1298. return payload;
  1299. }
  1300. static void
  1301. xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
  1302. {
  1303. struct xpc_notify_mq_msg_uv *msg;
  1304. enum xp_retval ret;
  1305. msg = container_of(payload, struct xpc_notify_mq_msg_uv, payload);
  1306. /* return an ACK to the sender of this message */
  1307. msg->hdr.partid = xp_partition_id;
  1308. msg->hdr.size = 0; /* size of zero indicates this is an ACK */
  1309. ret = xpc_send_gru_msg(ch->sn.uv.cached_notify_gru_mq_desc, msg,
  1310. sizeof(struct xpc_notify_mq_msghdr_uv));
  1311. if (ret != xpSuccess)
  1312. XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
  1313. }
  1314. static const struct xpc_arch_operations xpc_arch_ops_uv = {
  1315. .setup_partitions = xpc_setup_partitions_uv,
  1316. .teardown_partitions = xpc_teardown_partitions_uv,
  1317. .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
  1318. .get_partition_rsvd_page_pa = xpc_get_partition_rsvd_page_pa_uv,
  1319. .setup_rsvd_page = xpc_setup_rsvd_page_uv,
  1320. .allow_hb = xpc_allow_hb_uv,
  1321. .disallow_hb = xpc_disallow_hb_uv,
  1322. .disallow_all_hbs = xpc_disallow_all_hbs_uv,
  1323. .increment_heartbeat = xpc_increment_heartbeat_uv,
  1324. .offline_heartbeat = xpc_offline_heartbeat_uv,
  1325. .online_heartbeat = xpc_online_heartbeat_uv,
  1326. .heartbeat_init = xpc_heartbeat_init_uv,
  1327. .heartbeat_exit = xpc_heartbeat_exit_uv,
  1328. .get_remote_heartbeat = xpc_get_remote_heartbeat_uv,
  1329. .request_partition_activation =
  1330. xpc_request_partition_activation_uv,
  1331. .request_partition_reactivation =
  1332. xpc_request_partition_reactivation_uv,
  1333. .request_partition_deactivation =
  1334. xpc_request_partition_deactivation_uv,
  1335. .cancel_partition_deactivation_request =
  1336. xpc_cancel_partition_deactivation_request_uv,
  1337. .setup_ch_structures = xpc_setup_ch_structures_uv,
  1338. .teardown_ch_structures = xpc_teardown_ch_structures_uv,
  1339. .make_first_contact = xpc_make_first_contact_uv,
  1340. .get_chctl_all_flags = xpc_get_chctl_all_flags_uv,
  1341. .send_chctl_closerequest = xpc_send_chctl_closerequest_uv,
  1342. .send_chctl_closereply = xpc_send_chctl_closereply_uv,
  1343. .send_chctl_openrequest = xpc_send_chctl_openrequest_uv,
  1344. .send_chctl_openreply = xpc_send_chctl_openreply_uv,
  1345. .send_chctl_opencomplete = xpc_send_chctl_opencomplete_uv,
  1346. .process_msg_chctl_flags = xpc_process_msg_chctl_flags_uv,
  1347. .save_remote_msgqueue_pa = xpc_save_remote_msgqueue_pa_uv,
  1348. .setup_msg_structures = xpc_setup_msg_structures_uv,
  1349. .teardown_msg_structures = xpc_teardown_msg_structures_uv,
  1350. .indicate_partition_engaged = xpc_indicate_partition_engaged_uv,
  1351. .indicate_partition_disengaged = xpc_indicate_partition_disengaged_uv,
  1352. .assume_partition_disengaged = xpc_assume_partition_disengaged_uv,
  1353. .partition_engaged = xpc_partition_engaged_uv,
  1354. .any_partition_engaged = xpc_any_partition_engaged_uv,
  1355. .n_of_deliverable_payloads = xpc_n_of_deliverable_payloads_uv,
  1356. .send_payload = xpc_send_payload_uv,
  1357. .get_deliverable_payload = xpc_get_deliverable_payload_uv,
  1358. .received_payload = xpc_received_payload_uv,
  1359. .notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_uv,
  1360. };
  1361. static int
  1362. xpc_init_mq_node(int nid)
  1363. {
  1364. int cpu;
  1365. cpus_read_lock();
  1366. for_each_cpu(cpu, cpumask_of_node(nid)) {
  1367. xpc_activate_mq_uv =
  1368. xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, nid,
  1369. XPC_ACTIVATE_IRQ_NAME,
  1370. xpc_handle_activate_IRQ_uv);
  1371. if (!IS_ERR(xpc_activate_mq_uv))
  1372. break;
  1373. }
  1374. if (IS_ERR(xpc_activate_mq_uv)) {
  1375. cpus_read_unlock();
  1376. return PTR_ERR(xpc_activate_mq_uv);
  1377. }
  1378. for_each_cpu(cpu, cpumask_of_node(nid)) {
  1379. xpc_notify_mq_uv =
  1380. xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, nid,
  1381. XPC_NOTIFY_IRQ_NAME,
  1382. xpc_handle_notify_IRQ_uv);
  1383. if (!IS_ERR(xpc_notify_mq_uv))
  1384. break;
  1385. }
  1386. if (IS_ERR(xpc_notify_mq_uv)) {
  1387. xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
  1388. cpus_read_unlock();
  1389. return PTR_ERR(xpc_notify_mq_uv);
  1390. }
  1391. cpus_read_unlock();
  1392. return 0;
  1393. }
  1394. int
  1395. xpc_init_uv(void)
  1396. {
  1397. int nid;
  1398. int ret = 0;
  1399. xpc_arch_ops = xpc_arch_ops_uv;
  1400. if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
  1401. dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
  1402. XPC_MSG_HDR_MAX_SIZE);
  1403. return -E2BIG;
  1404. }
  1405. if (xpc_mq_node < 0)
  1406. for_each_online_node(nid) {
  1407. ret = xpc_init_mq_node(nid);
  1408. if (!ret)
  1409. break;
  1410. }
  1411. else
  1412. ret = xpc_init_mq_node(xpc_mq_node);
  1413. if (ret < 0)
  1414. dev_err(xpc_part, "xpc_init_mq_node() returned error=%d\n",
  1415. -ret);
  1416. return ret;
  1417. }
  1418. void
  1419. xpc_exit_uv(void)
  1420. {
  1421. xpc_destroy_gru_mq_uv(xpc_notify_mq_uv);
  1422. xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
  1423. }
  1424. module_param(xpc_mq_node, int, 0);
  1425. MODULE_PARM_DESC(xpc_mq_node, "Node number on which to allocate message queues.");