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
6 * Copyright (c) 2008-2009 Silicon Graphics, Inc. All Rights Reserved.
10 * Cross Partition Communication (XPC) uv-based functions.
12 * Architecture specific implementation of common functions.
16 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/delay.h>
20 #include <linux/device.h>
21 #include <linux/cpu.h>
22 #include <linux/module.h>
23 #include <linux/err.h>
24 #include <linux/slab.h>
25 #include <linux/numa.h>
26 #include <asm/uv/uv_hub.h>
27 #if defined CONFIG_X86_64
28 #include <asm/uv/bios.h>
29 #include <asm/uv/uv_irq.h>
30 #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
31 #include <asm/sn/intr.h>
32 #include <asm/sn/sn_sal.h>
34 #include "../sgi-gru/gru.h"
35 #include "../sgi-gru/grukservices.h"
38 #if defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
39 struct uv_IO_APIC_route_entry {
53 static struct xpc_heartbeat_uv *xpc_heartbeat_uv;
55 #define XPC_ACTIVATE_MSG_SIZE_UV (1 * GRU_CACHE_LINE_BYTES)
56 #define XPC_ACTIVATE_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
57 XPC_ACTIVATE_MSG_SIZE_UV)
58 #define XPC_ACTIVATE_IRQ_NAME "xpc_activate"
60 #define XPC_NOTIFY_MSG_SIZE_UV (2 * GRU_CACHE_LINE_BYTES)
61 #define XPC_NOTIFY_MQ_SIZE_UV (4 * XP_MAX_NPARTITIONS_UV * \
62 XPC_NOTIFY_MSG_SIZE_UV)
63 #define XPC_NOTIFY_IRQ_NAME "xpc_notify"
65 static int xpc_mq_node = NUMA_NO_NODE;
67 static struct xpc_gru_mq_uv *xpc_activate_mq_uv;
68 static struct xpc_gru_mq_uv *xpc_notify_mq_uv;
71 xpc_setup_partitions_uv(void)
74 struct xpc_partition_uv *part_uv;
76 for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
77 part_uv = &xpc_partitions[partid].sn.uv;
79 mutex_init(&part_uv->cached_activate_gru_mq_desc_mutex);
80 spin_lock_init(&part_uv->flags_lock);
81 part_uv->remote_act_state = XPC_P_AS_INACTIVE;
87 xpc_teardown_partitions_uv(void)
90 struct xpc_partition_uv *part_uv;
91 unsigned long irq_flags;
93 for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
94 part_uv = &xpc_partitions[partid].sn.uv;
96 if (part_uv->cached_activate_gru_mq_desc != NULL) {
97 mutex_lock(&part_uv->cached_activate_gru_mq_desc_mutex);
98 spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
99 part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
100 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
101 kfree(part_uv->cached_activate_gru_mq_desc);
102 part_uv->cached_activate_gru_mq_desc = NULL;
103 mutex_unlock(&part_uv->
104 cached_activate_gru_mq_desc_mutex);
110 xpc_get_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq, int cpu, char *irq_name)
112 int mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
114 #if defined CONFIG_X86_64
115 mq->irq = uv_setup_irq(irq_name, cpu, mq->mmr_blade, mq->mmr_offset,
120 mq->mmr_value = uv_read_global_mmr64(mmr_pnode, mq->mmr_offset);
122 #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
123 if (strcmp(irq_name, XPC_ACTIVATE_IRQ_NAME) == 0)
124 mq->irq = SGI_XPC_ACTIVATE;
125 else if (strcmp(irq_name, XPC_NOTIFY_IRQ_NAME) == 0)
126 mq->irq = SGI_XPC_NOTIFY;
130 mq->mmr_value = (unsigned long)cpu_physical_id(cpu) << 32 | mq->irq;
131 uv_write_global_mmr64(mmr_pnode, mq->mmr_offset, mq->mmr_value);
133 #error not a supported configuration
140 xpc_release_gru_mq_irq_uv(struct xpc_gru_mq_uv *mq)
142 #if defined CONFIG_X86_64
143 uv_teardown_irq(mq->irq);
145 #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
147 unsigned long mmr_value;
149 mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
150 mmr_value = 1UL << 16;
152 uv_write_global_mmr64(mmr_pnode, mq->mmr_offset, mmr_value);
154 #error not a supported configuration
159 xpc_gru_mq_watchlist_alloc_uv(struct xpc_gru_mq_uv *mq)
163 #if defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
164 int mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
166 ret = sn_mq_watchlist_alloc(mmr_pnode, (void *)uv_gpa(mq->address),
167 mq->order, &mq->mmr_offset);
169 dev_err(xpc_part, "sn_mq_watchlist_alloc() failed, ret=%d\n",
173 #elif defined CONFIG_X86_64
174 ret = uv_bios_mq_watchlist_alloc(uv_gpa(mq->address),
175 mq->order, &mq->mmr_offset);
177 dev_err(xpc_part, "uv_bios_mq_watchlist_alloc() failed, "
182 #error not a supported configuration
185 mq->watchlist_num = ret;
190 xpc_gru_mq_watchlist_free_uv(struct xpc_gru_mq_uv *mq)
193 int mmr_pnode = uv_blade_to_pnode(mq->mmr_blade);
195 #if defined CONFIG_X86_64
196 ret = uv_bios_mq_watchlist_free(mmr_pnode, mq->watchlist_num);
197 BUG_ON(ret != BIOS_STATUS_SUCCESS);
198 #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
199 ret = sn_mq_watchlist_free(mmr_pnode, mq->watchlist_num);
200 BUG_ON(ret != SALRET_OK);
202 #error not a supported configuration
206 static struct xpc_gru_mq_uv *
207 xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name,
208 irq_handler_t irq_handler)
210 enum xp_retval xp_ret;
216 struct xpc_gru_mq_uv *mq;
217 struct uv_IO_APIC_route_entry *mmr_value;
219 mq = kmalloc(sizeof(struct xpc_gru_mq_uv), GFP_KERNEL);
221 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() "
222 "a xpc_gru_mq_uv structure\n");
227 mq->gru_mq_desc = kzalloc(sizeof(struct gru_message_queue_desc),
229 if (mq->gru_mq_desc == NULL) {
230 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to kmalloc() "
231 "a gru_message_queue_desc structure\n");
236 pg_order = get_order(mq_size);
237 mq->order = pg_order + PAGE_SHIFT;
238 mq_size = 1UL << mq->order;
240 mq->mmr_blade = uv_cpu_to_blade_id(cpu);
242 nid = cpu_to_node(cpu);
243 page = __alloc_pages_node(nid,
244 GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE,
247 dev_err(xpc_part, "xpc_create_gru_mq_uv() failed to alloc %d "
248 "bytes of memory on nid=%d for GRU mq\n", mq_size, nid);
252 mq->address = page_address(page);
254 /* enable generation of irq when GRU mq operation occurs to this mq */
255 ret = xpc_gru_mq_watchlist_alloc_uv(mq);
259 ret = xpc_get_gru_mq_irq_uv(mq, cpu, irq_name);
263 ret = request_irq(mq->irq, irq_handler, 0, irq_name, NULL);
265 dev_err(xpc_part, "request_irq(irq=%d) returned error=%d\n",
270 nasid = UV_PNODE_TO_NASID(uv_cpu_to_pnode(cpu));
272 mmr_value = (struct uv_IO_APIC_route_entry *)&mq->mmr_value;
273 ret = gru_create_message_queue(mq->gru_mq_desc, mq->address, mq_size,
274 nasid, mmr_value->vector, mmr_value->dest);
276 dev_err(xpc_part, "gru_create_message_queue() returned "
282 /* allow other partitions to access this GRU mq */
283 xp_ret = xp_expand_memprotect(xp_pa(mq->address), mq_size);
284 if (xp_ret != xpSuccess) {
291 /* something went wrong */
293 free_irq(mq->irq, NULL);
295 xpc_release_gru_mq_irq_uv(mq);
297 xpc_gru_mq_watchlist_free_uv(mq);
299 free_pages((unsigned long)mq->address, pg_order);
301 kfree(mq->gru_mq_desc);
309 xpc_destroy_gru_mq_uv(struct xpc_gru_mq_uv *mq)
311 unsigned int mq_size;
315 /* disallow other partitions to access GRU mq */
316 mq_size = 1UL << mq->order;
317 ret = xp_restrict_memprotect(xp_pa(mq->address), mq_size);
318 BUG_ON(ret != xpSuccess);
320 /* unregister irq handler and release mq irq/vector mapping */
321 free_irq(mq->irq, NULL);
322 xpc_release_gru_mq_irq_uv(mq);
324 /* disable generation of irq when GRU mq op occurs to this mq */
325 xpc_gru_mq_watchlist_free_uv(mq);
327 pg_order = mq->order - PAGE_SHIFT;
328 free_pages((unsigned long)mq->address, pg_order);
333 static enum xp_retval
334 xpc_send_gru_msg(struct gru_message_queue_desc *gru_mq_desc, void *msg,
337 enum xp_retval xp_ret;
341 ret = gru_send_message_gpa(gru_mq_desc, msg, msg_size);
347 if (ret == MQE_QUEUE_FULL) {
348 dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
349 "error=MQE_QUEUE_FULL\n");
350 /* !!! handle QLimit reached; delay & try again */
351 /* ??? Do we add a limit to the number of retries? */
352 (void)msleep_interruptible(10);
353 } else if (ret == MQE_CONGESTION) {
354 dev_dbg(xpc_chan, "gru_send_message_gpa() returned "
355 "error=MQE_CONGESTION\n");
356 /* !!! handle LB Overflow; simply try again */
357 /* ??? Do we add a limit to the number of retries? */
359 /* !!! Currently this is MQE_UNEXPECTED_CB_ERR */
360 dev_err(xpc_chan, "gru_send_message_gpa() returned "
362 xp_ret = xpGruSendMqError;
370 xpc_process_activate_IRQ_rcvd_uv(void)
372 unsigned long irq_flags;
374 struct xpc_partition *part;
377 DBUG_ON(xpc_activate_IRQ_rcvd == 0);
379 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
380 for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
381 part = &xpc_partitions[partid];
383 if (part->sn.uv.act_state_req == 0)
386 xpc_activate_IRQ_rcvd--;
387 BUG_ON(xpc_activate_IRQ_rcvd < 0);
389 act_state_req = part->sn.uv.act_state_req;
390 part->sn.uv.act_state_req = 0;
391 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
393 if (act_state_req == XPC_P_ASR_ACTIVATE_UV) {
394 if (part->act_state == XPC_P_AS_INACTIVE)
395 xpc_activate_partition(part);
396 else if (part->act_state == XPC_P_AS_DEACTIVATING)
397 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
399 } else if (act_state_req == XPC_P_ASR_REACTIVATE_UV) {
400 if (part->act_state == XPC_P_AS_INACTIVE)
401 xpc_activate_partition(part);
403 XPC_DEACTIVATE_PARTITION(part, xpReactivating);
405 } else if (act_state_req == XPC_P_ASR_DEACTIVATE_UV) {
406 XPC_DEACTIVATE_PARTITION(part, part->sn.uv.reason);
412 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
413 if (xpc_activate_IRQ_rcvd == 0)
416 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
421 xpc_handle_activate_mq_msg_uv(struct xpc_partition *part,
422 struct xpc_activate_mq_msghdr_uv *msg_hdr,
424 int *wakeup_hb_checker)
426 unsigned long irq_flags;
427 struct xpc_partition_uv *part_uv = &part->sn.uv;
428 struct xpc_openclose_args *args;
430 part_uv->remote_act_state = msg_hdr->act_state;
432 switch (msg_hdr->type) {
433 case XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV:
434 /* syncing of remote_act_state was just done above */
437 case XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV: {
438 struct xpc_activate_mq_msg_activate_req_uv *msg;
441 * ??? Do we deal here with ts_jiffies being different
442 * ??? if act_state != XPC_P_AS_INACTIVE instead of
445 msg = container_of(msg_hdr, struct
446 xpc_activate_mq_msg_activate_req_uv, hdr);
448 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
449 if (part_uv->act_state_req == 0)
450 xpc_activate_IRQ_rcvd++;
451 part_uv->act_state_req = XPC_P_ASR_ACTIVATE_UV;
452 part->remote_rp_pa = msg->rp_gpa; /* !!! _pa is _gpa */
453 part->remote_rp_ts_jiffies = msg_hdr->rp_ts_jiffies;
454 part_uv->heartbeat_gpa = msg->heartbeat_gpa;
456 if (msg->activate_gru_mq_desc_gpa !=
457 part_uv->activate_gru_mq_desc_gpa) {
458 spin_lock(&part_uv->flags_lock);
459 part_uv->flags &= ~XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
460 spin_unlock(&part_uv->flags_lock);
461 part_uv->activate_gru_mq_desc_gpa =
462 msg->activate_gru_mq_desc_gpa;
464 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
466 (*wakeup_hb_checker)++;
469 case XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV: {
470 struct xpc_activate_mq_msg_deactivate_req_uv *msg;
472 msg = container_of(msg_hdr, struct
473 xpc_activate_mq_msg_deactivate_req_uv, hdr);
475 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
476 if (part_uv->act_state_req == 0)
477 xpc_activate_IRQ_rcvd++;
478 part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
479 part_uv->reason = msg->reason;
480 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
482 (*wakeup_hb_checker)++;
485 case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV: {
486 struct xpc_activate_mq_msg_chctl_closerequest_uv *msg;
491 msg = container_of(msg_hdr, struct
492 xpc_activate_mq_msg_chctl_closerequest_uv,
494 args = &part->remote_openclose_args[msg->ch_number];
495 args->reason = msg->reason;
497 spin_lock_irqsave(&part->chctl_lock, irq_flags);
498 part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREQUEST;
499 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
501 xpc_wakeup_channel_mgr(part);
504 case XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV: {
505 struct xpc_activate_mq_msg_chctl_closereply_uv *msg;
510 msg = container_of(msg_hdr, struct
511 xpc_activate_mq_msg_chctl_closereply_uv,
514 spin_lock_irqsave(&part->chctl_lock, irq_flags);
515 part->chctl.flags[msg->ch_number] |= XPC_CHCTL_CLOSEREPLY;
516 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
518 xpc_wakeup_channel_mgr(part);
521 case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV: {
522 struct xpc_activate_mq_msg_chctl_openrequest_uv *msg;
527 msg = container_of(msg_hdr, struct
528 xpc_activate_mq_msg_chctl_openrequest_uv,
530 args = &part->remote_openclose_args[msg->ch_number];
531 args->entry_size = msg->entry_size;
532 args->local_nentries = msg->local_nentries;
534 spin_lock_irqsave(&part->chctl_lock, irq_flags);
535 part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREQUEST;
536 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
538 xpc_wakeup_channel_mgr(part);
541 case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV: {
542 struct xpc_activate_mq_msg_chctl_openreply_uv *msg;
547 msg = container_of(msg_hdr, struct
548 xpc_activate_mq_msg_chctl_openreply_uv, hdr);
549 args = &part->remote_openclose_args[msg->ch_number];
550 args->remote_nentries = msg->remote_nentries;
551 args->local_nentries = msg->local_nentries;
552 args->local_msgqueue_pa = msg->notify_gru_mq_desc_gpa;
554 spin_lock_irqsave(&part->chctl_lock, irq_flags);
555 part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENREPLY;
556 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
558 xpc_wakeup_channel_mgr(part);
561 case XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV: {
562 struct xpc_activate_mq_msg_chctl_opencomplete_uv *msg;
567 msg = container_of(msg_hdr, struct
568 xpc_activate_mq_msg_chctl_opencomplete_uv, hdr);
569 spin_lock_irqsave(&part->chctl_lock, irq_flags);
570 part->chctl.flags[msg->ch_number] |= XPC_CHCTL_OPENCOMPLETE;
571 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
573 xpc_wakeup_channel_mgr(part);
576 case XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV:
577 spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
578 part_uv->flags |= XPC_P_ENGAGED_UV;
579 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
582 case XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV:
583 spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
584 part_uv->flags &= ~XPC_P_ENGAGED_UV;
585 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
589 dev_err(xpc_part, "received unknown activate_mq msg type=%d "
590 "from partition=%d\n", msg_hdr->type, XPC_PARTID(part));
592 /* get hb checker to deactivate from the remote partition */
593 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
594 if (part_uv->act_state_req == 0)
595 xpc_activate_IRQ_rcvd++;
596 part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
597 part_uv->reason = xpBadMsgType;
598 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
600 (*wakeup_hb_checker)++;
604 if (msg_hdr->rp_ts_jiffies != part->remote_rp_ts_jiffies &&
605 part->remote_rp_ts_jiffies != 0) {
607 * ??? Does what we do here need to be sensitive to
608 * ??? act_state or remote_act_state?
610 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
611 if (part_uv->act_state_req == 0)
612 xpc_activate_IRQ_rcvd++;
613 part_uv->act_state_req = XPC_P_ASR_REACTIVATE_UV;
614 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
616 (*wakeup_hb_checker)++;
621 xpc_handle_activate_IRQ_uv(int irq, void *dev_id)
623 struct xpc_activate_mq_msghdr_uv *msg_hdr;
625 struct xpc_partition *part;
626 int wakeup_hb_checker = 0;
630 msg_hdr = gru_get_next_message(xpc_activate_mq_uv->gru_mq_desc);
634 partid = msg_hdr->partid;
635 if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
636 dev_err(xpc_part, "xpc_handle_activate_IRQ_uv() "
637 "received invalid partid=0x%x in message\n",
640 part = &xpc_partitions[partid];
642 part_referenced = xpc_part_ref(part);
643 xpc_handle_activate_mq_msg_uv(part, msg_hdr,
647 xpc_part_deref(part);
650 gru_free_message(xpc_activate_mq_uv->gru_mq_desc, msg_hdr);
653 if (wakeup_hb_checker)
654 wake_up_interruptible(&xpc_activate_IRQ_wq);
659 static enum xp_retval
660 xpc_cache_remote_gru_mq_desc_uv(struct gru_message_queue_desc *gru_mq_desc,
661 unsigned long gru_mq_desc_gpa)
665 ret = xp_remote_memcpy(uv_gpa(gru_mq_desc), gru_mq_desc_gpa,
666 sizeof(struct gru_message_queue_desc));
667 if (ret == xpSuccess)
668 gru_mq_desc->mq = NULL;
673 static enum xp_retval
674 xpc_send_activate_IRQ_uv(struct xpc_partition *part, void *msg, size_t msg_size,
677 struct xpc_activate_mq_msghdr_uv *msg_hdr = msg;
678 struct xpc_partition_uv *part_uv = &part->sn.uv;
679 struct gru_message_queue_desc *gru_mq_desc;
680 unsigned long irq_flags;
683 DBUG_ON(msg_size > XPC_ACTIVATE_MSG_SIZE_UV);
685 msg_hdr->type = msg_type;
686 msg_hdr->partid = xp_partition_id;
687 msg_hdr->act_state = part->act_state;
688 msg_hdr->rp_ts_jiffies = xpc_rsvd_page->ts_jiffies;
690 mutex_lock(&part_uv->cached_activate_gru_mq_desc_mutex);
692 if (!(part_uv->flags & XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV)) {
693 gru_mq_desc = part_uv->cached_activate_gru_mq_desc;
694 if (gru_mq_desc == NULL) {
695 gru_mq_desc = kmalloc(sizeof(struct
696 gru_message_queue_desc),
698 if (gru_mq_desc == NULL) {
702 part_uv->cached_activate_gru_mq_desc = gru_mq_desc;
705 ret = xpc_cache_remote_gru_mq_desc_uv(gru_mq_desc,
707 activate_gru_mq_desc_gpa);
708 if (ret != xpSuccess)
711 spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
712 part_uv->flags |= XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV;
713 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
716 /* ??? Is holding a spin_lock (ch->lock) during this call a bad idea? */
717 ret = xpc_send_gru_msg(part_uv->cached_activate_gru_mq_desc, msg,
719 if (ret != xpSuccess) {
720 smp_rmb(); /* ensure a fresh copy of part_uv->flags */
721 if (!(part_uv->flags & XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV))
725 mutex_unlock(&part_uv->cached_activate_gru_mq_desc_mutex);
730 xpc_send_activate_IRQ_part_uv(struct xpc_partition *part, void *msg,
731 size_t msg_size, int msg_type)
735 ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
736 if (unlikely(ret != xpSuccess))
737 XPC_DEACTIVATE_PARTITION(part, ret);
741 xpc_send_activate_IRQ_ch_uv(struct xpc_channel *ch, unsigned long *irq_flags,
742 void *msg, size_t msg_size, int msg_type)
744 struct xpc_partition *part = &xpc_partitions[ch->partid];
747 ret = xpc_send_activate_IRQ_uv(part, msg, msg_size, msg_type);
748 if (unlikely(ret != xpSuccess)) {
749 if (irq_flags != NULL)
750 spin_unlock_irqrestore(&ch->lock, *irq_flags);
752 XPC_DEACTIVATE_PARTITION(part, ret);
754 if (irq_flags != NULL)
755 spin_lock_irqsave(&ch->lock, *irq_flags);
760 xpc_send_local_activate_IRQ_uv(struct xpc_partition *part, int act_state_req)
762 unsigned long irq_flags;
763 struct xpc_partition_uv *part_uv = &part->sn.uv;
766 * !!! Make our side think that the remote partition sent an activate
767 * !!! mq message our way by doing what the activate IRQ handler would
768 * !!! do had one really been sent.
771 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
772 if (part_uv->act_state_req == 0)
773 xpc_activate_IRQ_rcvd++;
774 part_uv->act_state_req = act_state_req;
775 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
777 wake_up_interruptible(&xpc_activate_IRQ_wq);
780 static enum xp_retval
781 xpc_get_partition_rsvd_page_pa_uv(void *buf, u64 *cookie, unsigned long *rp_pa,
787 #if defined CONFIG_X86_64
788 status = uv_bios_reserved_page_pa((u64)buf, cookie, (u64 *)rp_pa,
790 if (status == BIOS_STATUS_SUCCESS)
792 else if (status == BIOS_STATUS_MORE_PASSES)
793 ret = xpNeedMoreInfo;
797 #elif defined CONFIG_IA64_GENERIC || defined CONFIG_IA64_SGI_UV
798 status = sn_partition_reserved_page_pa((u64)buf, cookie, rp_pa, len);
799 if (status == SALRET_OK)
801 else if (status == SALRET_MORE_PASSES)
802 ret = xpNeedMoreInfo;
807 #error not a supported configuration
814 xpc_setup_rsvd_page_uv(struct xpc_rsvd_page *rp)
817 &xpc_partitions[sn_partition_id].sn.uv.cached_heartbeat;
818 rp->sn.uv.heartbeat_gpa = uv_gpa(xpc_heartbeat_uv);
819 rp->sn.uv.activate_gru_mq_desc_gpa =
820 uv_gpa(xpc_activate_mq_uv->gru_mq_desc);
825 xpc_allow_hb_uv(short partid)
830 xpc_disallow_hb_uv(short partid)
835 xpc_disallow_all_hbs_uv(void)
840 xpc_increment_heartbeat_uv(void)
842 xpc_heartbeat_uv->value++;
846 xpc_offline_heartbeat_uv(void)
848 xpc_increment_heartbeat_uv();
849 xpc_heartbeat_uv->offline = 1;
853 xpc_online_heartbeat_uv(void)
855 xpc_increment_heartbeat_uv();
856 xpc_heartbeat_uv->offline = 0;
860 xpc_heartbeat_init_uv(void)
862 xpc_heartbeat_uv->value = 1;
863 xpc_heartbeat_uv->offline = 0;
867 xpc_heartbeat_exit_uv(void)
869 xpc_offline_heartbeat_uv();
872 static enum xp_retval
873 xpc_get_remote_heartbeat_uv(struct xpc_partition *part)
875 struct xpc_partition_uv *part_uv = &part->sn.uv;
878 ret = xp_remote_memcpy(uv_gpa(&part_uv->cached_heartbeat),
879 part_uv->heartbeat_gpa,
880 sizeof(struct xpc_heartbeat_uv));
881 if (ret != xpSuccess)
884 if (part_uv->cached_heartbeat.value == part->last_heartbeat &&
885 !part_uv->cached_heartbeat.offline) {
889 part->last_heartbeat = part_uv->cached_heartbeat.value;
895 xpc_request_partition_activation_uv(struct xpc_rsvd_page *remote_rp,
896 unsigned long remote_rp_gpa, int nasid)
898 short partid = remote_rp->SAL_partid;
899 struct xpc_partition *part = &xpc_partitions[partid];
900 struct xpc_activate_mq_msg_activate_req_uv msg;
902 part->remote_rp_pa = remote_rp_gpa; /* !!! _pa here is really _gpa */
903 part->remote_rp_ts_jiffies = remote_rp->ts_jiffies;
904 part->sn.uv.heartbeat_gpa = remote_rp->sn.uv.heartbeat_gpa;
905 part->sn.uv.activate_gru_mq_desc_gpa =
906 remote_rp->sn.uv.activate_gru_mq_desc_gpa;
909 * ??? Is it a good idea to make this conditional on what is
910 * ??? potentially stale state information?
912 if (part->sn.uv.remote_act_state == XPC_P_AS_INACTIVE) {
913 msg.rp_gpa = uv_gpa(xpc_rsvd_page);
914 msg.heartbeat_gpa = xpc_rsvd_page->sn.uv.heartbeat_gpa;
915 msg.activate_gru_mq_desc_gpa =
916 xpc_rsvd_page->sn.uv.activate_gru_mq_desc_gpa;
917 xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
918 XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV);
921 if (part->act_state == XPC_P_AS_INACTIVE)
922 xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
926 xpc_request_partition_reactivation_uv(struct xpc_partition *part)
928 xpc_send_local_activate_IRQ_uv(part, XPC_P_ASR_ACTIVATE_UV);
932 xpc_request_partition_deactivation_uv(struct xpc_partition *part)
934 struct xpc_activate_mq_msg_deactivate_req_uv msg;
937 * ??? Is it a good idea to make this conditional on what is
938 * ??? potentially stale state information?
940 if (part->sn.uv.remote_act_state != XPC_P_AS_DEACTIVATING &&
941 part->sn.uv.remote_act_state != XPC_P_AS_INACTIVE) {
943 msg.reason = part->reason;
944 xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
945 XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV);
950 xpc_cancel_partition_deactivation_request_uv(struct xpc_partition *part)
952 /* nothing needs to be done */
957 xpc_init_fifo_uv(struct xpc_fifo_head_uv *head)
961 spin_lock_init(&head->lock);
966 xpc_get_fifo_entry_uv(struct xpc_fifo_head_uv *head)
968 unsigned long irq_flags;
969 struct xpc_fifo_entry_uv *first;
971 spin_lock_irqsave(&head->lock, irq_flags);
973 if (head->first != NULL) {
974 head->first = first->next;
975 if (head->first == NULL)
979 BUG_ON(head->n_entries < 0);
983 spin_unlock_irqrestore(&head->lock, irq_flags);
988 xpc_put_fifo_entry_uv(struct xpc_fifo_head_uv *head,
989 struct xpc_fifo_entry_uv *last)
991 unsigned long irq_flags;
994 spin_lock_irqsave(&head->lock, irq_flags);
995 if (head->last != NULL)
996 head->last->next = last;
1001 spin_unlock_irqrestore(&head->lock, irq_flags);
1005 xpc_n_of_fifo_entries_uv(struct xpc_fifo_head_uv *head)
1007 return head->n_entries;
1011 * Setup the channel structures that are uv specific.
1013 static enum xp_retval
1014 xpc_setup_ch_structures_uv(struct xpc_partition *part)
1016 struct xpc_channel_uv *ch_uv;
1019 for (ch_number = 0; ch_number < part->nchannels; ch_number++) {
1020 ch_uv = &part->channels[ch_number].sn.uv;
1022 xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
1023 xpc_init_fifo_uv(&ch_uv->recv_msg_list);
1030 * Teardown the channel structures that are uv specific.
1033 xpc_teardown_ch_structures_uv(struct xpc_partition *part)
1035 /* nothing needs to be done */
1039 static enum xp_retval
1040 xpc_make_first_contact_uv(struct xpc_partition *part)
1042 struct xpc_activate_mq_msg_uv msg;
1045 * We send a sync msg to get the remote partition's remote_act_state
1046 * updated to our current act_state which at this point should
1047 * be XPC_P_AS_ACTIVATING.
1049 xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
1050 XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV);
1052 while (!((part->sn.uv.remote_act_state == XPC_P_AS_ACTIVATING) ||
1053 (part->sn.uv.remote_act_state == XPC_P_AS_ACTIVE))) {
1055 dev_dbg(xpc_part, "waiting to make first contact with "
1056 "partition %d\n", XPC_PARTID(part));
1058 /* wait a 1/4 of a second or so */
1059 (void)msleep_interruptible(250);
1061 if (part->act_state == XPC_P_AS_DEACTIVATING)
1062 return part->reason;
1069 xpc_get_chctl_all_flags_uv(struct xpc_partition *part)
1071 unsigned long irq_flags;
1072 union xpc_channel_ctl_flags chctl;
1074 spin_lock_irqsave(&part->chctl_lock, irq_flags);
1075 chctl = part->chctl;
1076 if (chctl.all_flags != 0)
1077 part->chctl.all_flags = 0;
1079 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
1080 return chctl.all_flags;
1083 static enum xp_retval
1084 xpc_allocate_send_msg_slot_uv(struct xpc_channel *ch)
1086 struct xpc_channel_uv *ch_uv = &ch->sn.uv;
1087 struct xpc_send_msg_slot_uv *msg_slot;
1088 unsigned long irq_flags;
1093 for (nentries = ch->local_nentries; nentries > 0; nentries--) {
1094 nbytes = nentries * sizeof(struct xpc_send_msg_slot_uv);
1095 ch_uv->send_msg_slots = kzalloc(nbytes, GFP_KERNEL);
1096 if (ch_uv->send_msg_slots == NULL)
1099 for (entry = 0; entry < nentries; entry++) {
1100 msg_slot = &ch_uv->send_msg_slots[entry];
1102 msg_slot->msg_slot_number = entry;
1103 xpc_put_fifo_entry_uv(&ch_uv->msg_slot_free_list,
1107 spin_lock_irqsave(&ch->lock, irq_flags);
1108 if (nentries < ch->local_nentries)
1109 ch->local_nentries = nentries;
1110 spin_unlock_irqrestore(&ch->lock, irq_flags);
1117 static enum xp_retval
1118 xpc_allocate_recv_msg_slot_uv(struct xpc_channel *ch)
1120 struct xpc_channel_uv *ch_uv = &ch->sn.uv;
1121 struct xpc_notify_mq_msg_uv *msg_slot;
1122 unsigned long irq_flags;
1127 for (nentries = ch->remote_nentries; nentries > 0; nentries--) {
1128 nbytes = nentries * ch->entry_size;
1129 ch_uv->recv_msg_slots = kzalloc(nbytes, GFP_KERNEL);
1130 if (ch_uv->recv_msg_slots == NULL)
1133 for (entry = 0; entry < nentries; entry++) {
1134 msg_slot = ch_uv->recv_msg_slots +
1135 entry * ch->entry_size;
1137 msg_slot->hdr.msg_slot_number = entry;
1140 spin_lock_irqsave(&ch->lock, irq_flags);
1141 if (nentries < ch->remote_nentries)
1142 ch->remote_nentries = nentries;
1143 spin_unlock_irqrestore(&ch->lock, irq_flags);
1151 * Allocate msg_slots associated with the channel.
1153 static enum xp_retval
1154 xpc_setup_msg_structures_uv(struct xpc_channel *ch)
1156 static enum xp_retval ret;
1157 struct xpc_channel_uv *ch_uv = &ch->sn.uv;
1159 DBUG_ON(ch->flags & XPC_C_SETUP);
1161 ch_uv->cached_notify_gru_mq_desc = kmalloc(sizeof(struct
1162 gru_message_queue_desc),
1164 if (ch_uv->cached_notify_gru_mq_desc == NULL)
1167 ret = xpc_allocate_send_msg_slot_uv(ch);
1168 if (ret == xpSuccess) {
1170 ret = xpc_allocate_recv_msg_slot_uv(ch);
1171 if (ret != xpSuccess) {
1172 kfree(ch_uv->send_msg_slots);
1173 xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
1180 * Free up msg_slots and clear other stuff that were setup for the specified
1184 xpc_teardown_msg_structures_uv(struct xpc_channel *ch)
1186 struct xpc_channel_uv *ch_uv = &ch->sn.uv;
1188 lockdep_assert_held(&ch->lock);
1190 kfree(ch_uv->cached_notify_gru_mq_desc);
1191 ch_uv->cached_notify_gru_mq_desc = NULL;
1193 if (ch->flags & XPC_C_SETUP) {
1194 xpc_init_fifo_uv(&ch_uv->msg_slot_free_list);
1195 kfree(ch_uv->send_msg_slots);
1196 xpc_init_fifo_uv(&ch_uv->recv_msg_list);
1197 kfree(ch_uv->recv_msg_slots);
1202 xpc_send_chctl_closerequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
1204 struct xpc_activate_mq_msg_chctl_closerequest_uv msg;
1206 msg.ch_number = ch->number;
1207 msg.reason = ch->reason;
1208 xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
1209 XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV);
1213 xpc_send_chctl_closereply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
1215 struct xpc_activate_mq_msg_chctl_closereply_uv msg;
1217 msg.ch_number = ch->number;
1218 xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
1219 XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV);
1223 xpc_send_chctl_openrequest_uv(struct xpc_channel *ch, unsigned long *irq_flags)
1225 struct xpc_activate_mq_msg_chctl_openrequest_uv msg;
1227 msg.ch_number = ch->number;
1228 msg.entry_size = ch->entry_size;
1229 msg.local_nentries = ch->local_nentries;
1230 xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
1231 XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV);
1235 xpc_send_chctl_openreply_uv(struct xpc_channel *ch, unsigned long *irq_flags)
1237 struct xpc_activate_mq_msg_chctl_openreply_uv msg;
1239 msg.ch_number = ch->number;
1240 msg.local_nentries = ch->local_nentries;
1241 msg.remote_nentries = ch->remote_nentries;
1242 msg.notify_gru_mq_desc_gpa = uv_gpa(xpc_notify_mq_uv->gru_mq_desc);
1243 xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
1244 XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV);
1248 xpc_send_chctl_opencomplete_uv(struct xpc_channel *ch, unsigned long *irq_flags)
1250 struct xpc_activate_mq_msg_chctl_opencomplete_uv msg;
1252 msg.ch_number = ch->number;
1253 xpc_send_activate_IRQ_ch_uv(ch, irq_flags, &msg, sizeof(msg),
1254 XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV);
1258 xpc_send_chctl_local_msgrequest_uv(struct xpc_partition *part, int ch_number)
1260 unsigned long irq_flags;
1262 spin_lock_irqsave(&part->chctl_lock, irq_flags);
1263 part->chctl.flags[ch_number] |= XPC_CHCTL_MSGREQUEST;
1264 spin_unlock_irqrestore(&part->chctl_lock, irq_flags);
1266 xpc_wakeup_channel_mgr(part);
1269 static enum xp_retval
1270 xpc_save_remote_msgqueue_pa_uv(struct xpc_channel *ch,
1271 unsigned long gru_mq_desc_gpa)
1273 struct xpc_channel_uv *ch_uv = &ch->sn.uv;
1275 DBUG_ON(ch_uv->cached_notify_gru_mq_desc == NULL);
1276 return xpc_cache_remote_gru_mq_desc_uv(ch_uv->cached_notify_gru_mq_desc,
1281 xpc_indicate_partition_engaged_uv(struct xpc_partition *part)
1283 struct xpc_activate_mq_msg_uv msg;
1285 xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
1286 XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV);
1290 xpc_indicate_partition_disengaged_uv(struct xpc_partition *part)
1292 struct xpc_activate_mq_msg_uv msg;
1294 xpc_send_activate_IRQ_part_uv(part, &msg, sizeof(msg),
1295 XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV);
1299 xpc_assume_partition_disengaged_uv(short partid)
1301 struct xpc_partition_uv *part_uv = &xpc_partitions[partid].sn.uv;
1302 unsigned long irq_flags;
1304 spin_lock_irqsave(&part_uv->flags_lock, irq_flags);
1305 part_uv->flags &= ~XPC_P_ENGAGED_UV;
1306 spin_unlock_irqrestore(&part_uv->flags_lock, irq_flags);
1310 xpc_partition_engaged_uv(short partid)
1312 return (xpc_partitions[partid].sn.uv.flags & XPC_P_ENGAGED_UV) != 0;
1316 xpc_any_partition_engaged_uv(void)
1318 struct xpc_partition_uv *part_uv;
1321 for (partid = 0; partid < XP_MAX_NPARTITIONS_UV; partid++) {
1322 part_uv = &xpc_partitions[partid].sn.uv;
1323 if ((part_uv->flags & XPC_P_ENGAGED_UV) != 0)
1329 static enum xp_retval
1330 xpc_allocate_msg_slot_uv(struct xpc_channel *ch, u32 flags,
1331 struct xpc_send_msg_slot_uv **address_of_msg_slot)
1334 struct xpc_send_msg_slot_uv *msg_slot;
1335 struct xpc_fifo_entry_uv *entry;
1338 entry = xpc_get_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list);
1342 if (flags & XPC_NOWAIT)
1345 ret = xpc_allocate_msg_wait(ch);
1346 if (ret != xpInterrupted && ret != xpTimeout)
1350 msg_slot = container_of(entry, struct xpc_send_msg_slot_uv, next);
1351 *address_of_msg_slot = msg_slot;
1356 xpc_free_msg_slot_uv(struct xpc_channel *ch,
1357 struct xpc_send_msg_slot_uv *msg_slot)
1359 xpc_put_fifo_entry_uv(&ch->sn.uv.msg_slot_free_list, &msg_slot->next);
1361 /* wakeup anyone waiting for a free msg slot */
1362 if (atomic_read(&ch->n_on_msg_allocate_wq) > 0)
1363 wake_up(&ch->msg_allocate_wq);
1367 xpc_notify_sender_uv(struct xpc_channel *ch,
1368 struct xpc_send_msg_slot_uv *msg_slot,
1369 enum xp_retval reason)
1371 xpc_notify_func func = msg_slot->func;
1373 if (func != NULL && cmpxchg(&msg_slot->func, func, NULL) == func) {
1375 atomic_dec(&ch->n_to_notify);
1377 dev_dbg(xpc_chan, "msg_slot->func() called, msg_slot=0x%p "
1378 "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
1379 msg_slot->msg_slot_number, ch->partid, ch->number);
1381 func(reason, ch->partid, ch->number, msg_slot->key);
1383 dev_dbg(xpc_chan, "msg_slot->func() returned, msg_slot=0x%p "
1384 "msg_slot_number=%d partid=%d channel=%d\n", msg_slot,
1385 msg_slot->msg_slot_number, ch->partid, ch->number);
1390 xpc_handle_notify_mq_ack_uv(struct xpc_channel *ch,
1391 struct xpc_notify_mq_msg_uv *msg)
1393 struct xpc_send_msg_slot_uv *msg_slot;
1394 int entry = msg->hdr.msg_slot_number % ch->local_nentries;
1396 msg_slot = &ch->sn.uv.send_msg_slots[entry];
1398 BUG_ON(msg_slot->msg_slot_number != msg->hdr.msg_slot_number);
1399 msg_slot->msg_slot_number += ch->local_nentries;
1401 if (msg_slot->func != NULL)
1402 xpc_notify_sender_uv(ch, msg_slot, xpMsgDelivered);
1404 xpc_free_msg_slot_uv(ch, msg_slot);
1408 xpc_handle_notify_mq_msg_uv(struct xpc_partition *part,
1409 struct xpc_notify_mq_msg_uv *msg)
1411 struct xpc_partition_uv *part_uv = &part->sn.uv;
1412 struct xpc_channel *ch;
1413 struct xpc_channel_uv *ch_uv;
1414 struct xpc_notify_mq_msg_uv *msg_slot;
1415 unsigned long irq_flags;
1416 int ch_number = msg->hdr.ch_number;
1418 if (unlikely(ch_number >= part->nchannels)) {
1419 dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received invalid "
1420 "channel number=0x%x in message from partid=%d\n",
1421 ch_number, XPC_PARTID(part));
1423 /* get hb checker to deactivate from the remote partition */
1424 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock, irq_flags);
1425 if (part_uv->act_state_req == 0)
1426 xpc_activate_IRQ_rcvd++;
1427 part_uv->act_state_req = XPC_P_ASR_DEACTIVATE_UV;
1428 part_uv->reason = xpBadChannelNumber;
1429 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock, irq_flags);
1431 wake_up_interruptible(&xpc_activate_IRQ_wq);
1435 ch = &part->channels[ch_number];
1436 xpc_msgqueue_ref(ch);
1438 if (!(ch->flags & XPC_C_CONNECTED)) {
1439 xpc_msgqueue_deref(ch);
1443 /* see if we're really dealing with an ACK for a previously sent msg */
1444 if (msg->hdr.size == 0) {
1445 xpc_handle_notify_mq_ack_uv(ch, msg);
1446 xpc_msgqueue_deref(ch);
1450 /* we're dealing with a normal message sent via the notify_mq */
1453 msg_slot = ch_uv->recv_msg_slots +
1454 (msg->hdr.msg_slot_number % ch->remote_nentries) * ch->entry_size;
1456 BUG_ON(msg_slot->hdr.size != 0);
1458 memcpy(msg_slot, msg, msg->hdr.size);
1460 xpc_put_fifo_entry_uv(&ch_uv->recv_msg_list, &msg_slot->hdr.u.next);
1462 if (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE) {
1464 * If there is an existing idle kthread get it to deliver
1465 * the payload, otherwise we'll have to get the channel mgr
1466 * for this partition to create a kthread to do the delivery.
1468 if (atomic_read(&ch->kthreads_idle) > 0)
1469 wake_up_nr(&ch->idle_wq, 1);
1471 xpc_send_chctl_local_msgrequest_uv(part, ch->number);
1473 xpc_msgqueue_deref(ch);
1477 xpc_handle_notify_IRQ_uv(int irq, void *dev_id)
1479 struct xpc_notify_mq_msg_uv *msg;
1481 struct xpc_partition *part;
1483 while ((msg = gru_get_next_message(xpc_notify_mq_uv->gru_mq_desc)) !=
1486 partid = msg->hdr.partid;
1487 if (partid < 0 || partid >= XP_MAX_NPARTITIONS_UV) {
1488 dev_err(xpc_part, "xpc_handle_notify_IRQ_uv() received "
1489 "invalid partid=0x%x in message\n", partid);
1491 part = &xpc_partitions[partid];
1493 if (xpc_part_ref(part)) {
1494 xpc_handle_notify_mq_msg_uv(part, msg);
1495 xpc_part_deref(part);
1499 gru_free_message(xpc_notify_mq_uv->gru_mq_desc, msg);
1506 xpc_n_of_deliverable_payloads_uv(struct xpc_channel *ch)
1508 return xpc_n_of_fifo_entries_uv(&ch->sn.uv.recv_msg_list);
1512 xpc_process_msg_chctl_flags_uv(struct xpc_partition *part, int ch_number)
1514 struct xpc_channel *ch = &part->channels[ch_number];
1515 int ndeliverable_payloads;
1517 xpc_msgqueue_ref(ch);
1519 ndeliverable_payloads = xpc_n_of_deliverable_payloads_uv(ch);
1521 if (ndeliverable_payloads > 0 &&
1522 (ch->flags & XPC_C_CONNECTED) &&
1523 (ch->flags & XPC_C_CONNECTEDCALLOUT_MADE)) {
1525 xpc_activate_kthreads(ch, ndeliverable_payloads);
1528 xpc_msgqueue_deref(ch);
1531 static enum xp_retval
1532 xpc_send_payload_uv(struct xpc_channel *ch, u32 flags, void *payload,
1533 u16 payload_size, u8 notify_type, xpc_notify_func func,
1536 enum xp_retval ret = xpSuccess;
1537 struct xpc_send_msg_slot_uv *msg_slot = NULL;
1538 struct xpc_notify_mq_msg_uv *msg;
1539 u8 msg_buffer[XPC_NOTIFY_MSG_SIZE_UV];
1542 DBUG_ON(notify_type != XPC_N_CALL);
1544 msg_size = sizeof(struct xpc_notify_mq_msghdr_uv) + payload_size;
1545 if (msg_size > ch->entry_size)
1546 return xpPayloadTooBig;
1548 xpc_msgqueue_ref(ch);
1550 if (ch->flags & XPC_C_DISCONNECTING) {
1554 if (!(ch->flags & XPC_C_CONNECTED)) {
1555 ret = xpNotConnected;
1559 ret = xpc_allocate_msg_slot_uv(ch, flags, &msg_slot);
1560 if (ret != xpSuccess)
1564 atomic_inc(&ch->n_to_notify);
1566 msg_slot->key = key;
1567 smp_wmb(); /* a non-NULL func must hit memory after the key */
1568 msg_slot->func = func;
1570 if (ch->flags & XPC_C_DISCONNECTING) {
1576 msg = (struct xpc_notify_mq_msg_uv *)&msg_buffer;
1577 msg->hdr.partid = xp_partition_id;
1578 msg->hdr.ch_number = ch->number;
1579 msg->hdr.size = msg_size;
1580 msg->hdr.msg_slot_number = msg_slot->msg_slot_number;
1581 memcpy(&msg->payload, payload, payload_size);
1583 ret = xpc_send_gru_msg(ch->sn.uv.cached_notify_gru_mq_desc, msg,
1585 if (ret == xpSuccess)
1588 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
1592 * Try to NULL the msg_slot's func field. If we fail, then
1593 * xpc_notify_senders_of_disconnect_uv() beat us to it, in which
1594 * case we need to pretend we succeeded to send the message
1595 * since the user will get a callout for the disconnect error
1596 * by xpc_notify_senders_of_disconnect_uv(), and to also get an
1597 * error returned here will confuse them. Additionally, since
1598 * in this case the channel is being disconnected we don't need
1599 * to put the the msg_slot back on the free list.
1601 if (cmpxchg(&msg_slot->func, func, NULL) != func) {
1606 msg_slot->key = NULL;
1607 atomic_dec(&ch->n_to_notify);
1609 xpc_free_msg_slot_uv(ch, msg_slot);
1611 xpc_msgqueue_deref(ch);
1616 * Tell the callers of xpc_send_notify() that the status of their payloads
1617 * is unknown because the channel is now disconnecting.
1619 * We don't worry about putting these msg_slots on the free list since the
1620 * msg_slots themselves are about to be kfree'd.
1623 xpc_notify_senders_of_disconnect_uv(struct xpc_channel *ch)
1625 struct xpc_send_msg_slot_uv *msg_slot;
1628 DBUG_ON(!(ch->flags & XPC_C_DISCONNECTING));
1630 for (entry = 0; entry < ch->local_nentries; entry++) {
1632 if (atomic_read(&ch->n_to_notify) == 0)
1635 msg_slot = &ch->sn.uv.send_msg_slots[entry];
1636 if (msg_slot->func != NULL)
1637 xpc_notify_sender_uv(ch, msg_slot, ch->reason);
1642 * Get the next deliverable message's payload.
1645 xpc_get_deliverable_payload_uv(struct xpc_channel *ch)
1647 struct xpc_fifo_entry_uv *entry;
1648 struct xpc_notify_mq_msg_uv *msg;
1649 void *payload = NULL;
1651 if (!(ch->flags & XPC_C_DISCONNECTING)) {
1652 entry = xpc_get_fifo_entry_uv(&ch->sn.uv.recv_msg_list);
1653 if (entry != NULL) {
1654 msg = container_of(entry, struct xpc_notify_mq_msg_uv,
1656 payload = &msg->payload;
1663 xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
1665 struct xpc_notify_mq_msg_uv *msg;
1668 msg = container_of(payload, struct xpc_notify_mq_msg_uv, payload);
1670 /* return an ACK to the sender of this message */
1672 msg->hdr.partid = xp_partition_id;
1673 msg->hdr.size = 0; /* size of zero indicates this is an ACK */
1675 ret = xpc_send_gru_msg(ch->sn.uv.cached_notify_gru_mq_desc, msg,
1676 sizeof(struct xpc_notify_mq_msghdr_uv));
1677 if (ret != xpSuccess)
1678 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
1681 static struct xpc_arch_operations xpc_arch_ops_uv = {
1682 .setup_partitions = xpc_setup_partitions_uv,
1683 .teardown_partitions = xpc_teardown_partitions_uv,
1684 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
1685 .get_partition_rsvd_page_pa = xpc_get_partition_rsvd_page_pa_uv,
1686 .setup_rsvd_page = xpc_setup_rsvd_page_uv,
1688 .allow_hb = xpc_allow_hb_uv,
1689 .disallow_hb = xpc_disallow_hb_uv,
1690 .disallow_all_hbs = xpc_disallow_all_hbs_uv,
1691 .increment_heartbeat = xpc_increment_heartbeat_uv,
1692 .offline_heartbeat = xpc_offline_heartbeat_uv,
1693 .online_heartbeat = xpc_online_heartbeat_uv,
1694 .heartbeat_init = xpc_heartbeat_init_uv,
1695 .heartbeat_exit = xpc_heartbeat_exit_uv,
1696 .get_remote_heartbeat = xpc_get_remote_heartbeat_uv,
1698 .request_partition_activation =
1699 xpc_request_partition_activation_uv,
1700 .request_partition_reactivation =
1701 xpc_request_partition_reactivation_uv,
1702 .request_partition_deactivation =
1703 xpc_request_partition_deactivation_uv,
1704 .cancel_partition_deactivation_request =
1705 xpc_cancel_partition_deactivation_request_uv,
1707 .setup_ch_structures = xpc_setup_ch_structures_uv,
1708 .teardown_ch_structures = xpc_teardown_ch_structures_uv,
1710 .make_first_contact = xpc_make_first_contact_uv,
1712 .get_chctl_all_flags = xpc_get_chctl_all_flags_uv,
1713 .send_chctl_closerequest = xpc_send_chctl_closerequest_uv,
1714 .send_chctl_closereply = xpc_send_chctl_closereply_uv,
1715 .send_chctl_openrequest = xpc_send_chctl_openrequest_uv,
1716 .send_chctl_openreply = xpc_send_chctl_openreply_uv,
1717 .send_chctl_opencomplete = xpc_send_chctl_opencomplete_uv,
1718 .process_msg_chctl_flags = xpc_process_msg_chctl_flags_uv,
1720 .save_remote_msgqueue_pa = xpc_save_remote_msgqueue_pa_uv,
1722 .setup_msg_structures = xpc_setup_msg_structures_uv,
1723 .teardown_msg_structures = xpc_teardown_msg_structures_uv,
1725 .indicate_partition_engaged = xpc_indicate_partition_engaged_uv,
1726 .indicate_partition_disengaged = xpc_indicate_partition_disengaged_uv,
1727 .assume_partition_disengaged = xpc_assume_partition_disengaged_uv,
1728 .partition_engaged = xpc_partition_engaged_uv,
1729 .any_partition_engaged = xpc_any_partition_engaged_uv,
1731 .n_of_deliverable_payloads = xpc_n_of_deliverable_payloads_uv,
1732 .send_payload = xpc_send_payload_uv,
1733 .get_deliverable_payload = xpc_get_deliverable_payload_uv,
1734 .received_payload = xpc_received_payload_uv,
1735 .notify_senders_of_disconnect = xpc_notify_senders_of_disconnect_uv,
1739 xpc_init_mq_node(int nid)
1745 for_each_cpu(cpu, cpumask_of_node(nid)) {
1746 xpc_activate_mq_uv =
1747 xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, nid,
1748 XPC_ACTIVATE_IRQ_NAME,
1749 xpc_handle_activate_IRQ_uv);
1750 if (!IS_ERR(xpc_activate_mq_uv))
1753 if (IS_ERR(xpc_activate_mq_uv)) {
1755 return PTR_ERR(xpc_activate_mq_uv);
1758 for_each_cpu(cpu, cpumask_of_node(nid)) {
1760 xpc_create_gru_mq_uv(XPC_NOTIFY_MQ_SIZE_UV, nid,
1761 XPC_NOTIFY_IRQ_NAME,
1762 xpc_handle_notify_IRQ_uv);
1763 if (!IS_ERR(xpc_notify_mq_uv))
1766 if (IS_ERR(xpc_notify_mq_uv)) {
1767 xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
1769 return PTR_ERR(xpc_notify_mq_uv);
1782 xpc_arch_ops = xpc_arch_ops_uv;
1784 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
1785 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
1786 XPC_MSG_HDR_MAX_SIZE);
1790 if (xpc_mq_node < 0)
1791 for_each_online_node(nid) {
1792 ret = xpc_init_mq_node(nid);
1798 ret = xpc_init_mq_node(xpc_mq_node);
1801 dev_err(xpc_part, "xpc_init_mq_node() returned error=%d\n",
1810 xpc_destroy_gru_mq_uv(xpc_notify_mq_uv);
1811 xpc_destroy_gru_mq_uv(xpc_activate_mq_uv);
1814 module_param(xpc_mq_node, int, 0);
1815 MODULE_PARM_DESC(xpc_mq_node, "Node number on which to allocate message queues.");