xpc_uv.c 46 KB

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