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