[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / ia64 / sn / kernel / xpc.h
blob1a0aed8490d177a7830dbe17f11b22e976fdc945
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.
6 * Copyright (c) 2004-2005 Silicon Graphics, Inc. All Rights Reserved.
7 */
11 * Cross Partition Communication (XPC) structures and macros.
14 #ifndef _IA64_SN_KERNEL_XPC_H
15 #define _IA64_SN_KERNEL_XPC_H
18 #include <linux/config.h>
19 #include <linux/interrupt.h>
20 #include <linux/sysctl.h>
21 #include <linux/device.h>
22 #include <asm/pgtable.h>
23 #include <asm/processor.h>
24 #include <asm/sn/bte.h>
25 #include <asm/sn/clksupport.h>
26 #include <asm/sn/addrs.h>
27 #include <asm/sn/mspec.h>
28 #include <asm/sn/shub_mmr.h>
29 #include <asm/sn/xp.h>
33 * XPC Version numbers consist of a major and minor number. XPC can always
34 * talk to versions with same major #, and never talk to versions with a
35 * different major #.
37 #define _XPC_VERSION(_maj, _min) (((_maj) << 4) | ((_min) & 0xf))
38 #define XPC_VERSION_MAJOR(_v) ((_v) >> 4)
39 #define XPC_VERSION_MINOR(_v) ((_v) & 0xf)
43 * The next macros define word or bit representations for given
44 * C-brick nasid in either the SAL provided bit array representing
45 * nasids in the partition/machine or the AMO_t array used for
46 * inter-partition initiation communications.
48 * For SN2 machines, C-Bricks are alway even numbered NASIDs. As
49 * such, some space will be saved by insisting that nasid information
50 * passed from SAL always be packed for C-Bricks and the
51 * cross-partition interrupts use the same packing scheme.
53 #define XPC_NASID_W_INDEX(_n) (((_n) / 64) / 2)
54 #define XPC_NASID_B_INDEX(_n) (((_n) / 2) & (64 - 1))
55 #define XPC_NASID_IN_ARRAY(_n, _p) ((_p)[XPC_NASID_W_INDEX(_n)] & \
56 (1UL << XPC_NASID_B_INDEX(_n)))
57 #define XPC_NASID_FROM_W_B(_w, _b) (((_w) * 64 + (_b)) * 2)
59 #define XPC_HB_DEFAULT_INTERVAL 5 /* incr HB every x secs */
60 #define XPC_HB_CHECK_DEFAULT_TIMEOUT 20 /* check HB every x secs */
62 /* define the process name of HB checker and the CPU it is pinned to */
63 #define XPC_HB_CHECK_THREAD_NAME "xpc_hb"
64 #define XPC_HB_CHECK_CPU 0
66 /* define the process name of the discovery thread */
67 #define XPC_DISCOVERY_THREAD_NAME "xpc_discovery"
70 #define XPC_HB_ALLOWED(_p, _v) ((_v)->heartbeating_to_mask & (1UL << (_p)))
71 #define XPC_ALLOW_HB(_p, _v) (_v)->heartbeating_to_mask |= (1UL << (_p))
72 #define XPC_DISALLOW_HB(_p, _v) (_v)->heartbeating_to_mask &= (~(1UL << (_p)))
76 * Reserved Page provided by SAL.
78 * SAL provides one page per partition of reserved memory. When SAL
79 * initialization is complete, SAL_signature, SAL_version, partid,
80 * part_nasids, and mach_nasids are set.
82 * Note: Until vars_pa is set, the partition XPC code has not been initialized.
84 struct xpc_rsvd_page {
85 u64 SAL_signature; /* SAL unique signature */
86 u64 SAL_version; /* SAL specified version */
87 u8 partid; /* partition ID from SAL */
88 u8 version;
89 u8 pad[6]; /* pad to u64 align */
90 u64 vars_pa;
91 u64 part_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
92 u64 mach_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
94 #define XPC_RP_VERSION _XPC_VERSION(1,0) /* version 1.0 of the reserved page */
96 #define XPC_RSVD_PAGE_ALIGNED_SIZE \
97 (L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)))
101 * Define the structures by which XPC variables can be exported to other
102 * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
106 * The following structure describes the partition generic variables
107 * needed by other partitions in order to properly initialize.
109 * struct xpc_vars version number also applies to struct xpc_vars_part.
110 * Changes to either structure and/or related functionality should be
111 * reflected by incrementing either the major or minor version numbers
112 * of struct xpc_vars.
114 struct xpc_vars {
115 u8 version;
116 u64 heartbeat;
117 u64 heartbeating_to_mask;
118 u64 kdb_status; /* 0 = machine running */
119 int act_nasid;
120 int act_phys_cpuid;
121 u64 vars_part_pa;
122 u64 amos_page_pa; /* paddr of page of AMOs from MSPEC driver */
123 AMO_t *amos_page; /* vaddr of page of AMOs from MSPEC driver */
124 AMO_t *act_amos; /* pointer to the first activation AMO */
126 #define XPC_V_VERSION _XPC_VERSION(3,0) /* version 3.0 of the cross vars */
128 #define XPC_VARS_ALIGNED_SIZE (L1_CACHE_ALIGN(sizeof(struct xpc_vars)))
131 * The following structure describes the per partition specific variables.
133 * An array of these structures, one per partition, will be defined. As a
134 * partition becomes active XPC will copy the array entry corresponding to
135 * itself from that partition. It is desirable that the size of this
136 * structure evenly divide into a cacheline, such that none of the entries
137 * in this array crosses a cacheline boundary. As it is now, each entry
138 * occupies half a cacheline.
140 struct xpc_vars_part {
141 u64 magic;
143 u64 openclose_args_pa; /* physical address of open and close args */
144 u64 GPs_pa; /* physical address of Get/Put values */
146 u64 IPI_amo_pa; /* physical address of IPI AMO_t structure */
147 int IPI_nasid; /* nasid of where to send IPIs */
148 int IPI_phys_cpuid; /* physical CPU ID of where to send IPIs */
150 u8 nchannels; /* #of defined channels supported */
152 u8 reserved[23]; /* pad to a full 64 bytes */
156 * The vars_part MAGIC numbers play a part in the first contact protocol.
158 * MAGIC1 indicates that the per partition specific variables for a remote
159 * partition have been initialized by this partition.
161 * MAGIC2 indicates that this partition has pulled the remote partititions
162 * per partition variables that pertain to this partition.
164 #define XPC_VP_MAGIC1 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */
165 #define XPC_VP_MAGIC2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */
170 * Functions registered by add_timer() or called by kernel_thread() only
171 * allow for a single 64-bit argument. The following macros can be used to
172 * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
173 * the passed argument.
175 #define XPC_PACK_ARGS(_arg1, _arg2) \
176 ((((u64) _arg1) & 0xffffffff) | \
177 ((((u64) _arg2) & 0xffffffff) << 32))
179 #define XPC_UNPACK_ARG1(_args) (((u64) _args) & 0xffffffff)
180 #define XPC_UNPACK_ARG2(_args) ((((u64) _args) >> 32) & 0xffffffff)
185 * Define a Get/Put value pair (pointers) used with a message queue.
187 struct xpc_gp {
188 s64 get; /* Get value */
189 s64 put; /* Put value */
192 #define XPC_GP_SIZE \
193 L1_CACHE_ALIGN(sizeof(struct xpc_gp) * XPC_NCHANNELS)
198 * Define a structure that contains arguments associated with opening and
199 * closing a channel.
201 struct xpc_openclose_args {
202 u16 reason; /* reason why channel is closing */
203 u16 msg_size; /* sizeof each message entry */
204 u16 remote_nentries; /* #of message entries in remote msg queue */
205 u16 local_nentries; /* #of message entries in local msg queue */
206 u64 local_msgqueue_pa; /* physical address of local message queue */
209 #define XPC_OPENCLOSE_ARGS_SIZE \
210 L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * XPC_NCHANNELS)
214 /* struct xpc_msg flags */
216 #define XPC_M_DONE 0x01 /* msg has been received/consumed */
217 #define XPC_M_READY 0x02 /* msg is ready to be sent */
218 #define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */
221 #define XPC_MSG_ADDRESS(_payload) \
222 ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET))
227 * Defines notify entry.
229 * This is used to notify a message's sender that their message was received
230 * and consumed by the intended recipient.
232 struct xpc_notify {
233 struct semaphore sema; /* notify semaphore */
234 u8 type; /* type of notification */
236 /* the following two fields are only used if type == XPC_N_CALL */
237 xpc_notify_func func; /* user's notify function */
238 void *key; /* pointer to user's key */
241 /* struct xpc_notify type of notification */
243 #define XPC_N_CALL 0x01 /* notify function provided by user */
248 * Define the structure that manages all the stuff required by a channel. In
249 * particular, they are used to manage the messages sent across the channel.
251 * This structure is private to a partition, and is NOT shared across the
252 * partition boundary.
254 * There is an array of these structures for each remote partition. It is
255 * allocated at the time a partition becomes active. The array contains one
256 * of these structures for each potential channel connection to that partition.
258 * Each of these structures manages two message queues (circular buffers).
259 * They are allocated at the time a channel connection is made. One of
260 * these message queues (local_msgqueue) holds the locally created messages
261 * that are destined for the remote partition. The other of these message
262 * queues (remote_msgqueue) is a locally cached copy of the remote partition's
263 * own local_msgqueue.
265 * The following is a description of the Get/Put pointers used to manage these
266 * two message queues. Consider the local_msgqueue to be on one partition
267 * and the remote_msgqueue to be its cached copy on another partition. A
268 * description of what each of the lettered areas contains is included.
271 * local_msgqueue remote_msgqueue
273 * |/////////| |/////////|
274 * w_remote_GP.get --> +---------+ |/////////|
275 * | F | |/////////|
276 * remote_GP.get --> +---------+ +---------+ <-- local_GP->get
277 * | | | |
278 * | | | E |
279 * | | | |
280 * | | +---------+ <-- w_local_GP.get
281 * | B | |/////////|
282 * | | |////D////|
283 * | | |/////////|
284 * | | +---------+ <-- w_remote_GP.put
285 * | | |////C////|
286 * local_GP->put --> +---------+ +---------+ <-- remote_GP.put
287 * | | |/////////|
288 * | A | |/////////|
289 * | | |/////////|
290 * w_local_GP.put --> +---------+ |/////////|
291 * |/////////| |/////////|
294 * ( remote_GP.[get|put] are cached copies of the remote
295 * partition's local_GP->[get|put], and thus their values can
296 * lag behind their counterparts on the remote partition. )
299 * A - Messages that have been allocated, but have not yet been sent to the
300 * remote partition.
302 * B - Messages that have been sent, but have not yet been acknowledged by the
303 * remote partition as having been received.
305 * C - Area that needs to be prepared for the copying of sent messages, by
306 * the clearing of the message flags of any previously received messages.
308 * D - Area into which sent messages are to be copied from the remote
309 * partition's local_msgqueue and then delivered to their intended
310 * recipients. [ To allow for a multi-message copy, another pointer
311 * (next_msg_to_pull) has been added to keep track of the next message
312 * number needing to be copied (pulled). It chases after w_remote_GP.put.
313 * Any messages lying between w_local_GP.get and next_msg_to_pull have
314 * been copied and are ready to be delivered. ]
316 * E - Messages that have been copied and delivered, but have not yet been
317 * acknowledged by the recipient as having been received.
319 * F - Messages that have been acknowledged, but XPC has not yet notified the
320 * sender that the message was received by its intended recipient.
321 * This is also an area that needs to be prepared for the allocating of
322 * new messages, by the clearing of the message flags of the acknowledged
323 * messages.
325 struct xpc_channel {
326 partid_t partid; /* ID of remote partition connected */
327 spinlock_t lock; /* lock for updating this structure */
328 u32 flags; /* general flags */
330 enum xpc_retval reason; /* reason why channel is disconnect'g */
331 int reason_line; /* line# disconnect initiated from */
333 u16 number; /* channel # */
335 u16 msg_size; /* sizeof each msg entry */
336 u16 local_nentries; /* #of msg entries in local msg queue */
337 u16 remote_nentries; /* #of msg entries in remote msg queue*/
339 void *local_msgqueue_base; /* base address of kmalloc'd space */
340 struct xpc_msg *local_msgqueue; /* local message queue */
341 void *remote_msgqueue_base; /* base address of kmalloc'd space */
342 struct xpc_msg *remote_msgqueue;/* cached copy of remote partition's */
343 /* local message queue */
344 u64 remote_msgqueue_pa; /* phys addr of remote partition's */
345 /* local message queue */
347 atomic_t references; /* #of external references to queues */
349 atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
350 wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
352 /* queue of msg senders who want to be notified when msg received */
354 atomic_t n_to_notify; /* #of msg senders to notify */
355 struct xpc_notify *notify_queue;/* notify queue for messages sent */
357 xpc_channel_func func; /* user's channel function */
358 void *key; /* pointer to user's key */
360 struct semaphore msg_to_pull_sema; /* next msg to pull serialization */
361 struct semaphore teardown_sema; /* wait for teardown completion */
363 struct xpc_openclose_args *local_openclose_args; /* args passed on */
364 /* opening or closing of channel */
366 /* various flavors of local and remote Get/Put values */
368 struct xpc_gp *local_GP; /* local Get/Put values */
369 struct xpc_gp remote_GP; /* remote Get/Put values */
370 struct xpc_gp w_local_GP; /* working local Get/Put values */
371 struct xpc_gp w_remote_GP; /* working remote Get/Put values */
372 s64 next_msg_to_pull; /* Put value of next msg to pull */
374 /* kthread management related fields */
376 // >>> rethink having kthreads_assigned_limit and kthreads_idle_limit; perhaps
377 // >>> allow the assigned limit be unbounded and let the idle limit be dynamic
378 // >>> dependent on activity over the last interval of time
379 atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
380 u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
381 atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
382 u32 kthreads_idle_limit; /* limit on #of kthreads idle */
383 atomic_t kthreads_active; /* #of kthreads actively working */
384 // >>> following field is temporary
385 u32 kthreads_created; /* total #of kthreads created */
387 wait_queue_head_t idle_wq; /* idle kthread wait queue */
389 } ____cacheline_aligned;
392 /* struct xpc_channel flags */
394 #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
396 #define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */
397 #define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */
398 #define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */
399 #define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */
401 #define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */
402 #define XPC_C_CONNECTCALLOUT 0x00000040 /* channel connected callout made */
403 #define XPC_C_CONNECTED 0x00000080 /* local channel is connected */
404 #define XPC_C_CONNECTING 0x00000100 /* channel is being connected */
406 #define XPC_C_RCLOSEREPLY 0x00000200 /* remote close channel reply */
407 #define XPC_C_CLOSEREPLY 0x00000400 /* local close channel reply */
408 #define XPC_C_RCLOSEREQUEST 0x00000800 /* remote close channel request */
409 #define XPC_C_CLOSEREQUEST 0x00001000 /* local close channel request */
411 #define XPC_C_DISCONNECTED 0x00002000 /* channel is disconnected */
412 #define XPC_C_DISCONNECTING 0x00004000 /* channel is being disconnected */
417 * Manages channels on a partition basis. There is one of these structures
418 * for each partition (a partition will never utilize the structure that
419 * represents itself).
421 struct xpc_partition {
423 /* XPC HB infrastructure */
425 u64 remote_rp_pa; /* phys addr of partition's rsvd pg */
426 u64 remote_vars_pa; /* phys addr of partition's vars */
427 u64 remote_vars_part_pa; /* phys addr of partition's vars part */
428 u64 last_heartbeat; /* HB at last read */
429 u64 remote_amos_page_pa; /* phys addr of partition's amos page */
430 int remote_act_nasid; /* active part's act/deact nasid */
431 int remote_act_phys_cpuid; /* active part's act/deact phys cpuid */
432 u32 act_IRQ_rcvd; /* IRQs since activation */
433 spinlock_t act_lock; /* protect updating of act_state */
434 u8 act_state; /* from XPC HB viewpoint */
435 enum xpc_retval reason; /* reason partition is deactivating */
436 int reason_line; /* line# deactivation initiated from */
437 int reactivate_nasid; /* nasid in partition to reactivate */
440 /* XPC infrastructure referencing and teardown control */
442 u8 setup_state; /* infrastructure setup state */
443 wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
444 atomic_t references; /* #of references to infrastructure */
448 * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN
449 * XPC SETS UP THE NECESSARY INFRASTRUCTURE TO SUPPORT CROSS PARTITION
450 * COMMUNICATION. ALL OF THE FOLLOWING FIELDS WILL BE CLEARED. (THE
451 * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.)
455 u8 nchannels; /* #of defined channels supported */
456 atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
457 struct xpc_channel *channels;/* array of channel structures */
459 void *local_GPs_base; /* base address of kmalloc'd space */
460 struct xpc_gp *local_GPs; /* local Get/Put values */
461 void *remote_GPs_base; /* base address of kmalloc'd space */
462 struct xpc_gp *remote_GPs;/* copy of remote partition's local Get/Put */
463 /* values */
464 u64 remote_GPs_pa; /* phys address of remote partition's local */
465 /* Get/Put values */
468 /* fields used to pass args when opening or closing a channel */
470 void *local_openclose_args_base; /* base address of kmalloc'd space */
471 struct xpc_openclose_args *local_openclose_args; /* local's args */
472 void *remote_openclose_args_base; /* base address of kmalloc'd space */
473 struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
474 /* args */
475 u64 remote_openclose_args_pa; /* phys addr of remote's args */
478 /* IPI sending, receiving and handling related fields */
480 int remote_IPI_nasid; /* nasid of where to send IPIs */
481 int remote_IPI_phys_cpuid; /* phys CPU ID of where to send IPIs */
482 AMO_t *remote_IPI_amo_va; /* address of remote IPI AMO_t structure */
484 AMO_t *local_IPI_amo_va; /* address of IPI AMO_t structure */
485 u64 local_IPI_amo; /* IPI amo flags yet to be handled */
486 char IPI_owner[8]; /* IPI owner's name */
487 struct timer_list dropped_IPI_timer; /* dropped IPI timer */
489 spinlock_t IPI_lock; /* IPI handler lock */
492 /* channel manager related fields */
494 atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
495 wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
497 } ____cacheline_aligned;
500 /* struct xpc_partition act_state values (for XPC HB) */
502 #define XPC_P_INACTIVE 0x00 /* partition is not active */
503 #define XPC_P_ACTIVATION_REQ 0x01 /* created thread to activate */
504 #define XPC_P_ACTIVATING 0x02 /* activation thread started */
505 #define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */
506 #define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */
509 #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
510 xpc_deactivate_partition(__LINE__, (_p), (_reason))
513 /* struct xpc_partition setup_state values */
515 #define XPC_P_UNSET 0x00 /* infrastructure was never setup */
516 #define XPC_P_SETUP 0x01 /* infrastructure is setup */
517 #define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
518 #define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */
522 * struct xpc_partition IPI_timer #of seconds to wait before checking for
523 * dropped IPIs. These occur whenever an IPI amo write doesn't complete until
524 * after the IPI was received.
526 #define XPC_P_DROPPED_IPI_WAIT (0.25 * HZ)
529 #define XPC_PARTID(_p) ((partid_t) ((_p) - &xpc_partitions[0]))
533 /* found in xp_main.c */
534 extern struct xpc_registration xpc_registrations[];
537 /* >>> found in xpc_main.c only */
538 extern struct device *xpc_part;
539 extern struct device *xpc_chan;
540 extern irqreturn_t xpc_notify_IRQ_handler(int, void *, struct pt_regs *);
541 extern void xpc_dropped_IPI_check(struct xpc_partition *);
542 extern void xpc_activate_kthreads(struct xpc_channel *, int);
543 extern void xpc_create_kthreads(struct xpc_channel *, int);
544 extern void xpc_disconnect_wait(int);
547 /* found in xpc_main.c and efi-xpc.c */
548 extern void xpc_activate_partition(struct xpc_partition *);
551 /* found in xpc_partition.c */
552 extern int xpc_exiting;
553 extern int xpc_hb_interval;
554 extern int xpc_hb_check_interval;
555 extern struct xpc_vars *xpc_vars;
556 extern struct xpc_rsvd_page *xpc_rsvd_page;
557 extern struct xpc_vars_part *xpc_vars_part;
558 extern struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
559 extern char xpc_remote_copy_buffer[];
560 extern struct xpc_rsvd_page *xpc_rsvd_page_init(void);
561 extern void xpc_allow_IPI_ops(void);
562 extern void xpc_restrict_IPI_ops(void);
563 extern int xpc_identify_act_IRQ_sender(void);
564 extern enum xpc_retval xpc_mark_partition_active(struct xpc_partition *);
565 extern void xpc_mark_partition_inactive(struct xpc_partition *);
566 extern void xpc_discovery(void);
567 extern void xpc_check_remote_hb(void);
568 extern void xpc_deactivate_partition(const int, struct xpc_partition *,
569 enum xpc_retval);
570 extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *);
573 /* found in xpc_channel.c */
574 extern void xpc_initiate_connect(int);
575 extern void xpc_initiate_disconnect(int);
576 extern enum xpc_retval xpc_initiate_allocate(partid_t, int, u32, void **);
577 extern enum xpc_retval xpc_initiate_send(partid_t, int, void *);
578 extern enum xpc_retval xpc_initiate_send_notify(partid_t, int, void *,
579 xpc_notify_func, void *);
580 extern void xpc_initiate_received(partid_t, int, void *);
581 extern enum xpc_retval xpc_setup_infrastructure(struct xpc_partition *);
582 extern enum xpc_retval xpc_pull_remote_vars_part(struct xpc_partition *);
583 extern void xpc_process_channel_activity(struct xpc_partition *);
584 extern void xpc_connected_callout(struct xpc_channel *);
585 extern void xpc_deliver_msg(struct xpc_channel *);
586 extern void xpc_disconnect_channel(const int, struct xpc_channel *,
587 enum xpc_retval, unsigned long *);
588 extern void xpc_disconnected_callout(struct xpc_channel *);
589 extern void xpc_partition_down(struct xpc_partition *, enum xpc_retval);
590 extern void xpc_teardown_infrastructure(struct xpc_partition *);
594 static inline void
595 xpc_wakeup_channel_mgr(struct xpc_partition *part)
597 if (atomic_inc_return(&part->channel_mgr_requests) == 1) {
598 wake_up(&part->channel_mgr_wq);
605 * These next two inlines are used to keep us from tearing down a channel's
606 * msg queues while a thread may be referencing them.
608 static inline void
609 xpc_msgqueue_ref(struct xpc_channel *ch)
611 atomic_inc(&ch->references);
614 static inline void
615 xpc_msgqueue_deref(struct xpc_channel *ch)
617 s32 refs = atomic_dec_return(&ch->references);
619 DBUG_ON(refs < 0);
620 if (refs == 0) {
621 xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
627 #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
628 xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
632 * These two inlines are used to keep us from tearing down a partition's
633 * setup infrastructure while a thread may be referencing it.
635 static inline void
636 xpc_part_deref(struct xpc_partition *part)
638 s32 refs = atomic_dec_return(&part->references);
641 DBUG_ON(refs < 0);
642 if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN) {
643 wake_up(&part->teardown_wq);
647 static inline int
648 xpc_part_ref(struct xpc_partition *part)
650 int setup;
653 atomic_inc(&part->references);
654 setup = (part->setup_state == XPC_P_SETUP);
655 if (!setup) {
656 xpc_part_deref(part);
658 return setup;
664 * The following macro is to be used for the setting of the reason and
665 * reason_line fields in both the struct xpc_channel and struct xpc_partition
666 * structures.
668 #define XPC_SET_REASON(_p, _reason, _line) \
670 (_p)->reason = _reason; \
671 (_p)->reason_line = _line; \
677 * The following set of macros and inlines are used for the sending and
678 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
679 * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
680 * the other that is associated with channel activity (SGI_XPC_NOTIFY).
683 static inline u64
684 xpc_IPI_receive(AMO_t *amo)
686 return FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_CLEAR);
690 static inline enum xpc_retval
691 xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
693 int ret = 0;
694 unsigned long irq_flags;
697 local_irq_save(irq_flags);
699 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, flag);
700 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
703 * We must always use the nofault function regardless of whether we
704 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
705 * didn't, we'd never know that the other partition is down and would
706 * keep sending IPIs and AMOs to it until the heartbeat times out.
708 ret = xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
709 xp_nofault_PIOR_target));
711 local_irq_restore(irq_flags);
713 return ((ret == 0) ? xpcSuccess : xpcPioReadError);
718 * IPIs associated with SGI_XPC_ACTIVATE IRQ.
722 * Flag the appropriate AMO variable and send an IPI to the specified node.
724 static inline void
725 xpc_activate_IRQ_send(u64 amos_page, int from_nasid, int to_nasid,
726 int to_phys_cpuid)
728 int w_index = XPC_NASID_W_INDEX(from_nasid);
729 int b_index = XPC_NASID_B_INDEX(from_nasid);
730 AMO_t *amos = (AMO_t *) __va(amos_page +
731 (XP_MAX_PARTITIONS * sizeof(AMO_t)));
734 (void) xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
735 to_phys_cpuid, SGI_XPC_ACTIVATE);
738 static inline void
739 xpc_IPI_send_activate(struct xpc_vars *vars)
741 xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
742 vars->act_nasid, vars->act_phys_cpuid);
745 static inline void
746 xpc_IPI_send_activated(struct xpc_partition *part)
748 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
749 part->remote_act_nasid, part->remote_act_phys_cpuid);
752 static inline void
753 xpc_IPI_send_reactivate(struct xpc_partition *part)
755 xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
756 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
761 * IPIs associated with SGI_XPC_NOTIFY IRQ.
765 * Send an IPI to the remote partition that is associated with the
766 * specified channel.
768 #define XPC_NOTIFY_IRQ_SEND(_ch, _ipi_f, _irq_f) \
769 xpc_notify_IRQ_send(_ch, _ipi_f, #_ipi_f, _irq_f)
771 static inline void
772 xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
773 unsigned long *irq_flags)
775 struct xpc_partition *part = &xpc_partitions[ch->partid];
776 enum xpc_retval ret;
779 if (likely(part->act_state != XPC_P_DEACTIVATING)) {
780 ret = xpc_IPI_send(part->remote_IPI_amo_va,
781 (u64) ipi_flag << (ch->number * 8),
782 part->remote_IPI_nasid,
783 part->remote_IPI_phys_cpuid,
784 SGI_XPC_NOTIFY);
785 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
786 ipi_flag_string, ch->partid, ch->number, ret);
787 if (unlikely(ret != xpcSuccess)) {
788 if (irq_flags != NULL) {
789 spin_unlock_irqrestore(&ch->lock, *irq_flags);
791 XPC_DEACTIVATE_PARTITION(part, ret);
792 if (irq_flags != NULL) {
793 spin_lock_irqsave(&ch->lock, *irq_flags);
801 * Make it look like the remote partition, which is associated with the
802 * specified channel, sent us an IPI. This faked IPI will be handled
803 * by xpc_dropped_IPI_check().
805 #define XPC_NOTIFY_IRQ_SEND_LOCAL(_ch, _ipi_f) \
806 xpc_notify_IRQ_send_local(_ch, _ipi_f, #_ipi_f)
808 static inline void
809 xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
810 char *ipi_flag_string)
812 struct xpc_partition *part = &xpc_partitions[ch->partid];
815 FETCHOP_STORE_OP(TO_AMO((u64) &part->local_IPI_amo_va->variable),
816 FETCHOP_OR, ((u64) ipi_flag << (ch->number * 8)));
817 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
818 ipi_flag_string, ch->partid, ch->number);
823 * The sending and receiving of IPIs includes the setting of an AMO variable
824 * to indicate the reason the IPI was sent. The 64-bit variable is divided
825 * up into eight bytes, ordered from right to left. Byte zero pertains to
826 * channel 0, byte one to channel 1, and so on. Each byte is described by
827 * the following IPI flags.
830 #define XPC_IPI_CLOSEREQUEST 0x01
831 #define XPC_IPI_CLOSEREPLY 0x02
832 #define XPC_IPI_OPENREQUEST 0x04
833 #define XPC_IPI_OPENREPLY 0x08
834 #define XPC_IPI_MSGREQUEST 0x10
837 /* given an AMO variable and a channel#, get its associated IPI flags */
838 #define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
840 #define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0f)
841 #define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010)
844 static inline void
845 xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
847 struct xpc_openclose_args *args = ch->local_openclose_args;
850 args->reason = ch->reason;
852 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
855 static inline void
856 xpc_IPI_send_closereply(struct xpc_channel *ch, unsigned long *irq_flags)
858 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREPLY, irq_flags);
861 static inline void
862 xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
864 struct xpc_openclose_args *args = ch->local_openclose_args;
867 args->msg_size = ch->msg_size;
868 args->local_nentries = ch->local_nentries;
870 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREQUEST, irq_flags);
873 static inline void
874 xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
876 struct xpc_openclose_args *args = ch->local_openclose_args;
879 args->remote_nentries = ch->remote_nentries;
880 args->local_nentries = ch->local_nentries;
881 args->local_msgqueue_pa = __pa(ch->local_msgqueue);
883 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREPLY, irq_flags);
886 static inline void
887 xpc_IPI_send_msgrequest(struct xpc_channel *ch)
889 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_MSGREQUEST, NULL);
892 static inline void
893 xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
895 XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
900 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
901 * pages are located in the lowest granule. The lowest granule uses 4k pages
902 * for cached references and an alternate TLB handler to never provide a
903 * cacheable mapping for the entire region. This will prevent speculative
904 * reading of cached copies of our lines from being issued which will cause
905 * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
906 * (XP_MAX_PARTITIONS) AMO variables for message notification (xpc_main.c)
907 * and an additional 16 AMO variables for partition activation (xpc_hb.c).
909 static inline AMO_t *
910 xpc_IPI_init(partid_t partid)
912 AMO_t *part_amo = xpc_vars->amos_page + partid;
915 xpc_IPI_receive(part_amo);
916 return part_amo;
921 static inline enum xpc_retval
922 xpc_map_bte_errors(bte_result_t error)
924 switch (error) {
925 case BTE_SUCCESS: return xpcSuccess;
926 case BTEFAIL_DIR: return xpcBteDirectoryError;
927 case BTEFAIL_POISON: return xpcBtePoisonError;
928 case BTEFAIL_WERR: return xpcBteWriteError;
929 case BTEFAIL_ACCESS: return xpcBteAccessError;
930 case BTEFAIL_PWERR: return xpcBtePWriteError;
931 case BTEFAIL_PRERR: return xpcBtePReadError;
932 case BTEFAIL_TOUT: return xpcBteTimeOutError;
933 case BTEFAIL_XTERR: return xpcBteXtalkError;
934 case BTEFAIL_NOTAVAIL: return xpcBteNotAvailable;
935 default: return xpcBteUnmappedError;
941 static inline void *
942 xpc_kmalloc_cacheline_aligned(size_t size, int flags, void **base)
944 /* see if kmalloc will give us cachline aligned memory by default */
945 *base = kmalloc(size, flags);
946 if (*base == NULL) {
947 return NULL;
949 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
950 return *base;
952 kfree(*base);
954 /* nope, we'll have to do it ourselves */
955 *base = kmalloc(size + L1_CACHE_BYTES, flags);
956 if (*base == NULL) {
957 return NULL;
959 return (void *) L1_CACHE_ALIGN((u64) *base);
964 * Check to see if there is any channel activity to/from the specified
965 * partition.
967 static inline void
968 xpc_check_for_channel_activity(struct xpc_partition *part)
970 u64 IPI_amo;
971 unsigned long irq_flags;
974 IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
975 if (IPI_amo == 0) {
976 return;
979 spin_lock_irqsave(&part->IPI_lock, irq_flags);
980 part->local_IPI_amo |= IPI_amo;
981 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
983 dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
984 XPC_PARTID(part), IPI_amo);
986 xpc_wakeup_channel_mgr(part);
990 #endif /* _IA64_SN_KERNEL_XPC_H */