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) sn2-based functions.
12 * Architecture specific implementation of common functions.
16 #include <linux/delay.h>
17 #include <asm/uncached.h>
18 #include <asm/sn/mspec.h>
19 #include <asm/sn/sn_sal.h>
23 * Define the number of u64s required to represent all the C-brick nasids
24 * as a bitmap. The cross-partition kernel modules deal only with
25 * C-brick nasids, thus the need for bitmaps which don't account for
26 * odd-numbered (non C-brick) nasids.
28 #define XPC_MAX_PHYSNODES_SN2 (MAX_NUMALINK_NODES / 2)
29 #define XP_NASID_MASK_BYTES_SN2 ((XPC_MAX_PHYSNODES_SN2 + 7) / 8)
30 #define XP_NASID_MASK_WORDS_SN2 ((XPC_MAX_PHYSNODES_SN2 + 63) / 64)
33 * Memory for XPC's amo variables is allocated by the MSPEC driver. These
34 * pages are located in the lowest granule. The lowest granule uses 4k pages
35 * for cached references and an alternate TLB handler to never provide a
36 * cacheable mapping for the entire region. This will prevent speculative
37 * reading of cached copies of our lines from being issued which will cause
38 * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
39 * amo variables (based on XP_MAX_NPARTITIONS_SN2) to identify the senders of
40 * NOTIFY IRQs, 128 amo variables (based on XP_NASID_MASK_WORDS_SN2) to identify
41 * the senders of ACTIVATE IRQs, 1 amo variable to identify which remote
42 * partitions (i.e., XPCs) consider themselves currently engaged with the
43 * local XPC and 1 amo variable to request partition deactivation.
45 #define XPC_NOTIFY_IRQ_AMOS_SN2 0
46 #define XPC_ACTIVATE_IRQ_AMOS_SN2 (XPC_NOTIFY_IRQ_AMOS_SN2 + \
47 XP_MAX_NPARTITIONS_SN2)
48 #define XPC_ENGAGED_PARTITIONS_AMO_SN2 (XPC_ACTIVATE_IRQ_AMOS_SN2 + \
49 XP_NASID_MASK_WORDS_SN2)
50 #define XPC_DEACTIVATE_REQUEST_AMO_SN2 (XPC_ENGAGED_PARTITIONS_AMO_SN2 + 1)
53 * Buffer used to store a local copy of portions of a remote partition's
54 * reserved page (either its header and part_nasids mask, or its vars).
56 static void *xpc_remote_copy_buffer_base_sn2
;
57 static char *xpc_remote_copy_buffer_sn2
;
59 static struct xpc_vars_sn2
*xpc_vars_sn2
;
60 static struct xpc_vars_part_sn2
*xpc_vars_part_sn2
;
63 xpc_setup_partitions_sn2(void)
65 /* nothing needs to be done */
70 xpc_teardown_partitions_sn2(void)
72 /* nothing needs to be done */
75 /* SH_IPI_ACCESS shub register value on startup */
76 static u64 xpc_sh1_IPI_access_sn2
;
77 static u64 xpc_sh2_IPI_access0_sn2
;
78 static u64 xpc_sh2_IPI_access1_sn2
;
79 static u64 xpc_sh2_IPI_access2_sn2
;
80 static u64 xpc_sh2_IPI_access3_sn2
;
83 * Change protections to allow IPI operations.
86 xpc_allow_IPI_ops_sn2(void)
91 /* !!! The following should get moved into SAL. */
93 xpc_sh2_IPI_access0_sn2
=
94 (u64
)HUB_L((u64
*)LOCAL_MMR_ADDR(SH2_IPI_ACCESS0
));
95 xpc_sh2_IPI_access1_sn2
=
96 (u64
)HUB_L((u64
*)LOCAL_MMR_ADDR(SH2_IPI_ACCESS1
));
97 xpc_sh2_IPI_access2_sn2
=
98 (u64
)HUB_L((u64
*)LOCAL_MMR_ADDR(SH2_IPI_ACCESS2
));
99 xpc_sh2_IPI_access3_sn2
=
100 (u64
)HUB_L((u64
*)LOCAL_MMR_ADDR(SH2_IPI_ACCESS3
));
102 for_each_online_node(node
) {
103 nasid
= cnodeid_to_nasid(node
);
104 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS0
),
106 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS1
),
108 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS2
),
110 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS3
),
114 xpc_sh1_IPI_access_sn2
=
115 (u64
)HUB_L((u64
*)LOCAL_MMR_ADDR(SH1_IPI_ACCESS
));
117 for_each_online_node(node
) {
118 nasid
= cnodeid_to_nasid(node
);
119 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH1_IPI_ACCESS
),
126 * Restrict protections to disallow IPI operations.
129 xpc_disallow_IPI_ops_sn2(void)
134 /* !!! The following should get moved into SAL. */
136 for_each_online_node(node
) {
137 nasid
= cnodeid_to_nasid(node
);
138 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS0
),
139 xpc_sh2_IPI_access0_sn2
);
140 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS1
),
141 xpc_sh2_IPI_access1_sn2
);
142 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS2
),
143 xpc_sh2_IPI_access2_sn2
);
144 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH2_IPI_ACCESS3
),
145 xpc_sh2_IPI_access3_sn2
);
148 for_each_online_node(node
) {
149 nasid
= cnodeid_to_nasid(node
);
150 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
, SH1_IPI_ACCESS
),
151 xpc_sh1_IPI_access_sn2
);
157 * The following set of functions are used for the sending and receiving of
158 * IRQs (also known as IPIs). There are two flavors of IRQs, one that is
159 * associated with partition activity (SGI_XPC_ACTIVATE) and the other that
160 * is associated with channel activity (SGI_XPC_NOTIFY).
164 xpc_receive_IRQ_amo_sn2(struct amo
*amo
)
166 return FETCHOP_LOAD_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_CLEAR
);
169 static enum xp_retval
170 xpc_send_IRQ_sn2(struct amo
*amo
, u64 flag
, int nasid
, int phys_cpuid
,
174 unsigned long irq_flags
;
176 local_irq_save(irq_flags
);
178 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_OR
, flag
);
179 sn_send_IPI_phys(nasid
, phys_cpuid
, vector
, 0);
182 * We must always use the nofault function regardless of whether we
183 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
184 * didn't, we'd never know that the other partition is down and would
185 * keep sending IRQs and amos to it until the heartbeat times out.
187 ret
= xp_nofault_PIOR((u64
*)GLOBAL_MMR_ADDR(NASID_GET(&amo
->variable
),
188 xp_nofault_PIOR_target
));
190 local_irq_restore(irq_flags
);
192 return (ret
== 0) ? xpSuccess
: xpPioReadError
;
196 xpc_init_IRQ_amo_sn2(int index
)
198 struct amo
*amo
= xpc_vars_sn2
->amos_page
+ index
;
200 (void)xpc_receive_IRQ_amo_sn2(amo
); /* clear amo variable */
205 * Functions associated with SGI_XPC_ACTIVATE IRQ.
209 * Notify the heartbeat check thread that an activate IRQ has been received.
212 xpc_handle_activate_IRQ_sn2(int irq
, void *dev_id
)
214 unsigned long irq_flags
;
216 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
217 xpc_activate_IRQ_rcvd
++;
218 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
220 wake_up_interruptible(&xpc_activate_IRQ_wq
);
225 * Flag the appropriate amo variable and send an IRQ to the specified node.
228 xpc_send_activate_IRQ_sn2(unsigned long amos_page_pa
, int from_nasid
,
229 int to_nasid
, int to_phys_cpuid
)
231 struct amo
*amos
= (struct amo
*)__va(amos_page_pa
+
232 (XPC_ACTIVATE_IRQ_AMOS_SN2
*
233 sizeof(struct amo
)));
235 (void)xpc_send_IRQ_sn2(&amos
[BIT_WORD(from_nasid
/ 2)],
236 BIT_MASK(from_nasid
/ 2), to_nasid
,
237 to_phys_cpuid
, SGI_XPC_ACTIVATE
);
241 xpc_send_local_activate_IRQ_sn2(int from_nasid
)
243 unsigned long irq_flags
;
244 struct amo
*amos
= (struct amo
*)__va(xpc_vars_sn2
->amos_page_pa
+
245 (XPC_ACTIVATE_IRQ_AMOS_SN2
*
246 sizeof(struct amo
)));
248 /* fake the sending and receipt of an activate IRQ from remote nasid */
249 FETCHOP_STORE_OP(TO_AMO((u64
)&amos
[BIT_WORD(from_nasid
/ 2)].variable
),
250 FETCHOP_OR
, BIT_MASK(from_nasid
/ 2));
252 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
253 xpc_activate_IRQ_rcvd
++;
254 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
256 wake_up_interruptible(&xpc_activate_IRQ_wq
);
260 * Functions associated with SGI_XPC_NOTIFY IRQ.
264 * Check to see if any chctl flags were sent from the specified partition.
267 xpc_check_for_sent_chctl_flags_sn2(struct xpc_partition
*part
)
269 union xpc_channel_ctl_flags chctl
;
270 unsigned long irq_flags
;
272 chctl
.all_flags
= xpc_receive_IRQ_amo_sn2(part
->sn
.sn2
.
274 if (chctl
.all_flags
== 0)
277 spin_lock_irqsave(&part
->chctl_lock
, irq_flags
);
278 part
->chctl
.all_flags
|= chctl
.all_flags
;
279 spin_unlock_irqrestore(&part
->chctl_lock
, irq_flags
);
281 dev_dbg(xpc_chan
, "received notify IRQ from partid=%d, chctl.all_flags="
282 "0x%llx\n", XPC_PARTID(part
), chctl
.all_flags
);
284 xpc_wakeup_channel_mgr(part
);
288 * Handle the receipt of a SGI_XPC_NOTIFY IRQ by seeing whether the specified
289 * partition actually sent it. Since SGI_XPC_NOTIFY IRQs may be shared by more
290 * than one partition, we use an amo structure per partition to indicate
291 * whether a partition has sent an IRQ or not. If it has, then wake up the
292 * associated kthread to handle it.
294 * All SGI_XPC_NOTIFY IRQs received by XPC are the result of IRQs sent by XPC
295 * running on other partitions.
297 * Noteworthy Arguments:
299 * irq - Interrupt ReQuest number. NOT USED.
301 * dev_id - partid of IRQ's potential sender.
304 xpc_handle_notify_IRQ_sn2(int irq
, void *dev_id
)
306 short partid
= (short)(u64
)dev_id
;
307 struct xpc_partition
*part
= &xpc_partitions
[partid
];
309 DBUG_ON(partid
< 0 || partid
>= XP_MAX_NPARTITIONS_SN2
);
311 if (xpc_part_ref(part
)) {
312 xpc_check_for_sent_chctl_flags_sn2(part
);
314 xpc_part_deref(part
);
320 * Check to see if xpc_handle_notify_IRQ_sn2() dropped any IRQs on the floor
321 * because the write to their associated amo variable completed after the IRQ
325 xpc_check_for_dropped_notify_IRQ_sn2(struct xpc_partition
*part
)
327 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
329 if (xpc_part_ref(part
)) {
330 xpc_check_for_sent_chctl_flags_sn2(part
);
332 part_sn2
->dropped_notify_IRQ_timer
.expires
= jiffies
+
333 XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL
;
334 add_timer(&part_sn2
->dropped_notify_IRQ_timer
);
335 xpc_part_deref(part
);
340 * Send a notify IRQ to the remote partition that is associated with the
344 xpc_send_notify_IRQ_sn2(struct xpc_channel
*ch
, u8 chctl_flag
,
345 char *chctl_flag_string
, unsigned long *irq_flags
)
347 struct xpc_partition
*part
= &xpc_partitions
[ch
->partid
];
348 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
349 union xpc_channel_ctl_flags chctl
= { 0 };
352 if (likely(part
->act_state
!= XPC_P_AS_DEACTIVATING
)) {
353 chctl
.flags
[ch
->number
] = chctl_flag
;
354 ret
= xpc_send_IRQ_sn2(part_sn2
->remote_chctl_amo_va
,
356 part_sn2
->notify_IRQ_nasid
,
357 part_sn2
->notify_IRQ_phys_cpuid
,
359 dev_dbg(xpc_chan
, "%s sent to partid=%d, channel=%d, ret=%d\n",
360 chctl_flag_string
, ch
->partid
, ch
->number
, ret
);
361 if (unlikely(ret
!= xpSuccess
)) {
362 if (irq_flags
!= NULL
)
363 spin_unlock_irqrestore(&ch
->lock
, *irq_flags
);
364 XPC_DEACTIVATE_PARTITION(part
, ret
);
365 if (irq_flags
!= NULL
)
366 spin_lock_irqsave(&ch
->lock
, *irq_flags
);
371 #define XPC_SEND_NOTIFY_IRQ_SN2(_ch, _ipi_f, _irq_f) \
372 xpc_send_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f, _irq_f)
375 * Make it look like the remote partition, which is associated with the
376 * specified channel, sent us a notify IRQ. This faked IRQ will be handled
377 * by xpc_check_for_dropped_notify_IRQ_sn2().
380 xpc_send_local_notify_IRQ_sn2(struct xpc_channel
*ch
, u8 chctl_flag
,
381 char *chctl_flag_string
)
383 struct xpc_partition
*part
= &xpc_partitions
[ch
->partid
];
384 union xpc_channel_ctl_flags chctl
= { 0 };
386 chctl
.flags
[ch
->number
] = chctl_flag
;
387 FETCHOP_STORE_OP(TO_AMO((u64
)&part
->sn
.sn2
.local_chctl_amo_va
->
388 variable
), FETCHOP_OR
, chctl
.all_flags
);
389 dev_dbg(xpc_chan
, "%s sent local from partid=%d, channel=%d\n",
390 chctl_flag_string
, ch
->partid
, ch
->number
);
393 #define XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(_ch, _ipi_f) \
394 xpc_send_local_notify_IRQ_sn2(_ch, _ipi_f, #_ipi_f)
397 xpc_send_chctl_closerequest_sn2(struct xpc_channel
*ch
,
398 unsigned long *irq_flags
)
400 struct xpc_openclose_args
*args
= ch
->sn
.sn2
.local_openclose_args
;
402 args
->reason
= ch
->reason
;
403 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_CLOSEREQUEST
, irq_flags
);
407 xpc_send_chctl_closereply_sn2(struct xpc_channel
*ch
, unsigned long *irq_flags
)
409 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_CLOSEREPLY
, irq_flags
);
413 xpc_send_chctl_openrequest_sn2(struct xpc_channel
*ch
, unsigned long *irq_flags
)
415 struct xpc_openclose_args
*args
= ch
->sn
.sn2
.local_openclose_args
;
417 args
->entry_size
= ch
->entry_size
;
418 args
->local_nentries
= ch
->local_nentries
;
419 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_OPENREQUEST
, irq_flags
);
423 xpc_send_chctl_openreply_sn2(struct xpc_channel
*ch
, unsigned long *irq_flags
)
425 struct xpc_openclose_args
*args
= ch
->sn
.sn2
.local_openclose_args
;
427 args
->remote_nentries
= ch
->remote_nentries
;
428 args
->local_nentries
= ch
->local_nentries
;
429 args
->local_msgqueue_pa
= xp_pa(ch
->sn
.sn2
.local_msgqueue
);
430 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_OPENREPLY
, irq_flags
);
434 xpc_send_chctl_opencomplete_sn2(struct xpc_channel
*ch
,
435 unsigned long *irq_flags
)
437 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_OPENCOMPLETE
, irq_flags
);
441 xpc_send_chctl_msgrequest_sn2(struct xpc_channel
*ch
)
443 XPC_SEND_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_MSGREQUEST
, NULL
);
447 xpc_send_chctl_local_msgrequest_sn2(struct xpc_channel
*ch
)
449 XPC_SEND_LOCAL_NOTIFY_IRQ_SN2(ch
, XPC_CHCTL_MSGREQUEST
);
452 static enum xp_retval
453 xpc_save_remote_msgqueue_pa_sn2(struct xpc_channel
*ch
,
454 unsigned long msgqueue_pa
)
456 ch
->sn
.sn2
.remote_msgqueue_pa
= msgqueue_pa
;
461 * This next set of functions are used to keep track of when a partition is
462 * potentially engaged in accessing memory belonging to another partition.
466 xpc_indicate_partition_engaged_sn2(struct xpc_partition
*part
)
468 unsigned long irq_flags
;
469 struct amo
*amo
= (struct amo
*)__va(part
->sn
.sn2
.remote_amos_page_pa
+
470 (XPC_ENGAGED_PARTITIONS_AMO_SN2
*
471 sizeof(struct amo
)));
473 local_irq_save(irq_flags
);
475 /* set bit corresponding to our partid in remote partition's amo */
476 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_OR
,
477 BIT(sn_partition_id
));
480 * We must always use the nofault function regardless of whether we
481 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
482 * didn't, we'd never know that the other partition is down and would
483 * keep sending IRQs and amos to it until the heartbeat times out.
485 (void)xp_nofault_PIOR((u64
*)GLOBAL_MMR_ADDR(NASID_GET(&amo
->
487 xp_nofault_PIOR_target
));
489 local_irq_restore(irq_flags
);
493 xpc_indicate_partition_disengaged_sn2(struct xpc_partition
*part
)
495 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
496 unsigned long irq_flags
;
497 struct amo
*amo
= (struct amo
*)__va(part_sn2
->remote_amos_page_pa
+
498 (XPC_ENGAGED_PARTITIONS_AMO_SN2
*
499 sizeof(struct amo
)));
501 local_irq_save(irq_flags
);
503 /* clear bit corresponding to our partid in remote partition's amo */
504 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_AND
,
505 ~BIT(sn_partition_id
));
508 * We must always use the nofault function regardless of whether we
509 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
510 * didn't, we'd never know that the other partition is down and would
511 * keep sending IRQs and amos to it until the heartbeat times out.
513 (void)xp_nofault_PIOR((u64
*)GLOBAL_MMR_ADDR(NASID_GET(&amo
->
515 xp_nofault_PIOR_target
));
517 local_irq_restore(irq_flags
);
520 * Send activate IRQ to get other side to see that we've cleared our
521 * bit in their engaged partitions amo.
523 xpc_send_activate_IRQ_sn2(part_sn2
->remote_amos_page_pa
,
525 part_sn2
->activate_IRQ_nasid
,
526 part_sn2
->activate_IRQ_phys_cpuid
);
530 xpc_assume_partition_disengaged_sn2(short partid
)
532 struct amo
*amo
= xpc_vars_sn2
->amos_page
+
533 XPC_ENGAGED_PARTITIONS_AMO_SN2
;
535 /* clear bit(s) based on partid mask in our partition's amo */
536 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_AND
,
541 xpc_partition_engaged_sn2(short partid
)
543 struct amo
*amo
= xpc_vars_sn2
->amos_page
+
544 XPC_ENGAGED_PARTITIONS_AMO_SN2
;
546 /* our partition's amo variable ANDed with partid mask */
547 return (FETCHOP_LOAD_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_LOAD
) &
552 xpc_any_partition_engaged_sn2(void)
554 struct amo
*amo
= xpc_vars_sn2
->amos_page
+
555 XPC_ENGAGED_PARTITIONS_AMO_SN2
;
557 /* our partition's amo variable */
558 return FETCHOP_LOAD_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_LOAD
) != 0;
561 /* original protection values for each node */
562 static u64 xpc_prot_vec_sn2
[MAX_NUMNODES
];
565 * Change protections to allow amo operations on non-Shub 1.1 systems.
567 static enum xp_retval
568 xpc_allow_amo_ops_sn2(struct amo
*amos_page
)
570 enum xp_retval ret
= xpSuccess
;
573 * On SHUB 1.1, we cannot call sn_change_memprotect() since the BIST
574 * collides with memory operations. On those systems we call
575 * xpc_allow_amo_ops_shub_wars_1_1_sn2() instead.
577 if (!enable_shub_wars_1_1())
578 ret
= xp_expand_memprotect(ia64_tpa((u64
)amos_page
), PAGE_SIZE
);
584 * Change protections to allow amo operations on Shub 1.1 systems.
587 xpc_allow_amo_ops_shub_wars_1_1_sn2(void)
592 if (!enable_shub_wars_1_1())
595 for_each_online_node(node
) {
596 nasid
= cnodeid_to_nasid(node
);
597 /* save current protection values */
598 xpc_prot_vec_sn2
[node
] =
599 (u64
)HUB_L((u64
*)GLOBAL_MMR_ADDR(nasid
,
600 SH1_MD_DQLP_MMR_DIR_PRIVEC0
));
601 /* open up everything */
602 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
,
603 SH1_MD_DQLP_MMR_DIR_PRIVEC0
),
605 HUB_S((u64
*)GLOBAL_MMR_ADDR(nasid
,
606 SH1_MD_DQRP_MMR_DIR_PRIVEC0
),
611 static enum xp_retval
612 xpc_get_partition_rsvd_page_pa_sn2(void *buf
, u64
*cookie
, unsigned long *rp_pa
,
618 status
= sn_partition_reserved_page_pa((u64
)buf
, cookie
,
619 (u64
*)rp_pa
, (u64
*)len
);
620 if (status
== SALRET_OK
)
622 else if (status
== SALRET_MORE_PASSES
)
623 ret
= xpNeedMoreInfo
;
632 xpc_setup_rsvd_page_sn2(struct xpc_rsvd_page
*rp
)
634 struct amo
*amos_page
;
638 xpc_vars_sn2
= XPC_RP_VARS(rp
);
640 rp
->sn
.sn2
.vars_pa
= xp_pa(xpc_vars_sn2
);
642 /* vars_part array follows immediately after vars */
643 xpc_vars_part_sn2
= (struct xpc_vars_part_sn2
*)((u8
*)XPC_RP_VARS(rp
) +
647 * Before clearing xpc_vars_sn2, see if a page of amos had been
648 * previously allocated. If not we'll need to allocate one and set
649 * permissions so that cross-partition amos are allowed.
651 * The allocated amo page needs MCA reporting to remain disabled after
652 * XPC has unloaded. To make this work, we keep a copy of the pointer
653 * to this page (i.e., amos_page) in the struct xpc_vars_sn2 structure,
654 * which is pointed to by the reserved page, and re-use that saved copy
655 * on subsequent loads of XPC. This amo page is never freed, and its
656 * memory protections are never restricted.
658 amos_page
= xpc_vars_sn2
->amos_page
;
659 if (amos_page
== NULL
) {
660 amos_page
= (struct amo
*)TO_AMO(uncached_alloc_page(0, 1));
661 if (amos_page
== NULL
) {
662 dev_err(xpc_part
, "can't allocate page of amos\n");
667 * Open up amo-R/W to cpu. This is done on Shub 1.1 systems
668 * when xpc_allow_amo_ops_shub_wars_1_1_sn2() is called.
670 ret
= xpc_allow_amo_ops_sn2(amos_page
);
671 if (ret
!= xpSuccess
) {
672 dev_err(xpc_part
, "can't allow amo operations\n");
673 uncached_free_page(__IA64_UNCACHED_OFFSET
|
674 TO_PHYS((u64
)amos_page
), 1);
679 /* clear xpc_vars_sn2 */
680 memset(xpc_vars_sn2
, 0, sizeof(struct xpc_vars_sn2
));
682 xpc_vars_sn2
->version
= XPC_V_VERSION
;
683 xpc_vars_sn2
->activate_IRQ_nasid
= cpuid_to_nasid(0);
684 xpc_vars_sn2
->activate_IRQ_phys_cpuid
= cpu_physical_id(0);
685 xpc_vars_sn2
->vars_part_pa
= xp_pa(xpc_vars_part_sn2
);
686 xpc_vars_sn2
->amos_page_pa
= ia64_tpa((u64
)amos_page
);
687 xpc_vars_sn2
->amos_page
= amos_page
; /* save for next load of XPC */
689 /* clear xpc_vars_part_sn2 */
690 memset((u64
*)xpc_vars_part_sn2
, 0, sizeof(struct xpc_vars_part_sn2
) *
691 XP_MAX_NPARTITIONS_SN2
);
693 /* initialize the activate IRQ related amo variables */
694 for (i
= 0; i
< xpc_nasid_mask_nlongs
; i
++)
695 (void)xpc_init_IRQ_amo_sn2(XPC_ACTIVATE_IRQ_AMOS_SN2
+ i
);
697 /* initialize the engaged remote partitions related amo variables */
698 (void)xpc_init_IRQ_amo_sn2(XPC_ENGAGED_PARTITIONS_AMO_SN2
);
699 (void)xpc_init_IRQ_amo_sn2(XPC_DEACTIVATE_REQUEST_AMO_SN2
);
705 xpc_hb_allowed_sn2(short partid
, void *heartbeating_to_mask
)
707 return test_bit(partid
, heartbeating_to_mask
);
711 xpc_allow_hb_sn2(short partid
)
713 DBUG_ON(xpc_vars_sn2
== NULL
);
714 set_bit(partid
, xpc_vars_sn2
->heartbeating_to_mask
);
718 xpc_disallow_hb_sn2(short partid
)
720 DBUG_ON(xpc_vars_sn2
== NULL
);
721 clear_bit(partid
, xpc_vars_sn2
->heartbeating_to_mask
);
725 xpc_disallow_all_hbs_sn2(void)
727 DBUG_ON(xpc_vars_sn2
== NULL
);
728 bitmap_zero(xpc_vars_sn2
->heartbeating_to_mask
, xp_max_npartitions
);
732 xpc_increment_heartbeat_sn2(void)
734 xpc_vars_sn2
->heartbeat
++;
738 xpc_offline_heartbeat_sn2(void)
740 xpc_increment_heartbeat_sn2();
741 xpc_vars_sn2
->heartbeat_offline
= 1;
745 xpc_online_heartbeat_sn2(void)
747 xpc_increment_heartbeat_sn2();
748 xpc_vars_sn2
->heartbeat_offline
= 0;
752 xpc_heartbeat_init_sn2(void)
754 DBUG_ON(xpc_vars_sn2
== NULL
);
756 bitmap_zero(xpc_vars_sn2
->heartbeating_to_mask
, XP_MAX_NPARTITIONS_SN2
);
757 xpc_online_heartbeat_sn2();
761 xpc_heartbeat_exit_sn2(void)
763 xpc_offline_heartbeat_sn2();
766 static enum xp_retval
767 xpc_get_remote_heartbeat_sn2(struct xpc_partition
*part
)
769 struct xpc_vars_sn2
*remote_vars
;
772 remote_vars
= (struct xpc_vars_sn2
*)xpc_remote_copy_buffer_sn2
;
774 /* pull the remote vars structure that contains the heartbeat */
775 ret
= xp_remote_memcpy(xp_pa(remote_vars
),
776 part
->sn
.sn2
.remote_vars_pa
,
778 if (ret
!= xpSuccess
)
781 dev_dbg(xpc_part
, "partid=%d, heartbeat=%lld, last_heartbeat=%lld, "
782 "heartbeat_offline=%lld, HB_mask[0]=0x%lx\n", XPC_PARTID(part
),
783 remote_vars
->heartbeat
, part
->last_heartbeat
,
784 remote_vars
->heartbeat_offline
,
785 remote_vars
->heartbeating_to_mask
[0]);
787 if ((remote_vars
->heartbeat
== part
->last_heartbeat
&&
788 !remote_vars
->heartbeat_offline
) ||
789 !xpc_hb_allowed_sn2(sn_partition_id
,
790 remote_vars
->heartbeating_to_mask
)) {
793 part
->last_heartbeat
= remote_vars
->heartbeat
;
800 * Get a copy of the remote partition's XPC variables from the reserved page.
802 * remote_vars points to a buffer that is cacheline aligned for BTE copies and
803 * assumed to be of size XPC_RP_VARS_SIZE.
805 static enum xp_retval
806 xpc_get_remote_vars_sn2(unsigned long remote_vars_pa
,
807 struct xpc_vars_sn2
*remote_vars
)
811 if (remote_vars_pa
== 0)
814 /* pull over the cross partition variables */
815 ret
= xp_remote_memcpy(xp_pa(remote_vars
), remote_vars_pa
,
817 if (ret
!= xpSuccess
)
820 if (XPC_VERSION_MAJOR(remote_vars
->version
) !=
821 XPC_VERSION_MAJOR(XPC_V_VERSION
)) {
829 xpc_request_partition_activation_sn2(struct xpc_rsvd_page
*remote_rp
,
830 unsigned long remote_rp_pa
, int nasid
)
832 xpc_send_local_activate_IRQ_sn2(nasid
);
836 xpc_request_partition_reactivation_sn2(struct xpc_partition
*part
)
838 xpc_send_local_activate_IRQ_sn2(part
->sn
.sn2
.activate_IRQ_nasid
);
842 xpc_request_partition_deactivation_sn2(struct xpc_partition
*part
)
844 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
845 unsigned long irq_flags
;
846 struct amo
*amo
= (struct amo
*)__va(part_sn2
->remote_amos_page_pa
+
847 (XPC_DEACTIVATE_REQUEST_AMO_SN2
*
848 sizeof(struct amo
)));
850 local_irq_save(irq_flags
);
852 /* set bit corresponding to our partid in remote partition's amo */
853 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_OR
,
854 BIT(sn_partition_id
));
857 * We must always use the nofault function regardless of whether we
858 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
859 * didn't, we'd never know that the other partition is down and would
860 * keep sending IRQs and amos to it until the heartbeat times out.
862 (void)xp_nofault_PIOR((u64
*)GLOBAL_MMR_ADDR(NASID_GET(&amo
->
864 xp_nofault_PIOR_target
));
866 local_irq_restore(irq_flags
);
869 * Send activate IRQ to get other side to see that we've set our
870 * bit in their deactivate request amo.
872 xpc_send_activate_IRQ_sn2(part_sn2
->remote_amos_page_pa
,
874 part_sn2
->activate_IRQ_nasid
,
875 part_sn2
->activate_IRQ_phys_cpuid
);
879 xpc_cancel_partition_deactivation_request_sn2(struct xpc_partition
*part
)
881 unsigned long irq_flags
;
882 struct amo
*amo
= (struct amo
*)__va(part
->sn
.sn2
.remote_amos_page_pa
+
883 (XPC_DEACTIVATE_REQUEST_AMO_SN2
*
884 sizeof(struct amo
)));
886 local_irq_save(irq_flags
);
888 /* clear bit corresponding to our partid in remote partition's amo */
889 FETCHOP_STORE_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_AND
,
890 ~BIT(sn_partition_id
));
893 * We must always use the nofault function regardless of whether we
894 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
895 * didn't, we'd never know that the other partition is down and would
896 * keep sending IRQs and amos to it until the heartbeat times out.
898 (void)xp_nofault_PIOR((u64
*)GLOBAL_MMR_ADDR(NASID_GET(&amo
->
900 xp_nofault_PIOR_target
));
902 local_irq_restore(irq_flags
);
906 xpc_partition_deactivation_requested_sn2(short partid
)
908 struct amo
*amo
= xpc_vars_sn2
->amos_page
+
909 XPC_DEACTIVATE_REQUEST_AMO_SN2
;
911 /* our partition's amo variable ANDed with partid mask */
912 return (FETCHOP_LOAD_OP(TO_AMO((u64
)&amo
->variable
), FETCHOP_LOAD
) &
917 * Update the remote partition's info.
920 xpc_update_partition_info_sn2(struct xpc_partition
*part
, u8 remote_rp_version
,
921 unsigned long *remote_rp_ts_jiffies
,
922 unsigned long remote_rp_pa
,
923 unsigned long remote_vars_pa
,
924 struct xpc_vars_sn2
*remote_vars
)
926 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
928 part
->remote_rp_version
= remote_rp_version
;
929 dev_dbg(xpc_part
, " remote_rp_version = 0x%016x\n",
930 part
->remote_rp_version
);
932 part
->remote_rp_ts_jiffies
= *remote_rp_ts_jiffies
;
933 dev_dbg(xpc_part
, " remote_rp_ts_jiffies = 0x%016lx\n",
934 part
->remote_rp_ts_jiffies
);
936 part
->remote_rp_pa
= remote_rp_pa
;
937 dev_dbg(xpc_part
, " remote_rp_pa = 0x%016lx\n", part
->remote_rp_pa
);
939 part_sn2
->remote_vars_pa
= remote_vars_pa
;
940 dev_dbg(xpc_part
, " remote_vars_pa = 0x%016lx\n",
941 part_sn2
->remote_vars_pa
);
943 part
->last_heartbeat
= remote_vars
->heartbeat
- 1;
944 dev_dbg(xpc_part
, " last_heartbeat = 0x%016llx\n",
945 part
->last_heartbeat
);
947 part_sn2
->remote_vars_part_pa
= remote_vars
->vars_part_pa
;
948 dev_dbg(xpc_part
, " remote_vars_part_pa = 0x%016lx\n",
949 part_sn2
->remote_vars_part_pa
);
951 part_sn2
->activate_IRQ_nasid
= remote_vars
->activate_IRQ_nasid
;
952 dev_dbg(xpc_part
, " activate_IRQ_nasid = 0x%x\n",
953 part_sn2
->activate_IRQ_nasid
);
955 part_sn2
->activate_IRQ_phys_cpuid
=
956 remote_vars
->activate_IRQ_phys_cpuid
;
957 dev_dbg(xpc_part
, " activate_IRQ_phys_cpuid = 0x%x\n",
958 part_sn2
->activate_IRQ_phys_cpuid
);
960 part_sn2
->remote_amos_page_pa
= remote_vars
->amos_page_pa
;
961 dev_dbg(xpc_part
, " remote_amos_page_pa = 0x%lx\n",
962 part_sn2
->remote_amos_page_pa
);
964 part_sn2
->remote_vars_version
= remote_vars
->version
;
965 dev_dbg(xpc_part
, " remote_vars_version = 0x%x\n",
966 part_sn2
->remote_vars_version
);
970 * Prior code has determined the nasid which generated a activate IRQ.
971 * Inspect that nasid to determine if its partition needs to be activated
974 * A partition is considered "awaiting activation" if our partition
975 * flags indicate it is not active and it has a heartbeat. A
976 * partition is considered "awaiting deactivation" if our partition
977 * flags indicate it is active but it has no heartbeat or it is not
978 * sending its heartbeat to us.
980 * To determine the heartbeat, the remote nasid must have a properly
981 * initialized reserved page.
984 xpc_identify_activate_IRQ_req_sn2(int nasid
)
986 struct xpc_rsvd_page
*remote_rp
;
987 struct xpc_vars_sn2
*remote_vars
;
988 unsigned long remote_rp_pa
;
989 unsigned long remote_vars_pa
;
990 int remote_rp_version
;
992 unsigned long remote_rp_ts_jiffies
= 0;
994 struct xpc_partition
*part
;
995 struct xpc_partition_sn2
*part_sn2
;
998 /* pull over the reserved page structure */
1000 remote_rp
= (struct xpc_rsvd_page
*)xpc_remote_copy_buffer_sn2
;
1002 ret
= xpc_get_remote_rp(nasid
, NULL
, remote_rp
, &remote_rp_pa
);
1003 if (ret
!= xpSuccess
) {
1004 dev_warn(xpc_part
, "unable to get reserved page from nasid %d, "
1005 "which sent interrupt, reason=%d\n", nasid
, ret
);
1009 remote_vars_pa
= remote_rp
->sn
.sn2
.vars_pa
;
1010 remote_rp_version
= remote_rp
->version
;
1011 remote_rp_ts_jiffies
= remote_rp
->ts_jiffies
;
1013 partid
= remote_rp
->SAL_partid
;
1014 part
= &xpc_partitions
[partid
];
1015 part_sn2
= &part
->sn
.sn2
;
1017 /* pull over the cross partition variables */
1019 remote_vars
= (struct xpc_vars_sn2
*)xpc_remote_copy_buffer_sn2
;
1021 ret
= xpc_get_remote_vars_sn2(remote_vars_pa
, remote_vars
);
1022 if (ret
!= xpSuccess
) {
1023 dev_warn(xpc_part
, "unable to get XPC variables from nasid %d, "
1024 "which sent interrupt, reason=%d\n", nasid
, ret
);
1026 XPC_DEACTIVATE_PARTITION(part
, ret
);
1030 part
->activate_IRQ_rcvd
++;
1032 dev_dbg(xpc_part
, "partid for nasid %d is %d; IRQs = %d; HB = "
1033 "%lld:0x%lx\n", (int)nasid
, (int)partid
,
1034 part
->activate_IRQ_rcvd
,
1035 remote_vars
->heartbeat
, remote_vars
->heartbeating_to_mask
[0]);
1037 if (xpc_partition_disengaged(part
) &&
1038 part
->act_state
== XPC_P_AS_INACTIVE
) {
1040 xpc_update_partition_info_sn2(part
, remote_rp_version
,
1041 &remote_rp_ts_jiffies
,
1042 remote_rp_pa
, remote_vars_pa
,
1045 if (xpc_partition_deactivation_requested_sn2(partid
)) {
1047 * Other side is waiting on us to deactivate even though
1053 xpc_activate_partition(part
);
1057 DBUG_ON(part
->remote_rp_version
== 0);
1058 DBUG_ON(part_sn2
->remote_vars_version
== 0);
1060 if (remote_rp_ts_jiffies
!= part
->remote_rp_ts_jiffies
) {
1062 /* the other side rebooted */
1064 DBUG_ON(xpc_partition_engaged_sn2(partid
));
1065 DBUG_ON(xpc_partition_deactivation_requested_sn2(partid
));
1067 xpc_update_partition_info_sn2(part
, remote_rp_version
,
1068 &remote_rp_ts_jiffies
,
1069 remote_rp_pa
, remote_vars_pa
,
1074 if (part
->disengage_timeout
> 0 && !xpc_partition_disengaged(part
)) {
1075 /* still waiting on other side to disengage from us */
1080 XPC_DEACTIVATE_PARTITION(part
, xpReactivating
);
1081 else if (xpc_partition_deactivation_requested_sn2(partid
))
1082 XPC_DEACTIVATE_PARTITION(part
, xpOtherGoingDown
);
1086 * Loop through the activation amo variables and process any bits
1087 * which are set. Each bit indicates a nasid sending a partition
1088 * activation or deactivation request.
1090 * Return #of IRQs detected.
1093 xpc_identify_activate_IRQ_sender_sn2(void)
1097 unsigned long nasid_mask_long
;
1098 u64 nasid
; /* remote nasid */
1099 int n_IRQs_detected
= 0;
1100 struct amo
*act_amos
;
1102 act_amos
= xpc_vars_sn2
->amos_page
+ XPC_ACTIVATE_IRQ_AMOS_SN2
;
1104 /* scan through activate amo variables looking for non-zero entries */
1105 for (l
= 0; l
< xpc_nasid_mask_nlongs
; l
++) {
1110 nasid_mask_long
= xpc_receive_IRQ_amo_sn2(&act_amos
[l
]);
1112 b
= find_first_bit(&nasid_mask_long
, BITS_PER_LONG
);
1113 if (b
>= BITS_PER_LONG
) {
1114 /* no IRQs from nasids in this amo variable */
1118 dev_dbg(xpc_part
, "amo[%d] gave back 0x%lx\n", l
,
1122 * If this nasid has been added to the machine since
1123 * our partition was reset, this will retain the
1124 * remote nasid in our reserved pages machine mask.
1125 * This is used in the event of module reload.
1127 xpc_mach_nasids
[l
] |= nasid_mask_long
;
1129 /* locate the nasid(s) which sent interrupts */
1133 nasid
= (l
* BITS_PER_LONG
+ b
) * 2;
1134 dev_dbg(xpc_part
, "interrupt from nasid %lld\n", nasid
);
1135 xpc_identify_activate_IRQ_req_sn2(nasid
);
1137 b
= find_next_bit(&nasid_mask_long
, BITS_PER_LONG
,
1139 } while (b
< BITS_PER_LONG
);
1141 return n_IRQs_detected
;
1145 xpc_process_activate_IRQ_rcvd_sn2(void)
1147 unsigned long irq_flags
;
1148 int n_IRQs_expected
;
1149 int n_IRQs_detected
;
1151 spin_lock_irqsave(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
1152 n_IRQs_expected
= xpc_activate_IRQ_rcvd
;
1153 xpc_activate_IRQ_rcvd
= 0;
1154 spin_unlock_irqrestore(&xpc_activate_IRQ_rcvd_lock
, irq_flags
);
1156 n_IRQs_detected
= xpc_identify_activate_IRQ_sender_sn2();
1157 if (n_IRQs_detected
< n_IRQs_expected
) {
1158 /* retry once to help avoid missing amo */
1159 (void)xpc_identify_activate_IRQ_sender_sn2();
1164 * Setup the channel structures that are sn2 specific.
1166 static enum xp_retval
1167 xpc_setup_ch_structures_sn2(struct xpc_partition
*part
)
1169 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
1170 struct xpc_channel_sn2
*ch_sn2
;
1171 enum xp_retval retval
;
1175 struct timer_list
*timer
;
1176 short partid
= XPC_PARTID(part
);
1178 /* allocate all the required GET/PUT values */
1180 part_sn2
->local_GPs
=
1181 xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE
, GFP_KERNEL
,
1182 &part_sn2
->local_GPs_base
);
1183 if (part_sn2
->local_GPs
== NULL
) {
1184 dev_err(xpc_chan
, "can't get memory for local get/put "
1189 part_sn2
->remote_GPs
=
1190 xpc_kzalloc_cacheline_aligned(XPC_GP_SIZE
, GFP_KERNEL
,
1191 &part_sn2
->remote_GPs_base
);
1192 if (part_sn2
->remote_GPs
== NULL
) {
1193 dev_err(xpc_chan
, "can't get memory for remote get/put "
1195 retval
= xpNoMemory
;
1199 part_sn2
->remote_GPs_pa
= 0;
1201 /* allocate all the required open and close args */
1203 part_sn2
->local_openclose_args
=
1204 xpc_kzalloc_cacheline_aligned(XPC_OPENCLOSE_ARGS_SIZE
,
1205 GFP_KERNEL
, &part_sn2
->
1206 local_openclose_args_base
);
1207 if (part_sn2
->local_openclose_args
== NULL
) {
1208 dev_err(xpc_chan
, "can't get memory for local connect args\n");
1209 retval
= xpNoMemory
;
1213 part_sn2
->remote_openclose_args_pa
= 0;
1215 part_sn2
->local_chctl_amo_va
= xpc_init_IRQ_amo_sn2(partid
);
1217 part_sn2
->notify_IRQ_nasid
= 0;
1218 part_sn2
->notify_IRQ_phys_cpuid
= 0;
1219 part_sn2
->remote_chctl_amo_va
= NULL
;
1221 sprintf(part_sn2
->notify_IRQ_owner
, "xpc%02d", partid
);
1222 ret
= request_irq(SGI_XPC_NOTIFY
, xpc_handle_notify_IRQ_sn2
,
1223 IRQF_SHARED
, part_sn2
->notify_IRQ_owner
,
1224 (void *)(u64
)partid
);
1226 dev_err(xpc_chan
, "can't register NOTIFY IRQ handler, "
1227 "errno=%d\n", -ret
);
1228 retval
= xpLackOfResources
;
1232 /* Setup a timer to check for dropped notify IRQs */
1233 timer
= &part_sn2
->dropped_notify_IRQ_timer
;
1236 (void (*)(unsigned long))xpc_check_for_dropped_notify_IRQ_sn2
;
1237 timer
->data
= (unsigned long)part
;
1238 timer
->expires
= jiffies
+ XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL
;
1241 for (ch_number
= 0; ch_number
< part
->nchannels
; ch_number
++) {
1242 ch_sn2
= &part
->channels
[ch_number
].sn
.sn2
;
1244 ch_sn2
->local_GP
= &part_sn2
->local_GPs
[ch_number
];
1245 ch_sn2
->local_openclose_args
=
1246 &part_sn2
->local_openclose_args
[ch_number
];
1248 mutex_init(&ch_sn2
->msg_to_pull_mutex
);
1252 * Setup the per partition specific variables required by the
1253 * remote partition to establish channel connections with us.
1255 * The setting of the magic # indicates that these per partition
1256 * specific variables are ready to be used.
1258 xpc_vars_part_sn2
[partid
].GPs_pa
= xp_pa(part_sn2
->local_GPs
);
1259 xpc_vars_part_sn2
[partid
].openclose_args_pa
=
1260 xp_pa(part_sn2
->local_openclose_args
);
1261 xpc_vars_part_sn2
[partid
].chctl_amo_pa
=
1262 xp_pa(part_sn2
->local_chctl_amo_va
);
1263 cpuid
= raw_smp_processor_id(); /* any CPU in this partition will do */
1264 xpc_vars_part_sn2
[partid
].notify_IRQ_nasid
= cpuid_to_nasid(cpuid
);
1265 xpc_vars_part_sn2
[partid
].notify_IRQ_phys_cpuid
=
1266 cpu_physical_id(cpuid
);
1267 xpc_vars_part_sn2
[partid
].nchannels
= part
->nchannels
;
1268 xpc_vars_part_sn2
[partid
].magic
= XPC_VP_MAGIC1_SN2
;
1272 /* setup of ch structures failed */
1274 kfree(part_sn2
->local_openclose_args_base
);
1275 part_sn2
->local_openclose_args
= NULL
;
1277 kfree(part_sn2
->remote_GPs_base
);
1278 part_sn2
->remote_GPs
= NULL
;
1280 kfree(part_sn2
->local_GPs_base
);
1281 part_sn2
->local_GPs
= NULL
;
1286 * Teardown the channel structures that are sn2 specific.
1289 xpc_teardown_ch_structures_sn2(struct xpc_partition
*part
)
1291 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
1292 short partid
= XPC_PARTID(part
);
1295 * Indicate that the variables specific to the remote partition are no
1296 * longer available for its use.
1298 xpc_vars_part_sn2
[partid
].magic
= 0;
1300 /* in case we've still got outstanding timers registered... */
1301 del_timer_sync(&part_sn2
->dropped_notify_IRQ_timer
);
1302 free_irq(SGI_XPC_NOTIFY
, (void *)(u64
)partid
);
1304 kfree(part_sn2
->local_openclose_args_base
);
1305 part_sn2
->local_openclose_args
= NULL
;
1306 kfree(part_sn2
->remote_GPs_base
);
1307 part_sn2
->remote_GPs
= NULL
;
1308 kfree(part_sn2
->local_GPs_base
);
1309 part_sn2
->local_GPs
= NULL
;
1310 part_sn2
->local_chctl_amo_va
= NULL
;
1314 * Create a wrapper that hides the underlying mechanism for pulling a cacheline
1315 * (or multiple cachelines) from a remote partition.
1317 * src_pa must be a cacheline aligned physical address on the remote partition.
1318 * dst must be a cacheline aligned virtual address on this partition.
1319 * cnt must be cacheline sized
1321 /* ??? Replace this function by call to xp_remote_memcpy() or bte_copy()? */
1322 static enum xp_retval
1323 xpc_pull_remote_cachelines_sn2(struct xpc_partition
*part
, void *dst
,
1324 const unsigned long src_pa
, size_t cnt
)
1328 DBUG_ON(src_pa
!= L1_CACHE_ALIGN(src_pa
));
1329 DBUG_ON((unsigned long)dst
!= L1_CACHE_ALIGN((unsigned long)dst
));
1330 DBUG_ON(cnt
!= L1_CACHE_ALIGN(cnt
));
1332 if (part
->act_state
== XPC_P_AS_DEACTIVATING
)
1333 return part
->reason
;
1335 ret
= xp_remote_memcpy(xp_pa(dst
), src_pa
, cnt
);
1336 if (ret
!= xpSuccess
) {
1337 dev_dbg(xpc_chan
, "xp_remote_memcpy() from partition %d failed,"
1338 " ret=%d\n", XPC_PARTID(part
), ret
);
1344 * Pull the remote per partition specific variables from the specified
1347 static enum xp_retval
1348 xpc_pull_remote_vars_part_sn2(struct xpc_partition
*part
)
1350 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
1351 u8 buffer
[L1_CACHE_BYTES
* 2];
1352 struct xpc_vars_part_sn2
*pulled_entry_cacheline
=
1353 (struct xpc_vars_part_sn2
*)L1_CACHE_ALIGN((u64
)buffer
);
1354 struct xpc_vars_part_sn2
*pulled_entry
;
1355 unsigned long remote_entry_cacheline_pa
;
1356 unsigned long remote_entry_pa
;
1357 short partid
= XPC_PARTID(part
);
1360 /* pull the cacheline that contains the variables we're interested in */
1362 DBUG_ON(part_sn2
->remote_vars_part_pa
!=
1363 L1_CACHE_ALIGN(part_sn2
->remote_vars_part_pa
));
1364 DBUG_ON(sizeof(struct xpc_vars_part_sn2
) != L1_CACHE_BYTES
/ 2);
1366 remote_entry_pa
= part_sn2
->remote_vars_part_pa
+
1367 sn_partition_id
* sizeof(struct xpc_vars_part_sn2
);
1369 remote_entry_cacheline_pa
= (remote_entry_pa
& ~(L1_CACHE_BYTES
- 1));
1371 pulled_entry
= (struct xpc_vars_part_sn2
*)((u64
)pulled_entry_cacheline
1372 + (remote_entry_pa
&
1373 (L1_CACHE_BYTES
- 1)));
1375 ret
= xpc_pull_remote_cachelines_sn2(part
, pulled_entry_cacheline
,
1376 remote_entry_cacheline_pa
,
1378 if (ret
!= xpSuccess
) {
1379 dev_dbg(xpc_chan
, "failed to pull XPC vars_part from "
1380 "partition %d, ret=%d\n", partid
, ret
);
1384 /* see if they've been set up yet */
1386 if (pulled_entry
->magic
!= XPC_VP_MAGIC1_SN2
&&
1387 pulled_entry
->magic
!= XPC_VP_MAGIC2_SN2
) {
1389 if (pulled_entry
->magic
!= 0) {
1390 dev_dbg(xpc_chan
, "partition %d's XPC vars_part for "
1391 "partition %d has bad magic value (=0x%llx)\n",
1392 partid
, sn_partition_id
, pulled_entry
->magic
);
1396 /* they've not been initialized yet */
1400 if (xpc_vars_part_sn2
[partid
].magic
== XPC_VP_MAGIC1_SN2
) {
1402 /* validate the variables */
1404 if (pulled_entry
->GPs_pa
== 0 ||
1405 pulled_entry
->openclose_args_pa
== 0 ||
1406 pulled_entry
->chctl_amo_pa
== 0) {
1408 dev_err(xpc_chan
, "partition %d's XPC vars_part for "
1409 "partition %d are not valid\n", partid
,
1411 return xpInvalidAddress
;
1414 /* the variables we imported look to be valid */
1416 part_sn2
->remote_GPs_pa
= pulled_entry
->GPs_pa
;
1417 part_sn2
->remote_openclose_args_pa
=
1418 pulled_entry
->openclose_args_pa
;
1419 part_sn2
->remote_chctl_amo_va
=
1420 (struct amo
*)__va(pulled_entry
->chctl_amo_pa
);
1421 part_sn2
->notify_IRQ_nasid
= pulled_entry
->notify_IRQ_nasid
;
1422 part_sn2
->notify_IRQ_phys_cpuid
=
1423 pulled_entry
->notify_IRQ_phys_cpuid
;
1425 if (part
->nchannels
> pulled_entry
->nchannels
)
1426 part
->nchannels
= pulled_entry
->nchannels
;
1428 /* let the other side know that we've pulled their variables */
1430 xpc_vars_part_sn2
[partid
].magic
= XPC_VP_MAGIC2_SN2
;
1433 if (pulled_entry
->magic
== XPC_VP_MAGIC1_SN2
)
1440 * Establish first contact with the remote partititon. This involves pulling
1441 * the XPC per partition variables from the remote partition and waiting for
1442 * the remote partition to pull ours.
1444 static enum xp_retval
1445 xpc_make_first_contact_sn2(struct xpc_partition
*part
)
1447 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
1451 * Register the remote partition's amos with SAL so it can handle
1452 * and cleanup errors within that address range should the remote
1453 * partition go down. We don't unregister this range because it is
1454 * difficult to tell when outstanding writes to the remote partition
1455 * are finished and thus when it is safe to unregister. This should
1456 * not result in wasted space in the SAL xp_addr_region table because
1457 * we should get the same page for remote_amos_page_pa after module
1458 * reloads and system reboots.
1460 if (sn_register_xp_addr_region(part_sn2
->remote_amos_page_pa
,
1461 PAGE_SIZE
, 1) < 0) {
1462 dev_warn(xpc_part
, "xpc_activating(%d) failed to register "
1463 "xp_addr region\n", XPC_PARTID(part
));
1465 ret
= xpPhysAddrRegFailed
;
1466 XPC_DEACTIVATE_PARTITION(part
, ret
);
1471 * Send activate IRQ to get other side to activate if they've not
1472 * already begun to do so.
1474 xpc_send_activate_IRQ_sn2(part_sn2
->remote_amos_page_pa
,
1475 cnodeid_to_nasid(0),
1476 part_sn2
->activate_IRQ_nasid
,
1477 part_sn2
->activate_IRQ_phys_cpuid
);
1479 while ((ret
= xpc_pull_remote_vars_part_sn2(part
)) != xpSuccess
) {
1480 if (ret
!= xpRetry
) {
1481 XPC_DEACTIVATE_PARTITION(part
, ret
);
1485 dev_dbg(xpc_part
, "waiting to make first contact with "
1486 "partition %d\n", XPC_PARTID(part
));
1488 /* wait a 1/4 of a second or so */
1489 (void)msleep_interruptible(250);
1491 if (part
->act_state
== XPC_P_AS_DEACTIVATING
)
1492 return part
->reason
;
1499 * Get the chctl flags and pull the openclose args and/or remote GPs as needed.
1502 xpc_get_chctl_all_flags_sn2(struct xpc_partition
*part
)
1504 struct xpc_partition_sn2
*part_sn2
= &part
->sn
.sn2
;
1505 unsigned long irq_flags
;
1506 union xpc_channel_ctl_flags chctl
;
1510 * See if there are any chctl flags to be handled.
1513 spin_lock_irqsave(&part
->chctl_lock
, irq_flags
);
1514 chctl
= part
->chctl
;
1515 if (chctl
.all_flags
!= 0)
1516 part
->chctl
.all_flags
= 0;
1518 spin_unlock_irqrestore(&part
->chctl_lock
, irq_flags
);
1520 if (xpc_any_openclose_chctl_flags_set(&chctl
)) {
1521 ret
= xpc_pull_remote_cachelines_sn2(part
, part
->
1522 remote_openclose_args
,
1524 remote_openclose_args_pa
,
1525 XPC_OPENCLOSE_ARGS_SIZE
);
1526 if (ret
!= xpSuccess
) {
1527 XPC_DEACTIVATE_PARTITION(part
, ret
);
1529 dev_dbg(xpc_chan
, "failed to pull openclose args from "
1530 "partition %d, ret=%d\n", XPC_PARTID(part
),
1533 /* don't bother processing chctl flags anymore */
1534 chctl
.all_flags
= 0;
1538 if (xpc_any_msg_chctl_flags_set(&chctl
)) {
1539 ret
= xpc_pull_remote_cachelines_sn2(part
, part_sn2
->remote_GPs
,
1540 part_sn2
->remote_GPs_pa
,
1542 if (ret
!= xpSuccess
) {
1543 XPC_DEACTIVATE_PARTITION(part
, ret
);
1545 dev_dbg(xpc_chan
, "failed to pull GPs from partition "
1546 "%d, ret=%d\n", XPC_PARTID(part
), ret
);
1548 /* don't bother processing chctl flags anymore */
1549 chctl
.all_flags
= 0;
1553 return chctl
.all_flags
;
1557 * Allocate the local message queue and the notify queue.
1559 static enum xp_retval
1560 xpc_allocate_local_msgqueue_sn2(struct xpc_channel
*ch
)
1562 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1563 unsigned long irq_flags
;
1567 for (nentries
= ch
->local_nentries
; nentries
> 0; nentries
--) {
1569 nbytes
= nentries
* ch
->entry_size
;
1570 ch_sn2
->local_msgqueue
=
1571 xpc_kzalloc_cacheline_aligned(nbytes
, GFP_KERNEL
,
1572 &ch_sn2
->local_msgqueue_base
);
1573 if (ch_sn2
->local_msgqueue
== NULL
)
1576 nbytes
= nentries
* sizeof(struct xpc_notify_sn2
);
1577 ch_sn2
->notify_queue
= kzalloc(nbytes
, GFP_KERNEL
);
1578 if (ch_sn2
->notify_queue
== NULL
) {
1579 kfree(ch_sn2
->local_msgqueue_base
);
1580 ch_sn2
->local_msgqueue
= NULL
;
1584 spin_lock_irqsave(&ch
->lock
, irq_flags
);
1585 if (nentries
< ch
->local_nentries
) {
1586 dev_dbg(xpc_chan
, "nentries=%d local_nentries=%d, "
1587 "partid=%d, channel=%d\n", nentries
,
1588 ch
->local_nentries
, ch
->partid
, ch
->number
);
1590 ch
->local_nentries
= nentries
;
1592 spin_unlock_irqrestore(&ch
->lock
, irq_flags
);
1596 dev_dbg(xpc_chan
, "can't get memory for local message queue and notify "
1597 "queue, partid=%d, channel=%d\n", ch
->partid
, ch
->number
);
1602 * Allocate the cached remote message queue.
1604 static enum xp_retval
1605 xpc_allocate_remote_msgqueue_sn2(struct xpc_channel
*ch
)
1607 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1608 unsigned long irq_flags
;
1612 DBUG_ON(ch
->remote_nentries
<= 0);
1614 for (nentries
= ch
->remote_nentries
; nentries
> 0; nentries
--) {
1616 nbytes
= nentries
* ch
->entry_size
;
1617 ch_sn2
->remote_msgqueue
=
1618 xpc_kzalloc_cacheline_aligned(nbytes
, GFP_KERNEL
, &ch_sn2
->
1619 remote_msgqueue_base
);
1620 if (ch_sn2
->remote_msgqueue
== NULL
)
1623 spin_lock_irqsave(&ch
->lock
, irq_flags
);
1624 if (nentries
< ch
->remote_nentries
) {
1625 dev_dbg(xpc_chan
, "nentries=%d remote_nentries=%d, "
1626 "partid=%d, channel=%d\n", nentries
,
1627 ch
->remote_nentries
, ch
->partid
, ch
->number
);
1629 ch
->remote_nentries
= nentries
;
1631 spin_unlock_irqrestore(&ch
->lock
, irq_flags
);
1635 dev_dbg(xpc_chan
, "can't get memory for cached remote message queue, "
1636 "partid=%d, channel=%d\n", ch
->partid
, ch
->number
);
1641 * Allocate message queues and other stuff associated with a channel.
1643 * Note: Assumes all of the channel sizes are filled in.
1645 static enum xp_retval
1646 xpc_setup_msg_structures_sn2(struct xpc_channel
*ch
)
1648 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1651 DBUG_ON(ch
->flags
& XPC_C_SETUP
);
1653 ret
= xpc_allocate_local_msgqueue_sn2(ch
);
1654 if (ret
== xpSuccess
) {
1656 ret
= xpc_allocate_remote_msgqueue_sn2(ch
);
1657 if (ret
!= xpSuccess
) {
1658 kfree(ch_sn2
->local_msgqueue_base
);
1659 ch_sn2
->local_msgqueue
= NULL
;
1660 kfree(ch_sn2
->notify_queue
);
1661 ch_sn2
->notify_queue
= NULL
;
1668 * Free up message queues and other stuff that were allocated for the specified
1672 xpc_teardown_msg_structures_sn2(struct xpc_channel
*ch
)
1674 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1676 DBUG_ON(!spin_is_locked(&ch
->lock
));
1678 ch_sn2
->remote_msgqueue_pa
= 0;
1680 ch_sn2
->local_GP
->get
= 0;
1681 ch_sn2
->local_GP
->put
= 0;
1682 ch_sn2
->remote_GP
.get
= 0;
1683 ch_sn2
->remote_GP
.put
= 0;
1684 ch_sn2
->w_local_GP
.get
= 0;
1685 ch_sn2
->w_local_GP
.put
= 0;
1686 ch_sn2
->w_remote_GP
.get
= 0;
1687 ch_sn2
->w_remote_GP
.put
= 0;
1688 ch_sn2
->next_msg_to_pull
= 0;
1690 if (ch
->flags
& XPC_C_SETUP
) {
1691 dev_dbg(xpc_chan
, "ch->flags=0x%x, partid=%d, channel=%d\n",
1692 ch
->flags
, ch
->partid
, ch
->number
);
1694 kfree(ch_sn2
->local_msgqueue_base
);
1695 ch_sn2
->local_msgqueue
= NULL
;
1696 kfree(ch_sn2
->remote_msgqueue_base
);
1697 ch_sn2
->remote_msgqueue
= NULL
;
1698 kfree(ch_sn2
->notify_queue
);
1699 ch_sn2
->notify_queue
= NULL
;
1704 * Notify those who wanted to be notified upon delivery of their message.
1707 xpc_notify_senders_sn2(struct xpc_channel
*ch
, enum xp_retval reason
, s64 put
)
1709 struct xpc_notify_sn2
*notify
;
1711 s64 get
= ch
->sn
.sn2
.w_remote_GP
.get
- 1;
1713 while (++get
< put
&& atomic_read(&ch
->n_to_notify
) > 0) {
1715 notify
= &ch
->sn
.sn2
.notify_queue
[get
% ch
->local_nentries
];
1718 * See if the notify entry indicates it was associated with
1719 * a message who's sender wants to be notified. It is possible
1720 * that it is, but someone else is doing or has done the
1723 notify_type
= notify
->type
;
1724 if (notify_type
== 0 ||
1725 cmpxchg(¬ify
->type
, notify_type
, 0) != notify_type
) {
1729 DBUG_ON(notify_type
!= XPC_N_CALL
);
1731 atomic_dec(&ch
->n_to_notify
);
1733 if (notify
->func
!= NULL
) {
1734 dev_dbg(xpc_chan
, "notify->func() called, notify=0x%p "
1735 "msg_number=%lld partid=%d channel=%d\n",
1736 (void *)notify
, get
, ch
->partid
, ch
->number
);
1738 notify
->func(reason
, ch
->partid
, ch
->number
,
1741 dev_dbg(xpc_chan
, "notify->func() returned, notify=0x%p"
1742 " msg_number=%lld partid=%d channel=%d\n",
1743 (void *)notify
, get
, ch
->partid
, ch
->number
);
1749 xpc_notify_senders_of_disconnect_sn2(struct xpc_channel
*ch
)
1751 xpc_notify_senders_sn2(ch
, ch
->reason
, ch
->sn
.sn2
.w_local_GP
.put
);
1755 * Clear some of the msg flags in the local message queue.
1758 xpc_clear_local_msgqueue_flags_sn2(struct xpc_channel
*ch
)
1760 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1761 struct xpc_msg_sn2
*msg
;
1764 get
= ch_sn2
->w_remote_GP
.get
;
1766 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->local_msgqueue
+
1767 (get
% ch
->local_nentries
) *
1769 DBUG_ON(!(msg
->flags
& XPC_M_SN2_READY
));
1771 } while (++get
< ch_sn2
->remote_GP
.get
);
1775 * Clear some of the msg flags in the remote message queue.
1778 xpc_clear_remote_msgqueue_flags_sn2(struct xpc_channel
*ch
)
1780 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1781 struct xpc_msg_sn2
*msg
;
1782 s64 put
, remote_nentries
= ch
->remote_nentries
;
1784 /* flags are zeroed when the buffer is allocated */
1785 if (ch_sn2
->remote_GP
.put
< remote_nentries
)
1788 put
= max(ch_sn2
->w_remote_GP
.put
, remote_nentries
);
1790 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->remote_msgqueue
+
1791 (put
% remote_nentries
) *
1793 DBUG_ON(!(msg
->flags
& XPC_M_SN2_READY
));
1794 DBUG_ON(!(msg
->flags
& XPC_M_SN2_DONE
));
1795 DBUG_ON(msg
->number
!= put
- remote_nentries
);
1797 } while (++put
< ch_sn2
->remote_GP
.put
);
1801 xpc_n_of_deliverable_payloads_sn2(struct xpc_channel
*ch
)
1803 return ch
->sn
.sn2
.w_remote_GP
.put
- ch
->sn
.sn2
.w_local_GP
.get
;
1807 xpc_process_msg_chctl_flags_sn2(struct xpc_partition
*part
, int ch_number
)
1809 struct xpc_channel
*ch
= &part
->channels
[ch_number
];
1810 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1813 ch_sn2
->remote_GP
= part
->sn
.sn2
.remote_GPs
[ch_number
];
1815 /* See what, if anything, has changed for each connected channel */
1817 xpc_msgqueue_ref(ch
);
1819 if (ch_sn2
->w_remote_GP
.get
== ch_sn2
->remote_GP
.get
&&
1820 ch_sn2
->w_remote_GP
.put
== ch_sn2
->remote_GP
.put
) {
1821 /* nothing changed since GPs were last pulled */
1822 xpc_msgqueue_deref(ch
);
1826 if (!(ch
->flags
& XPC_C_CONNECTED
)) {
1827 xpc_msgqueue_deref(ch
);
1832 * First check to see if messages recently sent by us have been
1833 * received by the other side. (The remote GET value will have
1834 * changed since we last looked at it.)
1837 if (ch_sn2
->w_remote_GP
.get
!= ch_sn2
->remote_GP
.get
) {
1840 * We need to notify any senders that want to be notified
1841 * that their sent messages have been received by their
1842 * intended recipients. We need to do this before updating
1843 * w_remote_GP.get so that we don't allocate the same message
1844 * queue entries prematurely (see xpc_allocate_msg()).
1846 if (atomic_read(&ch
->n_to_notify
) > 0) {
1848 * Notify senders that messages sent have been
1849 * received and delivered by the other side.
1851 xpc_notify_senders_sn2(ch
, xpMsgDelivered
,
1852 ch_sn2
->remote_GP
.get
);
1856 * Clear msg->flags in previously sent messages, so that
1857 * they're ready for xpc_allocate_msg().
1859 xpc_clear_local_msgqueue_flags_sn2(ch
);
1861 ch_sn2
->w_remote_GP
.get
= ch_sn2
->remote_GP
.get
;
1863 dev_dbg(xpc_chan
, "w_remote_GP.get changed to %lld, partid=%d, "
1864 "channel=%d\n", ch_sn2
->w_remote_GP
.get
, ch
->partid
,
1868 * If anyone was waiting for message queue entries to become
1869 * available, wake them up.
1871 if (atomic_read(&ch
->n_on_msg_allocate_wq
) > 0)
1872 wake_up(&ch
->msg_allocate_wq
);
1876 * Now check for newly sent messages by the other side. (The remote
1877 * PUT value will have changed since we last looked at it.)
1880 if (ch_sn2
->w_remote_GP
.put
!= ch_sn2
->remote_GP
.put
) {
1882 * Clear msg->flags in previously received messages, so that
1883 * they're ready for xpc_get_deliverable_payload_sn2().
1885 xpc_clear_remote_msgqueue_flags_sn2(ch
);
1887 smp_wmb(); /* ensure flags have been cleared before bte_copy */
1888 ch_sn2
->w_remote_GP
.put
= ch_sn2
->remote_GP
.put
;
1890 dev_dbg(xpc_chan
, "w_remote_GP.put changed to %lld, partid=%d, "
1891 "channel=%d\n", ch_sn2
->w_remote_GP
.put
, ch
->partid
,
1894 npayloads_sent
= xpc_n_of_deliverable_payloads_sn2(ch
);
1895 if (npayloads_sent
> 0) {
1896 dev_dbg(xpc_chan
, "msgs waiting to be copied and "
1897 "delivered=%d, partid=%d, channel=%d\n",
1898 npayloads_sent
, ch
->partid
, ch
->number
);
1900 if (ch
->flags
& XPC_C_CONNECTEDCALLOUT_MADE
)
1901 xpc_activate_kthreads(ch
, npayloads_sent
);
1905 xpc_msgqueue_deref(ch
);
1908 static struct xpc_msg_sn2
*
1909 xpc_pull_remote_msg_sn2(struct xpc_channel
*ch
, s64 get
)
1911 struct xpc_partition
*part
= &xpc_partitions
[ch
->partid
];
1912 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1913 unsigned long remote_msg_pa
;
1914 struct xpc_msg_sn2
*msg
;
1920 if (mutex_lock_interruptible(&ch_sn2
->msg_to_pull_mutex
) != 0) {
1921 /* we were interrupted by a signal */
1925 while (get
>= ch_sn2
->next_msg_to_pull
) {
1927 /* pull as many messages as are ready and able to be pulled */
1929 msg_index
= ch_sn2
->next_msg_to_pull
% ch
->remote_nentries
;
1931 DBUG_ON(ch_sn2
->next_msg_to_pull
>= ch_sn2
->w_remote_GP
.put
);
1932 nmsgs
= ch_sn2
->w_remote_GP
.put
- ch_sn2
->next_msg_to_pull
;
1933 if (msg_index
+ nmsgs
> ch
->remote_nentries
) {
1934 /* ignore the ones that wrap the msg queue for now */
1935 nmsgs
= ch
->remote_nentries
- msg_index
;
1938 msg_offset
= msg_index
* ch
->entry_size
;
1939 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->remote_msgqueue
+
1941 remote_msg_pa
= ch_sn2
->remote_msgqueue_pa
+ msg_offset
;
1943 ret
= xpc_pull_remote_cachelines_sn2(part
, msg
, remote_msg_pa
,
1944 nmsgs
* ch
->entry_size
);
1945 if (ret
!= xpSuccess
) {
1947 dev_dbg(xpc_chan
, "failed to pull %d msgs starting with"
1948 " msg %lld from partition %d, channel=%d, "
1949 "ret=%d\n", nmsgs
, ch_sn2
->next_msg_to_pull
,
1950 ch
->partid
, ch
->number
, ret
);
1952 XPC_DEACTIVATE_PARTITION(part
, ret
);
1954 mutex_unlock(&ch_sn2
->msg_to_pull_mutex
);
1958 ch_sn2
->next_msg_to_pull
+= nmsgs
;
1961 mutex_unlock(&ch_sn2
->msg_to_pull_mutex
);
1963 /* return the message we were looking for */
1964 msg_offset
= (get
% ch
->remote_nentries
) * ch
->entry_size
;
1965 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->remote_msgqueue
+ msg_offset
);
1971 * Get the next deliverable message's payload.
1974 xpc_get_deliverable_payload_sn2(struct xpc_channel
*ch
)
1976 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
1977 struct xpc_msg_sn2
*msg
;
1978 void *payload
= NULL
;
1982 if (ch
->flags
& XPC_C_DISCONNECTING
)
1985 get
= ch_sn2
->w_local_GP
.get
;
1986 smp_rmb(); /* guarantee that .get loads before .put */
1987 if (get
== ch_sn2
->w_remote_GP
.put
)
1990 /* There are messages waiting to be pulled and delivered.
1991 * We need to try to secure one for ourselves. We'll do this
1992 * by trying to increment w_local_GP.get and hope that no one
1993 * else beats us to it. If they do, we'll we'll simply have
1994 * to try again for the next one.
1997 if (cmpxchg(&ch_sn2
->w_local_GP
.get
, get
, get
+ 1) == get
) {
1998 /* we got the entry referenced by get */
2000 dev_dbg(xpc_chan
, "w_local_GP.get changed to %lld, "
2001 "partid=%d, channel=%d\n", get
+ 1,
2002 ch
->partid
, ch
->number
);
2004 /* pull the message from the remote partition */
2006 msg
= xpc_pull_remote_msg_sn2(ch
, get
);
2009 DBUG_ON(msg
->number
!= get
);
2010 DBUG_ON(msg
->flags
& XPC_M_SN2_DONE
);
2011 DBUG_ON(!(msg
->flags
& XPC_M_SN2_READY
));
2013 payload
= &msg
->payload
;
2024 * Now we actually send the messages that are ready to be sent by advancing
2025 * the local message queue's Put value and then send a chctl msgrequest to the
2026 * recipient partition.
2029 xpc_send_msgs_sn2(struct xpc_channel
*ch
, s64 initial_put
)
2031 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
2032 struct xpc_msg_sn2
*msg
;
2033 s64 put
= initial_put
+ 1;
2034 int send_msgrequest
= 0;
2039 if (put
== ch_sn2
->w_local_GP
.put
)
2042 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->
2043 local_msgqueue
+ (put
%
2044 ch
->local_nentries
) *
2047 if (!(msg
->flags
& XPC_M_SN2_READY
))
2053 if (put
== initial_put
) {
2054 /* nothing's changed */
2058 if (cmpxchg_rel(&ch_sn2
->local_GP
->put
, initial_put
, put
) !=
2060 /* someone else beat us to it */
2061 DBUG_ON(ch_sn2
->local_GP
->put
< initial_put
);
2065 /* we just set the new value of local_GP->put */
2067 dev_dbg(xpc_chan
, "local_GP->put changed to %lld, partid=%d, "
2068 "channel=%d\n", put
, ch
->partid
, ch
->number
);
2070 send_msgrequest
= 1;
2073 * We need to ensure that the message referenced by
2074 * local_GP->put is not XPC_M_SN2_READY or that local_GP->put
2075 * equals w_local_GP.put, so we'll go have a look.
2080 if (send_msgrequest
)
2081 xpc_send_chctl_msgrequest_sn2(ch
);
2085 * Allocate an entry for a message from the message queue associated with the
2086 * specified channel.
2088 static enum xp_retval
2089 xpc_allocate_msg_sn2(struct xpc_channel
*ch
, u32 flags
,
2090 struct xpc_msg_sn2
**address_of_msg
)
2092 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
2093 struct xpc_msg_sn2
*msg
;
2098 * Get the next available message entry from the local message queue.
2099 * If none are available, we'll make sure that we grab the latest
2106 put
= ch_sn2
->w_local_GP
.put
;
2107 smp_rmb(); /* guarantee that .put loads before .get */
2108 if (put
- ch_sn2
->w_remote_GP
.get
< ch
->local_nentries
) {
2110 /* There are available message entries. We need to try
2111 * to secure one for ourselves. We'll do this by trying
2112 * to increment w_local_GP.put as long as someone else
2113 * doesn't beat us to it. If they do, we'll have to
2116 if (cmpxchg(&ch_sn2
->w_local_GP
.put
, put
, put
+ 1) ==
2118 /* we got the entry referenced by put */
2121 continue; /* try again */
2125 * There aren't any available msg entries at this time.
2127 * In waiting for a message entry to become available,
2128 * we set a timeout in case the other side is not sending
2129 * completion interrupts. This lets us fake a notify IRQ
2130 * that will cause the notify IRQ handler to fetch the latest
2131 * GP values as if an interrupt was sent by the other side.
2133 if (ret
== xpTimeout
)
2134 xpc_send_chctl_local_msgrequest_sn2(ch
);
2136 if (flags
& XPC_NOWAIT
)
2139 ret
= xpc_allocate_msg_wait(ch
);
2140 if (ret
!= xpInterrupted
&& ret
!= xpTimeout
)
2144 /* get the message's address and initialize it */
2145 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->local_msgqueue
+
2146 (put
% ch
->local_nentries
) *
2149 DBUG_ON(msg
->flags
!= 0);
2152 dev_dbg(xpc_chan
, "w_local_GP.put changed to %lld; msg=0x%p, "
2153 "msg_number=%lld, partid=%d, channel=%d\n", put
+ 1,
2154 (void *)msg
, msg
->number
, ch
->partid
, ch
->number
);
2156 *address_of_msg
= msg
;
2161 * Common code that does the actual sending of the message by advancing the
2162 * local message queue's Put value and sends a chctl msgrequest to the
2163 * partition the message is being sent to.
2165 static enum xp_retval
2166 xpc_send_payload_sn2(struct xpc_channel
*ch
, u32 flags
, void *payload
,
2167 u16 payload_size
, u8 notify_type
, xpc_notify_func func
,
2170 enum xp_retval ret
= xpSuccess
;
2171 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
2172 struct xpc_msg_sn2
*msg
= msg
;
2173 struct xpc_notify_sn2
*notify
= notify
;
2177 DBUG_ON(notify_type
== XPC_N_CALL
&& func
== NULL
);
2179 if (XPC_MSG_SIZE(payload_size
) > ch
->entry_size
)
2180 return xpPayloadTooBig
;
2182 xpc_msgqueue_ref(ch
);
2184 if (ch
->flags
& XPC_C_DISCONNECTING
) {
2188 if (!(ch
->flags
& XPC_C_CONNECTED
)) {
2189 ret
= xpNotConnected
;
2193 ret
= xpc_allocate_msg_sn2(ch
, flags
, &msg
);
2194 if (ret
!= xpSuccess
)
2197 msg_number
= msg
->number
;
2199 if (notify_type
!= 0) {
2201 * Tell the remote side to send an ACK interrupt when the
2202 * message has been delivered.
2204 msg
->flags
|= XPC_M_SN2_INTERRUPT
;
2206 atomic_inc(&ch
->n_to_notify
);
2208 notify
= &ch_sn2
->notify_queue
[msg_number
% ch
->local_nentries
];
2209 notify
->func
= func
;
2211 notify
->type
= notify_type
;
2213 /* ??? Is a mb() needed here? */
2215 if (ch
->flags
& XPC_C_DISCONNECTING
) {
2217 * An error occurred between our last error check and
2218 * this one. We will try to clear the type field from
2219 * the notify entry. If we succeed then
2220 * xpc_disconnect_channel() didn't already process
2223 if (cmpxchg(¬ify
->type
, notify_type
, 0) ==
2225 atomic_dec(&ch
->n_to_notify
);
2232 memcpy(&msg
->payload
, payload
, payload_size
);
2234 msg
->flags
|= XPC_M_SN2_READY
;
2237 * The preceding store of msg->flags must occur before the following
2238 * load of local_GP->put.
2242 /* see if the message is next in line to be sent, if so send it */
2244 put
= ch_sn2
->local_GP
->put
;
2245 if (put
== msg_number
)
2246 xpc_send_msgs_sn2(ch
, put
);
2249 xpc_msgqueue_deref(ch
);
2254 * Now we actually acknowledge the messages that have been delivered and ack'd
2255 * by advancing the cached remote message queue's Get value and if requested
2256 * send a chctl msgrequest to the message sender's partition.
2258 * If a message has XPC_M_SN2_INTERRUPT set, send an interrupt to the partition
2259 * that sent the message.
2262 xpc_acknowledge_msgs_sn2(struct xpc_channel
*ch
, s64 initial_get
, u8 msg_flags
)
2264 struct xpc_channel_sn2
*ch_sn2
= &ch
->sn
.sn2
;
2265 struct xpc_msg_sn2
*msg
;
2266 s64 get
= initial_get
+ 1;
2267 int send_msgrequest
= 0;
2272 if (get
== ch_sn2
->w_local_GP
.get
)
2275 msg
= (struct xpc_msg_sn2
*)((u64
)ch_sn2
->
2276 remote_msgqueue
+ (get
%
2277 ch
->remote_nentries
) *
2280 if (!(msg
->flags
& XPC_M_SN2_DONE
))
2283 msg_flags
|= msg
->flags
;
2287 if (get
== initial_get
) {
2288 /* nothing's changed */
2292 if (cmpxchg_rel(&ch_sn2
->local_GP
->get
, initial_get
, get
) !=
2294 /* someone else beat us to it */
2295 DBUG_ON(ch_sn2
->local_GP
->get
<= initial_get
);
2299 /* we just set the new value of local_GP->get */
2301 dev_dbg(xpc_chan
, "local_GP->get changed to %lld, partid=%d, "
2302 "channel=%d\n", get
, ch
->partid
, ch
->number
);
2304 send_msgrequest
= (msg_flags
& XPC_M_SN2_INTERRUPT
);
2307 * We need to ensure that the message referenced by
2308 * local_GP->get is not XPC_M_SN2_DONE or that local_GP->get
2309 * equals w_local_GP.get, so we'll go have a look.
2314 if (send_msgrequest
)
2315 xpc_send_chctl_msgrequest_sn2(ch
);
2319 xpc_received_payload_sn2(struct xpc_channel
*ch
, void *payload
)
2321 struct xpc_msg_sn2
*msg
;
2325 msg
= container_of(payload
, struct xpc_msg_sn2
, payload
);
2326 msg_number
= msg
->number
;
2328 dev_dbg(xpc_chan
, "msg=0x%p, msg_number=%lld, partid=%d, channel=%d\n",
2329 (void *)msg
, msg_number
, ch
->partid
, ch
->number
);
2331 DBUG_ON((((u64
)msg
- (u64
)ch
->sn
.sn2
.remote_msgqueue
) / ch
->entry_size
) !=
2332 msg_number
% ch
->remote_nentries
);
2333 DBUG_ON(!(msg
->flags
& XPC_M_SN2_READY
));
2334 DBUG_ON(msg
->flags
& XPC_M_SN2_DONE
);
2336 msg
->flags
|= XPC_M_SN2_DONE
;
2339 * The preceding store of msg->flags must occur before the following
2340 * load of local_GP->get.
2345 * See if this message is next in line to be acknowledged as having
2348 get
= ch
->sn
.sn2
.local_GP
->get
;
2349 if (get
== msg_number
)
2350 xpc_acknowledge_msgs_sn2(ch
, get
, msg
->flags
);
2353 static struct xpc_arch_operations xpc_arch_ops_sn2
= {
2354 .setup_partitions
= xpc_setup_partitions_sn2
,
2355 .teardown_partitions
= xpc_teardown_partitions_sn2
,
2356 .process_activate_IRQ_rcvd
= xpc_process_activate_IRQ_rcvd_sn2
,
2357 .get_partition_rsvd_page_pa
= xpc_get_partition_rsvd_page_pa_sn2
,
2358 .setup_rsvd_page
= xpc_setup_rsvd_page_sn2
,
2360 .allow_hb
= xpc_allow_hb_sn2
,
2361 .disallow_hb
= xpc_disallow_hb_sn2
,
2362 .disallow_all_hbs
= xpc_disallow_all_hbs_sn2
,
2363 .increment_heartbeat
= xpc_increment_heartbeat_sn2
,
2364 .offline_heartbeat
= xpc_offline_heartbeat_sn2
,
2365 .online_heartbeat
= xpc_online_heartbeat_sn2
,
2366 .heartbeat_init
= xpc_heartbeat_init_sn2
,
2367 .heartbeat_exit
= xpc_heartbeat_exit_sn2
,
2368 .get_remote_heartbeat
= xpc_get_remote_heartbeat_sn2
,
2370 .request_partition_activation
=
2371 xpc_request_partition_activation_sn2
,
2372 .request_partition_reactivation
=
2373 xpc_request_partition_reactivation_sn2
,
2374 .request_partition_deactivation
=
2375 xpc_request_partition_deactivation_sn2
,
2376 .cancel_partition_deactivation_request
=
2377 xpc_cancel_partition_deactivation_request_sn2
,
2379 .setup_ch_structures
= xpc_setup_ch_structures_sn2
,
2380 .teardown_ch_structures
= xpc_teardown_ch_structures_sn2
,
2382 .make_first_contact
= xpc_make_first_contact_sn2
,
2384 .get_chctl_all_flags
= xpc_get_chctl_all_flags_sn2
,
2385 .send_chctl_closerequest
= xpc_send_chctl_closerequest_sn2
,
2386 .send_chctl_closereply
= xpc_send_chctl_closereply_sn2
,
2387 .send_chctl_openrequest
= xpc_send_chctl_openrequest_sn2
,
2388 .send_chctl_openreply
= xpc_send_chctl_openreply_sn2
,
2389 .send_chctl_opencomplete
= xpc_send_chctl_opencomplete_sn2
,
2390 .process_msg_chctl_flags
= xpc_process_msg_chctl_flags_sn2
,
2392 .save_remote_msgqueue_pa
= xpc_save_remote_msgqueue_pa_sn2
,
2394 .setup_msg_structures
= xpc_setup_msg_structures_sn2
,
2395 .teardown_msg_structures
= xpc_teardown_msg_structures_sn2
,
2397 .indicate_partition_engaged
= xpc_indicate_partition_engaged_sn2
,
2398 .indicate_partition_disengaged
= xpc_indicate_partition_disengaged_sn2
,
2399 .partition_engaged
= xpc_partition_engaged_sn2
,
2400 .any_partition_engaged
= xpc_any_partition_engaged_sn2
,
2401 .assume_partition_disengaged
= xpc_assume_partition_disengaged_sn2
,
2403 .n_of_deliverable_payloads
= xpc_n_of_deliverable_payloads_sn2
,
2404 .send_payload
= xpc_send_payload_sn2
,
2405 .get_deliverable_payload
= xpc_get_deliverable_payload_sn2
,
2406 .received_payload
= xpc_received_payload_sn2
,
2407 .notify_senders_of_disconnect
= xpc_notify_senders_of_disconnect_sn2
,
2416 xpc_arch_ops
= xpc_arch_ops_sn2
;
2418 if (offsetof(struct xpc_msg_sn2
, payload
) > XPC_MSG_HDR_MAX_SIZE
) {
2419 dev_err(xpc_part
, "header portion of struct xpc_msg_sn2 is "
2420 "larger than %d\n", XPC_MSG_HDR_MAX_SIZE
);
2424 buf_size
= max(XPC_RP_VARS_SIZE
,
2425 XPC_RP_HEADER_SIZE
+ XP_NASID_MASK_BYTES_SN2
);
2426 xpc_remote_copy_buffer_sn2
= xpc_kmalloc_cacheline_aligned(buf_size
,
2428 &xpc_remote_copy_buffer_base_sn2
);
2429 if (xpc_remote_copy_buffer_sn2
== NULL
) {
2430 dev_err(xpc_part
, "can't get memory for remote copy buffer\n");
2434 /* open up protections for IPI and [potentially] amo operations */
2435 xpc_allow_IPI_ops_sn2();
2436 xpc_allow_amo_ops_shub_wars_1_1_sn2();
2439 * This is safe to do before the xpc_hb_checker thread has started
2440 * because the handler releases a wait queue. If an interrupt is
2441 * received before the thread is waiting, it will not go to sleep,
2442 * but rather immediately process the interrupt.
2444 ret
= request_irq(SGI_XPC_ACTIVATE
, xpc_handle_activate_IRQ_sn2
, 0,
2447 dev_err(xpc_part
, "can't register ACTIVATE IRQ handler, "
2448 "errno=%d\n", -ret
);
2449 xpc_disallow_IPI_ops_sn2();
2450 kfree(xpc_remote_copy_buffer_base_sn2
);
2458 free_irq(SGI_XPC_ACTIVATE
, NULL
);
2459 xpc_disallow_IPI_ops_sn2();
2460 kfree(xpc_remote_copy_buffer_base_sn2
);