xpc_uv.c 46 KB

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