xpc_uv.c 46 KB

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