xpc_uv.c 46 KB

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