xpc_uv.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 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 <asm/uv/uv_hub.h>
  20. #include "../sgi-gru/gru.h"
  21. #include "../sgi-gru/grukservices.h"
  22. #include "xpc.h"
  23. static atomic64_t xpc_heartbeat_uv;
  24. static DECLARE_BITMAP(xpc_heartbeating_to_mask_uv, XP_MAX_NPARTITIONS_UV);
  25. #define XPC_ACTIVATE_MSG_SIZE_UV (1 * GRU_CACHE_LINE_BYTES)
  26. #define XPC_NOTIFY_MSG_SIZE_UV (2 * GRU_CACHE_LINE_BYTES)
  27. #define XPC_ACTIVATE_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
  28. XPC_ACTIVATE_MSG_SIZE_UV)
  29. #define XPC_NOTIFY_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
  30. XPC_NOTIFY_MSG_SIZE_UV)
  31. static void *xpc_activate_mq_uv;
  32. static void *xpc_notify_mq_uv;
  33. static int
  34. xpc_setup_partitions_sn_uv(void)
  35. {
  36. short partid;
  37. struct xpc_partition_uv *part_uv;
  38. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  39. part_uv = &xpc_partitions[partid].sn.uv;
  40. spin_lock_init(&part_uv->flags_lock);
  41. part_uv->remote_act_state = XPC_P_AS_INACTIVE;
  42. }
  43. return 0;
  44. }
  45. static void *
  46. xpc_create_gru_mq_uv(unsigned int mq_size, int cpuid, unsigned int irq,
  47. irq_handler_t irq_handler)
  48. {
  49. int ret;
  50. int nid;
  51. int mq_order;
  52. struct page *page;
  53. void *mq;
  54. nid = cpu_to_node(cpuid);
  55. mq_order = get_order(mq_size);
  56. page = alloc_pages_node(nid, GFP_KERNEL | __GFP_ZERO | GFP_THISNODE,
  57. mq_order);
  58. if (page == NULL) {
  59. dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
  60. "bytes of memory on nid=%d for GRU mq\n", mq_size, nid);
  61. return NULL;
  62. }
  63. mq = page_address(page);
  64. ret = gru_create_message_queue(mq, mq_size);
  65. if (ret != 0) {
  66. dev_err(xpc_part, "gru_create_message_queue() returned "
  67. "error=%d\n", ret);
  68. free_pages((unsigned long)mq, mq_order);
  69. return NULL;
  70. }
  71. /* !!! Need to do some other things to set up IRQ */
  72. ret = request_irq(irq, irq_handler, 0, "xpc", NULL);
  73. if (ret != 0) {
  74. dev_err(xpc_part, "request_irq(irq=%d) returned error=%d\n",
  75. irq, ret);
  76. free_pages((unsigned long)mq, mq_order);
  77. return NULL;
  78. }
  79. /* !!! enable generation of irq when GRU mq op occurs to this mq */
  80. /* ??? allow other partitions to access GRU mq? */
  81. return mq;
  82. }
  83. static void
  84. xpc_destroy_gru_mq_uv(void *mq, unsigned int mq_size, unsigned int irq)
  85. {
  86. /* ??? disallow other partitions to access GRU mq? */
  87. /* !!! disable generation of irq when GRU mq op occurs to this mq */
  88. free_irq(irq, NULL);
  89. free_pages((unsigned long)mq, get_order(mq_size));
  90. }
  91. static enum xp_retval
  92. xpc_send_gru_msg(unsigned long mq_gpa, void *msg, size_t msg_size)
  93. {
  94. enum xp_retval xp_ret;
  95. int ret;
  96. while (1) {
  97. ret = gru_send_message_gpa(mq_gpa, msg, msg_size);
  98. if (ret == MQE_OK) {
  99. xp_ret = xpSuccess;
  100. break;
  101. }
  102. if (ret == MQE_QUEUE_FULL) {
  103. dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
  104. "error=MQE_QUEUE_FULL\n");
  105. /* !!! handle QLimit reached; delay & try again */
  106. /* ??? Do we add a limit to the number of retries? */
  107. (void)msleep_interruptible(10);
  108. } else if (ret == MQE_CONGESTION) {
  109. dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
  110. "error=MQE_CONGESTION\n");
  111. /* !!! handle LB Overflow; simply try again */
  112. /* ??? Do we add a limit to the number of retries? */
  113. } else {
  114. /* !!! Currently this is MQE_UNEXPECTED_CB_ERR */
  115. dev_err(xpc_chan, "gru_send_message_gpa() returned "
  116. "error=%d\n", ret);
  117. xp_ret = xpGruSendMqError;
  118. break;
  119. }
  120. }
  121. return xp_ret;
  122. }
  123. static void
  124. xpc_process_activate_IRQ_rcvd_uv(void)
  125. {
  126. unsigned long irq_flags;
  127. short partid;
  128. struct xpc_partition *part;
  129. u8 act_state_req;
  130. DBUG_ON(xpc_activate_IRQ_rcvd == 0);
  131. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  132. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  133. part = &xpc_partitions[partid];
  134. if (part->sn.uv.act_state_req == 0)
  135. continue;
  136. xpc_activate_IRQ_rcvd--;
  137. BUG_ON(xpc_activate_IRQ_rcvd < 0);
  138. act_state_req = part->sn.uv.act_state_req;
  139. part->sn.uv.act_state_req = 0;
  140. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  141. if (act_state_req == XPC_P_ASR_ACTIVATE_UV) {
  142. if (part->act_state == XPC_P_AS_INACTIVE)
  143. xpc_activate_partition(part);
  144. else if (part->act_state == XPC_P_AS_DEACTIVATING)
  145. XPC_DEACTIVATE_PARTITION(part, xpReactivating);
  146. } else if (act_state_req == XPC_P_ASR_REACTIVATE_UV) {
  147. if (part->act_state == XPC_P_AS_INACTIVE)
  148. xpc_activate_partition(part);
  149. else
  150. XPC_DEACTIVATE_PARTITION(part, xpReactivating);
  151. } else if (act_state_req == XPC_P_ASR_DEACTIVATE_UV) {
  152. XPC_DEACTIVATE_PARTITION(part, part->sn.uv.reason);
  153. } else {
  154. BUG();
  155. }
  156. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  157. if (xpc_activate_IRQ_rcvd == 0)
  158. break;
  159. }
  160. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  161. }
  162. static void
  163. xpc_handle_activate_mq_msg_uv(struct xpc_partition *part,
  164. struct xpc_activate_mq_msghdr_uv *msg_hdr,
  165. int *wakeup_hb_checker)
  166. {
  167. unsigned long irq_flags;
  168. struct xpc_partition_uv *part_uv = &part->sn.uv;
  169. struct xpc_openclose_args *args;
  170. part_uv->remote_act_state = msg_hdr->act_state;
  171. switch (msg_hdr->type) {
  172. case XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV:
  173. /* syncing of remote_act_state was just done above */
  174. break;
  175. case XPC_ACTIVATE_MQ_MSG_INC_HEARTBEAT_UV: {
  176. struct xpc_activate_mq_msg_heartbeat_req_uv *msg;
  177. msg = container_of(msg_hdr,
  178. struct xpc_activate_mq_msg_heartbeat_req_uv,
  179. hdr);
  180. part_uv->heartbeat = msg->heartbeat;
  181. break;
  182. }
  183. case XPC_ACTIVATE_MQ_MSG_OFFLINE_HEARTBEAT_UV: {
  184. struct xpc_activate_mq_msg_heartbeat_req_uv *msg;
  185. msg = container_of(msg_hdr,
  186. struct xpc_activate_mq_msg_heartbeat_req_uv,
  187. hdr);
  188. part_uv->heartbeat = msg->heartbeat;
  189. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  190. part_uv->flags |= XPC_P_HEARTBEAT_OFFLINE_UV;
  191. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  192. break;
  193. }
  194. case XPC_ACTIVATE_MQ_MSG_ONLINE_HEARTBEAT_UV: {
  195. struct xpc_activate_mq_msg_heartbeat_req_uv *msg;
  196. msg = container_of(msg_hdr,
  197. struct xpc_activate_mq_msg_heartbeat_req_uv,
  198. hdr);
  199. part_uv->heartbeat = msg->heartbeat;
  200. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  201. part_uv->flags &= ~XPC_P_HEARTBEAT_OFFLINE_UV;
  202. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  203. break;
  204. }
  205. case XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV: {
  206. struct xpc_activate_mq_msg_activate_req_uv *msg;
  207. /*
  208. * ??? Do we deal here with ts_jiffies being different
  209. * ??? if act_state != XPC_P_AS_INACTIVE instead of
  210. * ??? below?
  211. */
  212. msg = container_of(msg_hdr, struct
  213. xpc_activate_mq_msg_activate_req_uv, hdr);
  214. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  215. if (part_uv->act_state_req == 0)
  216. xpc_activate_IRQ_rcvd++;
  217. part_uv->act_state_req = XPC_P_ASR_ACTIVATE_UV;
  218. part->remote_rp_pa = msg->rp_gpa; /* !!! _pa is _gpa */
  219. part->remote_rp_ts_jiffies = msg_hdr->rp_ts_jiffies;
  220. part_uv->remote_activate_mq_gpa = msg->activate_mq_gpa;
  221. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  222. (*wakeup_hb_checker)++;
  223. break;
  224. }
  225. case XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV: {
  226. struct xpc_activate_mq_msg_deactivate_req_uv *msg;
  227. msg = container_of(msg_hdr, struct
  228. xpc_activate_mq_msg_deactivate_req_uv, hdr);
  229. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  230. if (part_uv->act_state_req == 0)
  231. xpc_activate_IRQ_rcvd++;
  232. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  233. part_uv->reason = msg->reason;
  234. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  235. (*wakeup_hb_checker)++;
  236. return;
  237. }
  238. case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV: {
  239. struct xpc_activate_mq_msg_chctl_closerequest_uv *msg;
  240. msg = container_of(msg_hdr, struct
  241. xpc_activate_mq_msg_chctl_closerequest_uv,
  242. hdr);
  243. args = &part->remote_openclose_args[msg->ch_number];
  244. args->reason = msg->reason;
  245. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  246. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREQUEST;
  247. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  248. xpc_wakeup_channel_mgr(part);
  249. break;
  250. }
  251. case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV: {
  252. struct xpc_activate_mq_msg_chctl_closereply_uv *msg;
  253. msg = container_of(msg_hdr, struct
  254. xpc_activate_mq_msg_chctl_closereply_uv,
  255. hdr);
  256. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  257. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREPLY;
  258. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  259. xpc_wakeup_channel_mgr(part);
  260. break;
  261. }
  262. case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV: {
  263. struct xpc_activate_mq_msg_chctl_openrequest_uv *msg;
  264. msg = container_of(msg_hdr, struct
  265. xpc_activate_mq_msg_chctl_openrequest_uv,
  266. hdr);
  267. args = &part->remote_openclose_args[msg->ch_number];
  268. args->entry_size = msg->entry_size;
  269. args->local_nentries = msg->local_nentries;
  270. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  271. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREQUEST;
  272. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  273. xpc_wakeup_channel_mgr(part);
  274. break;
  275. }
  276. case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV: {
  277. struct xpc_activate_mq_msg_chctl_openreply_uv *msg;
  278. msg = container_of(msg_hdr, struct
  279. xpc_activate_mq_msg_chctl_openreply_uv, hdr);
  280. args = &part->remote_openclose_args[msg->ch_number];
  281. args->remote_nentries = msg->remote_nentries;
  282. args->local_nentries = msg->local_nentries;
  283. args->local_msgqueue_pa = msg->local_notify_mq_gpa;
  284. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  285. part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREPLY;
  286. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  287. xpc_wakeup_channel_mgr(part);
  288. break;
  289. }
  290. case XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV:
  291. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  292. part_uv->flags |= XPC_P_ENGAGED_UV;
  293. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  294. break;
  295. case XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV:
  296. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  297. part_uv->flags &= ~XPC_P_ENGAGED_UV;
  298. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  299. break;
  300. default:
  301. dev_err(xpc_part, "received unknown activate_mq msg type=%d "
  302. "from partition=%d\n", msg_hdr->type, XPC_PARTID(part));
  303. /* get hb checker to deactivate from the remote partition */
  304. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  305. if (part_uv->act_state_req == 0)
  306. xpc_activate_IRQ_rcvd++;
  307. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  308. part_uv->reason = xpBadMsgType;
  309. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  310. (*wakeup_hb_checker)++;
  311. return;
  312. }
  313. if (msg_hdr->rp_ts_jiffies != part->remote_rp_ts_jiffies &&
  314. part->remote_rp_ts_jiffies != 0) {
  315. /*
  316. * ??? Does what we do here need to be sensitive to
  317. * ??? act_state or remote_act_state?
  318. */
  319. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  320. if (part_uv->act_state_req == 0)
  321. xpc_activate_IRQ_rcvd++;
  322. part_uv->act_state_req = XPC_P_ASR_REACTIVATE_UV;
  323. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  324. (*wakeup_hb_checker)++;
  325. }
  326. }
  327. static irqreturn_t
  328. xpc_handle_activate_IRQ_uv(int irq, void *dev_id)
  329. {
  330. struct xpc_activate_mq_msghdr_uv *msg_hdr;
  331. short partid;
  332. struct xpc_partition *part;
  333. int wakeup_hb_checker = 0;
  334. while ((msg_hdr = gru_get_next_message(xpc_activate_mq_uv)) != NULL) {
  335. partid = msg_hdr->partid;
  336. if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
  337. dev_err(xpc_part, "xpc_handle_activate_IRQ_uv() "
  338. "received invalid partid=0x%x in message\n",
  339. partid);
  340. } else {
  341. part = &xpc_partitions[partid];
  342. if (xpc_part_ref(part)) {
  343. xpc_handle_activate_mq_msg_uv(part, msg_hdr,
  344. &wakeup_hb_checker);
  345. xpc_part_deref(part);
  346. }
  347. }
  348. gru_free_message(xpc_activate_mq_uv, msg_hdr);
  349. }
  350. if (wakeup_hb_checker)
  351. wake_up_interruptible(&xpc_activate_IRQ_wq);
  352. return IRQ_HANDLED;
  353. }
  354. static enum xp_retval
  355. xpc_send_activate_IRQ_uv(struct xpc_partition *part, void *msg, size_t msg_size,
  356. int msg_type)
  357. {
  358. struct xpc_activate_mq_msghdr_uv *msg_hdr = msg;
  359. DBUG_ON(msg_size > XPC_ACTIVATE_MSG_SIZE_UV);
  360. msg_hdr->type = msg_type;
  361. msg_hdr->partid = XPC_PARTID(part);
  362. msg_hdr->act_state = part->act_state;
  363. msg_hdr->rp_ts_jiffies = xpc_rsvd_page->ts_jiffies;
  364. /* ??? Is holding a spin_lock (ch->lock) during this call a bad idea? */
  365. return xpc_send_gru_msg(part->sn.uv.remote_activate_mq_gpa, msg,
  366. msg_size);
  367. }
  368. static void
  369. xpc_send_activate_IRQ_part_uv(struct xpc_partition *part, void *msg,
  370. size_t msg_size, int msg_type)
  371. {
  372. enum xp_retval ret;
  373. ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
  374. if (unlikely(ret != xpSuccess))
  375. XPC_DEACTIVATE_PARTITION(part, ret);
  376. }
  377. static void
  378. xpc_send_activate_IRQ_ch_uv(struct xpc_channel *ch, unsigned long *irq_flags,
  379. void *msg, size_t msg_size, int msg_type)
  380. {
  381. struct xpc_partition *part = &xpc_partitions[ch->number];
  382. enum xp_retval ret;
  383. ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
  384. if (unlikely(ret != xpSuccess)) {
  385. if (irq_flags != NULL)
  386. spin_unlock_irqrestore(&ch->lock, *irq_flags);
  387. XPC_DEACTIVATE_PARTITION(part, ret);
  388. if (irq_flags != NULL)
  389. spin_lock_irqsave(&ch->lock, *irq_flags);
  390. }
  391. }
  392. static void
  393. xpc_send_local_activate_IRQ_uv(struct xpc_partition *part, int act_state_req)
  394. {
  395. unsigned long irq_flags;
  396. struct xpc_partition_uv *part_uv = &part->sn.uv;
  397. /*
  398. * !!! Make our side think that the remote parition sent an activate
  399. * !!! message our way by doing what the activate IRQ handler would
  400. * !!! do had one really been sent.
  401. */
  402. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  403. if (part_uv->act_state_req == 0)
  404. xpc_activate_IRQ_rcvd++;
  405. part_uv->act_state_req = act_state_req;
  406. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  407. wake_up_interruptible(&xpc_activate_IRQ_wq);
  408. }
  409. static enum xp_retval
  410. xpc_get_partition_rsvd_page_pa_uv(void *buf, u64 *cookie, unsigned long *rp_pa,
  411. size_t *len)
  412. {
  413. /* !!! call the UV version of sn_partition_reserved_page_pa() */
  414. return xpUnsupported;
  415. }
  416. static int
  417. xpc_setup_rsvd_page_sn_uv(struct xpc_rsvd_page *rp)
  418. {
  419. rp->sn.activate_mq_gpa = uv_gpa(xpc_activate_mq_uv);
  420. return 0;
  421. }
  422. static void
  423. xpc_send_heartbeat_uv(int msg_type)
  424. {
  425. short partid;
  426. struct xpc_partition *part;
  427. struct xpc_activate_mq_msg_heartbeat_req_uv msg;
  428. /*
  429. * !!! On uv we're broadcasting a heartbeat message every 5 seconds.
  430. * !!! Whereas on sn2 we're bte_copy'ng the heartbeat info every 20
  431. * !!! seconds. This is an increase in numalink traffic.
  432. * ??? Is this good?
  433. */
  434. msg.heartbeat = atomic64_inc_return(&xpc_heartbeat_uv);
  435. partid = find_first_bit(xpc_heartbeating_to_mask_uv,
  436. XP_MAX_NPARTITIONS_UV);
  437. while (partid < XP_MAX_NPARTITIONS_UV) {
  438. part = &xpc_partitions[partid];
  439. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  440. msg_type);
  441. partid = find_next_bit(xpc_heartbeating_to_mask_uv,
  442. XP_MAX_NPARTITIONS_UV, partid + 1);
  443. }
  444. }
  445. static void
  446. xpc_increment_heartbeat_uv(void)
  447. {
  448. xpc_send_heartbeat_uv(XPC_ACTIVATE_MQ_MSG_INC_HEARTBEAT_UV);
  449. }
  450. static void
  451. xpc_offline_heartbeat_uv(void)
  452. {
  453. xpc_send_heartbeat_uv(XPC_ACTIVATE_MQ_MSG_OFFLINE_HEARTBEAT_UV);
  454. }
  455. static void
  456. xpc_online_heartbeat_uv(void)
  457. {
  458. xpc_send_heartbeat_uv(XPC_ACTIVATE_MQ_MSG_ONLINE_HEARTBEAT_UV);
  459. }
  460. static void
  461. xpc_heartbeat_init_uv(void)
  462. {
  463. atomic64_set(&xpc_heartbeat_uv, 0);
  464. bitmap_zero(xpc_heartbeating_to_mask_uv, XP_MAX_NPARTITIONS_UV);
  465. xpc_heartbeating_to_mask = &xpc_heartbeating_to_mask_uv[0];
  466. }
  467. static void
  468. xpc_heartbeat_exit_uv(void)
  469. {
  470. xpc_send_heartbeat_uv(XPC_ACTIVATE_MQ_MSG_OFFLINE_HEARTBEAT_UV);
  471. }
  472. static enum xp_retval
  473. xpc_get_remote_heartbeat_uv(struct xpc_partition *part)
  474. {
  475. struct xpc_partition_uv *part_uv = &part->sn.uv;
  476. enum xp_retval ret = xpNoHeartbeat;
  477. if (part_uv->remote_act_state != XPC_P_AS_INACTIVE &&
  478. part_uv->remote_act_state != XPC_P_AS_DEACTIVATING) {
  479. if (part_uv->heartbeat != part->last_heartbeat ||
  480. (part_uv->flags & XPC_P_HEARTBEAT_OFFLINE_UV)) {
  481. part->last_heartbeat = part_uv->heartbeat;
  482. ret = xpSuccess;
  483. }
  484. }
  485. return ret;
  486. }
  487. static void
  488. xpc_request_partition_activation_uv(struct xpc_rsvd_page *remote_rp,
  489. unsigned long remote_rp_gpa, int nasid)
  490. {
  491. short partid = remote_rp->SAL_partid;
  492. struct xpc_partition *part = &xpc_partitions[partid];
  493. struct xpc_activate_mq_msg_activate_req_uv msg;
  494. part->remote_rp_pa = remote_rp_gpa; /* !!! _pa here is really _gpa */
  495. part->remote_rp_ts_jiffies = remote_rp->ts_jiffies;
  496. part->sn.uv.remote_activate_mq_gpa = remote_rp->sn.activate_mq_gpa;
  497. /*
  498. * ??? Is it a good idea to make this conditional on what is
  499. * ??? potentially stale state information?
  500. */
  501. if (part->sn.uv.remote_act_state == XPC_P_AS_INACTIVE) {
  502. msg.rp_gpa = uv_gpa(xpc_rsvd_page);
  503. msg.activate_mq_gpa = xpc_rsvd_page->sn.activate_mq_gpa;
  504. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  505. XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV);
  506. }
  507. if (part->act_state == XPC_P_AS_INACTIVE)
  508. xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
  509. }
  510. static void
  511. xpc_request_partition_reactivation_uv(struct xpc_partition *part)
  512. {
  513. xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
  514. }
  515. static void
  516. xpc_request_partition_deactivation_uv(struct xpc_partition *part)
  517. {
  518. struct xpc_activate_mq_msg_deactivate_req_uv msg;
  519. /*
  520. * ??? Is it a good idea to make this conditional on what is
  521. * ??? potentially stale state information?
  522. */
  523. if (part->sn.uv.remote_act_state != XPC_P_AS_DEACTIVATING &&
  524. part->sn.uv.remote_act_state != XPC_P_AS_INACTIVE) {
  525. msg.reason = part->reason;
  526. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  527. XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV);
  528. }
  529. }
  530. static void
  531. xpc_cancel_partition_deactivation_request_uv(struct xpc_partition *part)
  532. {
  533. /* nothing needs to be done */
  534. return;
  535. }
  536. static void
  537. xpc_init_fifo_uv(struct xpc_fifo_head_uv *head)
  538. {
  539. head->first = NULL;
  540. head->last = NULL;
  541. spin_lock_init(&head->lock);
  542. head->n_entries = 0;
  543. }
  544. static void *
  545. xpc_get_fifo_entry_uv(struct xpc_fifo_head_uv *head)
  546. {
  547. unsigned long irq_flags;
  548. struct xpc_fifo_entry_uv *first;
  549. spin_lock_irqsave(&head->lock, irq_flags);
  550. first = head->first;
  551. if (head->first != NULL) {
  552. head->first = first->next;
  553. if (head->first == NULL)
  554. head->last = NULL;
  555. }
  556. head->n_entries++;
  557. spin_unlock_irqrestore(&head->lock, irq_flags);
  558. first->next = NULL;
  559. return first;
  560. }
  561. static void
  562. xpc_put_fifo_entry_uv(struct xpc_fifo_head_uv *head,
  563. struct xpc_fifo_entry_uv *last)
  564. {
  565. unsigned long irq_flags;
  566. last->next = NULL;
  567. spin_lock_irqsave(&head->lock, irq_flags);
  568. if (head->last != NULL)
  569. head->last->next = last;
  570. else
  571. head->first = last;
  572. head->last = last;
  573. head->n_entries--;
  574. BUG_ON(head->n_entries < 0);
  575. spin_unlock_irqrestore(&head->lock, irq_flags);
  576. }
  577. static int
  578. xpc_n_of_fifo_entries_uv(struct xpc_fifo_head_uv *head)
  579. {
  580. return head->n_entries;
  581. }
  582. /*
  583. * Setup the channel structures that are uv specific.
  584. */
  585. static enum xp_retval
  586. xpc_setup_ch_structures_sn_uv(struct xpc_partition *part)
  587. {
  588. struct xpc_channel_uv *ch_uv;
  589. int ch_number;
  590. for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
  591. ch_uv = &part->channels[ch_number].sn.uv;
  592. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  593. xpc_init_fifo_uv(&ch_uv->recv_msg_list);
  594. }
  595. return xpSuccess;
  596. }
  597. /*
  598. * Teardown the channel structures that are uv specific.
  599. */
  600. static void
  601. xpc_teardown_ch_structures_sn_uv(struct xpc_partition *part)
  602. {
  603. /* nothing needs to be done */
  604. return;
  605. }
  606. static enum xp_retval
  607. xpc_make_first_contact_uv(struct xpc_partition *part)
  608. {
  609. struct xpc_activate_mq_msg_uv msg;
  610. /*
  611. * We send a sync msg to get the remote partition's remote_act_state
  612. * updated to our current act_state which at this point should
  613. * be XPC_P_AS_ACTIVATING.
  614. */
  615. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  616. XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV);
  617. while (part->sn.uv.remote_act_state != XPC_P_AS_ACTIVATING) {
  618. dev_dbg(xpc_part, "waiting to make first contact with "
  619. "partition %d\n", XPC_PARTID(part));
  620. /* wait a 1/4 of a second or so */
  621. (void)msleep_interruptible(250);
  622. if (part->act_state == XPC_P_AS_DEACTIVATING)
  623. return part->reason;
  624. }
  625. return xpSuccess;
  626. }
  627. static u64
  628. xpc_get_chctl_all_flags_uv(struct xpc_partition *part)
  629. {
  630. unsigned long irq_flags;
  631. union xpc_channel_ctl_flags chctl;
  632. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  633. chctl = part->chctl;
  634. if (chctl.all_flags != 0)
  635. part->chctl.all_flags = 0;
  636. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  637. return chctl.all_flags;
  638. }
  639. static enum xp_retval
  640. xpc_allocate_send_msg_slot_uv(struct xpc_channel *ch)
  641. {
  642. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  643. struct xpc_send_msg_slot_uv *msg_slot;
  644. unsigned long irq_flags;
  645. int nentries;
  646. int entry;
  647. size_t nbytes;
  648. for (nentries = ch->local_nentries; nentries > 0; nentries--) {
  649. nbytes = nentries * sizeof(struct xpc_send_msg_slot_uv);
  650. ch_uv->send_msg_slots = kzalloc(nbytes, GFP_KERNEL);
  651. if (ch_uv->send_msg_slots == NULL)
  652. continue;
  653. for (entry = 0; entry < nentries; entry++) {
  654. msg_slot = &ch_uv->send_msg_slots[entry];
  655. msg_slot->msg_slot_number = entry;
  656. xpc_put_fifo_entry_uv(&ch_uv->msg_slot_free_list,
  657. &msg_slot->next);
  658. }
  659. spin_lock_irqsave(&ch->lock, irq_flags);
  660. if (nentries < ch->local_nentries)
  661. ch->local_nentries = nentries;
  662. spin_unlock_irqrestore(&ch->lock, irq_flags);
  663. return xpSuccess;
  664. }
  665. return xpNoMemory;
  666. }
  667. static enum xp_retval
  668. xpc_allocate_recv_msg_slot_uv(struct xpc_channel *ch)
  669. {
  670. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  671. struct xpc_notify_mq_msg_uv *msg_slot;
  672. unsigned long irq_flags;
  673. int nentries;
  674. int entry;
  675. size_t nbytes;
  676. for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
  677. nbytes = nentries * ch->entry_size;
  678. ch_uv->recv_msg_slots = kzalloc(nbytes, GFP_KERNEL);
  679. if (ch_uv->recv_msg_slots == NULL)
  680. continue;
  681. for (entry = 0; entry < nentries; entry++) {
  682. msg_slot = ch_uv->recv_msg_slots + entry *
  683. ch->entry_size;
  684. msg_slot->hdr.msg_slot_number = entry;
  685. }
  686. spin_lock_irqsave(&ch->lock, irq_flags);
  687. if (nentries < ch->remote_nentries)
  688. ch->remote_nentries = nentries;
  689. spin_unlock_irqrestore(&ch->lock, irq_flags);
  690. return xpSuccess;
  691. }
  692. return xpNoMemory;
  693. }
  694. /*
  695. * Allocate msg_slots associated with the channel.
  696. */
  697. static enum xp_retval
  698. xpc_setup_msg_structures_uv(struct xpc_channel *ch)
  699. {
  700. static enum xp_retval ret;
  701. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  702. DBUG_ON(ch->flags & XPC_C_SETUP);
  703. ret = xpc_allocate_send_msg_slot_uv(ch);
  704. if (ret == xpSuccess) {
  705. ret = xpc_allocate_recv_msg_slot_uv(ch);
  706. if (ret != xpSuccess) {
  707. kfree(ch_uv->send_msg_slots);
  708. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  709. }
  710. }
  711. return ret;
  712. }
  713. /*
  714. * Free up msg_slots and clear other stuff that were setup for the specified
  715. * channel.
  716. */
  717. static void
  718. xpc_teardown_msg_structures_uv(struct xpc_channel *ch)
  719. {
  720. struct xpc_channel_uv *ch_uv = &ch->sn.uv;
  721. DBUG_ON(!spin_is_locked(&ch->lock));
  722. ch_uv->remote_notify_mq_gpa = 0;
  723. if (ch->flags & XPC_C_SETUP) {
  724. xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
  725. kfree(ch_uv->send_msg_slots);
  726. xpc_init_fifo_uv(&ch_uv->recv_msg_list);
  727. kfree(ch_uv->recv_msg_slots);
  728. }
  729. }
  730. static void
  731. xpc_send_chctl_closerequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  732. {
  733. struct xpc_activate_mq_msg_chctl_closerequest_uv msg;
  734. msg.ch_number = ch->number;
  735. msg.reason = ch->reason;
  736. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  737. XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV);
  738. }
  739. static void
  740. xpc_send_chctl_closereply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  741. {
  742. struct xpc_activate_mq_msg_chctl_closereply_uv msg;
  743. msg.ch_number = ch->number;
  744. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  745. XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV);
  746. }
  747. static void
  748. xpc_send_chctl_openrequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  749. {
  750. struct xpc_activate_mq_msg_chctl_openrequest_uv msg;
  751. msg.ch_number = ch->number;
  752. msg.entry_size = ch->entry_size;
  753. msg.local_nentries = ch->local_nentries;
  754. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  755. XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV);
  756. }
  757. static void
  758. xpc_send_chctl_openreply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
  759. {
  760. struct xpc_activate_mq_msg_chctl_openreply_uv msg;
  761. msg.ch_number = ch->number;
  762. msg.local_nentries = ch->local_nentries;
  763. msg.remote_nentries = ch->remote_nentries;
  764. msg.local_notify_mq_gpa = uv_gpa(xpc_notify_mq_uv);
  765. xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
  766. XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV);
  767. }
  768. static void
  769. xpc_send_chctl_local_msgrequest_uv(struct xpc_partition *part, int ch_number)
  770. {
  771. unsigned long irq_flags;
  772. spin_lock_irqsave(&part->chctl_lock, irq_flags);
  773. part->chctl.flags[ch_number] |= XPC_CHCTL_MSGREQUEST;
  774. spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
  775. xpc_wakeup_channel_mgr(part);
  776. }
  777. static void
  778. xpc_save_remote_msgqueue_pa_uv(struct xpc_channel *ch,
  779. unsigned long msgqueue_pa)
  780. {
  781. ch->sn.uv.remote_notify_mq_gpa = msgqueue_pa;
  782. }
  783. static void
  784. xpc_indicate_partition_engaged_uv(struct xpc_partition *part)
  785. {
  786. struct xpc_activate_mq_msg_uv msg;
  787. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  788. XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV);
  789. }
  790. static void
  791. xpc_indicate_partition_disengaged_uv(struct xpc_partition *part)
  792. {
  793. struct xpc_activate_mq_msg_uv msg;
  794. xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
  795. XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV);
  796. }
  797. static void
  798. xpc_assume_partition_disengaged_uv(short partid)
  799. {
  800. struct xpc_partition_uv *part_uv = &xpc_partitions[partid].sn.uv;
  801. unsigned long irq_flags;
  802. spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
  803. part_uv->flags &= ~XPC_P_ENGAGED_UV;
  804. spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
  805. }
  806. static int
  807. xpc_partition_engaged_uv(short partid)
  808. {
  809. return (xpc_partitions[partid].sn.uv.flags & XPC_P_ENGAGED_UV) != 0;
  810. }
  811. static int
  812. xpc_any_partition_engaged_uv(void)
  813. {
  814. struct xpc_partition_uv *part_uv;
  815. short partid;
  816. for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
  817. part_uv = &xpc_partitions[partid].sn.uv;
  818. if ((part_uv->flags & XPC_P_ENGAGED_UV) != 0)
  819. return 1;
  820. }
  821. return 0;
  822. }
  823. static enum xp_retval
  824. xpc_allocate_msg_slot_uv(struct xpc_channel *ch, u32 flags,
  825. struct xpc_send_msg_slot_uv **address_of_msg_slot)
  826. {
  827. enum xp_retval ret;
  828. struct xpc_send_msg_slot_uv *msg_slot;
  829. struct xpc_fifo_entry_uv *entry;
  830. while (1) {
  831. entry = xpc_get_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list);
  832. if (entry != NULL)
  833. break;
  834. if (flags & XPC_NOWAIT)
  835. return xpNoWait;
  836. ret = xpc_allocate_msg_wait(ch);
  837. if (ret != xpInterrupted && ret != xpTimeout)
  838. return ret;
  839. }
  840. msg_slot = container_of(entry, struct xpc_send_msg_slot_uv, next);
  841. *address_of_msg_slot = msg_slot;
  842. return xpSuccess;
  843. }
  844. static void
  845. xpc_free_msg_slot_uv(struct xpc_channel *ch,
  846. struct xpc_send_msg_slot_uv *msg_slot)
  847. {
  848. xpc_put_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list, &msg_slot->next);
  849. /* wakeup anyone waiting for a free msg slot */
  850. if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
  851. wake_up(&ch->msg_allocate_wq);
  852. }
  853. static void
  854. xpc_notify_sender_uv(struct xpc_channel *ch,
  855. struct xpc_send_msg_slot_uv *msg_slot,
  856. enum xp_retval reason)
  857. {
  858. xpc_notify_func func = msg_slot->func;
  859. if (func != NULL && cmpxchg(&msg_slot->func, func, NULL) == func) {
  860. atomic_dec(&ch->n_to_notify);
  861. dev_dbg(xpc_chan, "msg_slot->func() called, msg_slot=0x%p "
  862. "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
  863. msg_slot->msg_slot_number, ch->partid, ch->number);
  864. func(reason, ch->partid, ch->number, msg_slot->key);
  865. dev_dbg(xpc_chan, "msg_slot->func() returned, msg_slot=0x%p "
  866. "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
  867. msg_slot->msg_slot_number, ch->partid, ch->number);
  868. }
  869. }
  870. static void
  871. xpc_handle_notify_mq_ack_uv(struct xpc_channel *ch,
  872. struct xpc_notify_mq_msg_uv *msg)
  873. {
  874. struct xpc_send_msg_slot_uv *msg_slot;
  875. int entry = msg->hdr.msg_slot_number % ch->local_nentries;
  876. msg_slot = &ch->sn.uv.send_msg_slots[entry];
  877. BUG_ON(msg_slot->msg_slot_number != msg->hdr.msg_slot_number);
  878. msg_slot->msg_slot_number += ch->local_nentries;
  879. if (msg_slot->func != NULL)
  880. xpc_notify_sender_uv(ch, msg_slot, xpMsgDelivered);
  881. xpc_free_msg_slot_uv(ch, msg_slot);
  882. }
  883. static void
  884. xpc_handle_notify_mq_msg_uv(struct xpc_partition *part,
  885. struct xpc_notify_mq_msg_uv *msg)
  886. {
  887. struct xpc_partition_uv *part_uv = &part->sn.uv;
  888. struct xpc_channel *ch;
  889. struct xpc_channel_uv *ch_uv;
  890. struct xpc_notify_mq_msg_uv *msg_slot;
  891. unsigned long irq_flags;
  892. int ch_number = msg->hdr.ch_number;
  893. if (unlikely(ch_number >= part->nchannels)) {
  894. dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received invalid "
  895. "channel number=0x%x in message from partid=%d\n",
  896. ch_number, XPC_PARTID(part));
  897. /* get hb checker to deactivate from the remote partition */
  898. spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  899. if (part_uv->act_state_req == 0)
  900. xpc_activate_IRQ_rcvd++;
  901. part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
  902. part_uv->reason = xpBadChannelNumber;
  903. spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
  904. wake_up_interruptible(&xpc_activate_IRQ_wq);
  905. return;
  906. }
  907. ch = &part->channels[ch_number];
  908. xpc_msgqueue_ref(ch);
  909. if (!(ch->flags & XPC_C_CONNECTED)) {
  910. xpc_msgqueue_deref(ch);
  911. return;
  912. }
  913. /* see if we're really dealing with an ACK for a previously sent msg */
  914. if (msg->hdr.size == 0) {
  915. xpc_handle_notify_mq_ack_uv(ch, msg);
  916. xpc_msgqueue_deref(ch);
  917. return;
  918. }
  919. /* we're dealing with a normal message sent via the notify_mq */
  920. ch_uv = &ch->sn.uv;
  921. msg_slot = (struct xpc_notify_mq_msg_uv *)((u64)ch_uv->recv_msg_slots +
  922. (msg->hdr.msg_slot_number % ch->remote_nentries) *
  923. ch->entry_size);
  924. BUG_ON(msg->hdr.msg_slot_number != msg_slot->hdr.msg_slot_number);
  925. BUG_ON(msg_slot->hdr.size != 0);
  926. memcpy(msg_slot, msg, msg->hdr.size);
  927. xpc_put_fifo_entry_uv(&ch_uv->recv_msg_list, &msg_slot->hdr.u.next);
  928. if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) {
  929. /*
  930. * If there is an existing idle kthread get it to deliver
  931. * the payload, otherwise we'll have to get the channel mgr
  932. * for this partition to create a kthread to do the delivery.
  933. */
  934. if (atomic_read(&ch->kthreads_idle) > 0)
  935. wake_up_nr(&ch->idle_wq, 1);
  936. else
  937. xpc_send_chctl_local_msgrequest_uv(part, ch->number);
  938. }
  939. xpc_msgqueue_deref(ch);
  940. }
  941. static irqreturn_t
  942. xpc_handle_notify_IRQ_uv(int irq, void *dev_id)
  943. {
  944. struct xpc_notify_mq_msg_uv *msg;
  945. short partid;
  946. struct xpc_partition *part;
  947. while ((msg = gru_get_next_message(xpc_notify_mq_uv)) != NULL) {
  948. partid = msg->hdr.partid;
  949. if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
  950. dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received "
  951. "invalid partid=0x%x in message\n", partid);
  952. } else {
  953. part = &xpc_partitions[partid];
  954. if (xpc_part_ref(part)) {
  955. xpc_handle_notify_mq_msg_uv(part, msg);
  956. xpc_part_deref(part);
  957. }
  958. }
  959. gru_free_message(xpc_notify_mq_uv, msg);
  960. }
  961. return IRQ_HANDLED;
  962. }
  963. static int
  964. xpc_n_of_deliverable_payloads_uv(struct xpc_channel *ch)
  965. {
  966. return xpc_n_of_fifo_entries_uv(&ch->sn.uv.recv_msg_list);
  967. }
  968. static void
  969. xpc_process_msg_chctl_flags_uv(struct xpc_partition *part, int ch_number)
  970. {
  971. struct xpc_channel *ch = &part->channels[ch_number];
  972. int ndeliverable_payloads;
  973. xpc_msgqueue_ref(ch);
  974. ndeliverable_payloads = xpc_n_of_deliverable_payloads_uv(ch);
  975. if (ndeliverable_payloads > 0 &&
  976. (ch->flags & XPC_C_CONNECTED) &&
  977. (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE)) {
  978. xpc_activate_kthreads(ch, ndeliverable_payloads);
  979. }
  980. xpc_msgqueue_deref(ch);
  981. }
  982. static enum xp_retval
  983. xpc_send_payload_uv(struct xpc_channel *ch, u32 flags, void *payload,
  984. u16 payload_size, u8 notify_type, xpc_notify_func func,
  985. void *key)
  986. {
  987. enum xp_retval ret = xpSuccess;
  988. struct xpc_send_msg_slot_uv *msg_slot = NULL;
  989. struct xpc_notify_mq_msg_uv *msg;
  990. u8 msg_buffer[XPC_NOTIFY_MSG_SIZE_UV];
  991. size_t msg_size;
  992. DBUG_ON(notify_type != XPC_N_CALL);
  993. msg_size = sizeof(struct xpc_notify_mq_msghdr_uv) + payload_size;
  994. if (msg_size > ch->entry_size)
  995. return xpPayloadTooBig;
  996. xpc_msgqueue_ref(ch);
  997. if (ch->flags & XPC_C_DISCONNECTING) {
  998. ret = ch->reason;
  999. goto out_1;
  1000. }
  1001. if (!(ch->flags & XPC_C_CONNECTED)) {
  1002. ret = xpNotConnected;
  1003. goto out_1;
  1004. }
  1005. ret = xpc_allocate_msg_slot_uv(ch, flags, &msg_slot);
  1006. if (ret != xpSuccess)
  1007. goto out_1;
  1008. if (func != NULL) {
  1009. atomic_inc(&ch->n_to_notify);
  1010. msg_slot->key = key;
  1011. wmb(); /* a non-NULL func must hit memory after the key */
  1012. msg_slot->func = func;
  1013. if (ch->flags & XPC_C_DISCONNECTING) {
  1014. ret = ch->reason;
  1015. goto out_2;
  1016. }
  1017. }
  1018. msg = (struct xpc_notify_mq_msg_uv *)&msg_buffer;
  1019. msg->hdr.partid = xp_partition_id;
  1020. msg->hdr.ch_number = ch->number;
  1021. msg->hdr.size = msg_size;
  1022. msg->hdr.msg_slot_number = msg_slot->msg_slot_number;
  1023. memcpy(&msg->payload, payload, payload_size);
  1024. ret = xpc_send_gru_msg(ch->sn.uv.remote_notify_mq_gpa, msg, msg_size);
  1025. if (ret == xpSuccess)
  1026. goto out_1;
  1027. XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
  1028. out_2:
  1029. if (func != NULL) {
  1030. /*
  1031. * Try to NULL the msg_slot's func field. If we fail, then
  1032. * xpc_notify_senders_of_disconnect_uv() beat us to it, in which
  1033. * case we need to pretend we succeeded to send the message
  1034. * since the user will get a callout for the disconnect error
  1035. * by xpc_notify_senders_of_disconnect_uv(), and to also get an
  1036. * error returned here will confuse them. Additionally, since
  1037. * in this case the channel is being disconnected we don't need
  1038. * to put the the msg_slot back on the free list.
  1039. */
  1040. if (cmpxchg(&msg_slot->func, func, NULL) != func) {
  1041. ret = xpSuccess;
  1042. goto out_1;
  1043. }
  1044. msg_slot->key = NULL;
  1045. atomic_dec(&ch->n_to_notify);
  1046. }
  1047. xpc_free_msg_slot_uv(ch, msg_slot);
  1048. out_1:
  1049. xpc_msgqueue_deref(ch);
  1050. return ret;
  1051. }
  1052. /*
  1053. * Tell the callers of xpc_send_notify() that the status of their payloads
  1054. * is unknown because the channel is now disconnecting.
  1055. *
  1056. * We don't worry about putting these msg_slots on the free list since the
  1057. * msg_slots themselves are about to be kfree'd.
  1058. */
  1059. static void
  1060. xpc_notify_senders_of_disconnect_uv(struct xpc_channel *ch)
  1061. {
  1062. struct xpc_send_msg_slot_uv *msg_slot;
  1063. int entry;
  1064. DBUG_ON(!(ch->flags & XPC_C_DISCONNECTING));
  1065. for (entry = 0; entry < ch->local_nentries; entry++) {
  1066. if (atomic_read(&ch->n_to_notify) == 0)
  1067. break;
  1068. msg_slot = &ch->sn.uv.send_msg_slots[entry];
  1069. if (msg_slot->func != NULL)
  1070. xpc_notify_sender_uv(ch, msg_slot, ch->reason);
  1071. }
  1072. }
  1073. /*
  1074. * Get the next deliverable message's payload.
  1075. */
  1076. static void *
  1077. xpc_get_deliverable_payload_uv(struct xpc_channel *ch)
  1078. {
  1079. struct xpc_fifo_entry_uv *entry;
  1080. struct xpc_notify_mq_msg_uv *msg;
  1081. void *payload = NULL;
  1082. if (!(ch->flags & XPC_C_DISCONNECTING)) {
  1083. entry = xpc_get_fifo_entry_uv(&ch->sn.uv.recv_msg_list);
  1084. if (entry != NULL) {
  1085. msg = container_of(entry, struct xpc_notify_mq_msg_uv,
  1086. hdr.u.next);
  1087. payload = &msg->payload;
  1088. }
  1089. }
  1090. return payload;
  1091. }
  1092. static void
  1093. xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
  1094. {
  1095. struct xpc_notify_mq_msg_uv *msg;
  1096. enum xp_retval ret;
  1097. msg = container_of(payload, struct xpc_notify_mq_msg_uv, payload);
  1098. /* return an ACK to the sender of this message */
  1099. msg->hdr.partid = xp_partition_id;
  1100. msg->hdr.size = 0; /* size of zero indicates this is an ACK */
  1101. ret = xpc_send_gru_msg(ch->sn.uv.remote_notify_mq_gpa, msg,
  1102. sizeof(struct xpc_notify_mq_msghdr_uv));
  1103. if (ret != xpSuccess)
  1104. XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
  1105. msg->hdr.msg_slot_number += ch->remote_nentries;
  1106. }
  1107. int
  1108. xpc_init_uv(void)
  1109. {
  1110. xpc_setup_partitions_sn = xpc_setup_partitions_sn_uv;
  1111. xpc_process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv;
  1112. xpc_get_partition_rsvd_page_pa = xpc_get_partition_rsvd_page_pa_uv;
  1113. xpc_setup_rsvd_page_sn = xpc_setup_rsvd_page_sn_uv;
  1114. xpc_increment_heartbeat = xpc_increment_heartbeat_uv;
  1115. xpc_offline_heartbeat = xpc_offline_heartbeat_uv;
  1116. xpc_online_heartbeat = xpc_online_heartbeat_uv;
  1117. xpc_heartbeat_init = xpc_heartbeat_init_uv;
  1118. xpc_heartbeat_exit = xpc_heartbeat_exit_uv;
  1119. xpc_get_remote_heartbeat = xpc_get_remote_heartbeat_uv;
  1120. xpc_request_partition_activation = xpc_request_partition_activation_uv;
  1121. xpc_request_partition_reactivation =
  1122. xpc_request_partition_reactivation_uv;
  1123. xpc_request_partition_deactivation =
  1124. xpc_request_partition_deactivation_uv;
  1125. xpc_cancel_partition_deactivation_request =
  1126. xpc_cancel_partition_deactivation_request_uv;
  1127. xpc_setup_ch_structures_sn = xpc_setup_ch_structures_sn_uv;
  1128. xpc_teardown_ch_structures_sn = xpc_teardown_ch_structures_sn_uv;
  1129. xpc_make_first_contact = xpc_make_first_contact_uv;
  1130. xpc_get_chctl_all_flags = xpc_get_chctl_all_flags_uv;
  1131. xpc_send_chctl_closerequest = xpc_send_chctl_closerequest_uv;
  1132. xpc_send_chctl_closereply = xpc_send_chctl_closereply_uv;
  1133. xpc_send_chctl_openrequest = xpc_send_chctl_openrequest_uv;
  1134. xpc_send_chctl_openreply = xpc_send_chctl_openreply_uv;
  1135. xpc_save_remote_msgqueue_pa = xpc_save_remote_msgqueue_pa_uv;
  1136. xpc_setup_msg_structures = xpc_setup_msg_structures_uv;
  1137. xpc_teardown_msg_structures = xpc_teardown_msg_structures_uv;
  1138. xpc_indicate_partition_engaged = xpc_indicate_partition_engaged_uv;
  1139. xpc_indicate_partition_disengaged =
  1140. xpc_indicate_partition_disengaged_uv;
  1141. xpc_assume_partition_disengaged = xpc_assume_partition_disengaged_uv;
  1142. xpc_partition_engaged = xpc_partition_engaged_uv;
  1143. xpc_any_partition_engaged = xpc_any_partition_engaged_uv;
  1144. xpc_n_of_deliverable_payloads = xpc_n_of_deliverable_payloads_uv;
  1145. xpc_process_msg_chctl_flags = xpc_process_msg_chctl_flags_uv;
  1146. xpc_send_payload = xpc_send_payload_uv;
  1147. xpc_notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_uv;
  1148. xpc_get_deliverable_payload = xpc_get_deliverable_payload_uv;
  1149. xpc_received_payload = xpc_received_payload_uv;
  1150. if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
  1151. dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
  1152. XPC_MSG_HDR_MAX_SIZE);
  1153. return -E2BIG;
  1154. }
  1155. /* ??? The cpuid argument's value is 0, is that what we want? */
  1156. /* !!! The irq argument's value isn't correct. */
  1157. xpc_activate_mq_uv = xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, 0, 0,
  1158. xpc_handle_activate_IRQ_uv);
  1159. if (xpc_activate_mq_uv == NULL)
  1160. return -ENOMEM;
  1161. /* ??? The cpuid argument's value is 0, is that what we want? */
  1162. /* !!! The irq argument's value isn't correct. */
  1163. xpc_notify_mq_uv = xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, 0, 0,
  1164. xpc_handle_notify_IRQ_uv);
  1165. if (xpc_notify_mq_uv == NULL) {
  1166. /* !!! The irq argument's value isn't correct. */
  1167. xpc_destroy_gru_mq_uv(xpc_activate_mq_uv,
  1168. XPC_ACTIVATE_MQ_SIZE_UV, 0);
  1169. return -ENOMEM;
  1170. }
  1171. return 0;
  1172. }
  1173. void
  1174. xpc_exit_uv(void)
  1175. {
  1176. /* !!! The irq argument's value isn't correct. */
  1177. xpc_destroy_gru_mq_uv(xpc_notify_mq_uv, XPC_NOTIFY_MQ_SIZE_UV, 0);
  1178. /* !!! The irq argument's value isn't correct. */
  1179. xpc_destroy_gru_mq_uv(xpc_activate_mq_uv, XPC_ACTIVATE_MQ_SIZE_UV, 0);
  1180. }