[IA64-SGI] get XPC to cleanly disengage from remote memory references
[pandora-kernel.git] / arch / ia64 / sn / kernel / xpc.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (c) 2004-2005 Silicon Graphics, Inc.  All Rights Reserved.
7  */
8
9
10 /*
11  * Cross Partition Communication (XPC) structures and macros.
12  */
13
14 #ifndef _IA64_SN_KERNEL_XPC_H
15 #define _IA64_SN_KERNEL_XPC_H
16
17
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>
30
31
32 /*
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 #.
36  */
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)
40
41
42 /*
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.
47  *
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.
52  */
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)
58
59 #define XPC_HB_DEFAULT_INTERVAL         5       /* incr HB every x secs */
60 #define XPC_HB_CHECK_DEFAULT_INTERVAL   20      /* check HB every x secs */
61
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
65
66 /* define the process name of the discovery thread */
67 #define XPC_DISCOVERY_THREAD_NAME       "xpc_discovery"
68
69
70 /*
71  * Reserved Page provided by SAL.
72  *
73  * SAL provides one page per partition of reserved memory.  When SAL
74  * initialization is complete, SAL_signature, SAL_version, partid,
75  * part_nasids, and mach_nasids are set.
76  *
77  * Note: Until vars_pa is set, the partition XPC code has not been initialized.
78  */
79 struct xpc_rsvd_page {
80         u64 SAL_signature;      /* SAL unique signature */
81         u64 SAL_version;        /* SAL specified version */
82         u8 partid;              /* partition ID from SAL */
83         u8 version;
84         u8 pad[6];              /* pad to u64 align */
85         volatile u64 vars_pa;
86         struct timespec stamp;  /* time when reserved page was initialized */
87         u64 part_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
88         u64 mach_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
89 };
90
91 #define XPC_RSVD_PAGE_ALIGNED_SIZE \
92                         (L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)))
93
94 #define XPC_RP_VERSION _XPC_VERSION(1,1) /* version 1.1 of the reserved page */
95
96 #define XPC_SUPPORTS_RP_STAMP(_version) \
97                         (_version >= _XPC_VERSION(1,1))
98
99 /*
100  * compare stamps - the return value is:
101  *
102  *      < 0,    if stamp1 < stamp2
103  *      = 0,    if stamp1 == stamp2
104  *      > 0,    if stamp1 > stamp2
105  */
106 static inline int
107 xpc_compare_stamps(struct timespec *stamp1, struct timespec *stamp2)
108 {
109         int ret;
110
111
112         if ((ret = stamp1->tv_sec - stamp2->tv_sec) == 0) {
113                 ret = stamp1->tv_nsec - stamp2->tv_nsec;
114         }
115         return ret;
116 }
117
118
119 /*
120  * Define the structures by which XPC variables can be exported to other
121  * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
122  */
123
124 /*
125  * The following structure describes the partition generic variables
126  * needed by other partitions in order to properly initialize.
127  *
128  * struct xpc_vars version number also applies to struct xpc_vars_part.
129  * Changes to either structure and/or related functionality should be
130  * reflected by incrementing either the major or minor version numbers
131  * of struct xpc_vars.
132  */
133 struct xpc_vars {
134         u8 version;
135         u64 heartbeat;
136         u64 heartbeating_to_mask;
137         u64 kdb_status;         /* 0 = machine running */
138         int act_nasid;
139         int act_phys_cpuid;
140         u64 vars_part_pa;
141         u64 amos_page_pa;       /* paddr of page of AMOs from MSPEC driver */
142         AMO_t *amos_page;       /* vaddr of page of AMOs from MSPEC driver */
143 };
144
145 #define XPC_VARS_ALIGNED_SIZE  (L1_CACHE_ALIGN(sizeof(struct xpc_vars)))
146
147 #define XPC_V_VERSION _XPC_VERSION(3,1) /* version 3.1 of the cross vars */
148
149 #define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \
150                         (_version >= _XPC_VERSION(3,1))
151
152
153 static inline int
154 xpc_hb_allowed(partid_t partid, struct xpc_vars *vars)
155 {
156         return ((vars->heartbeating_to_mask & (1UL << partid)) != 0);
157 }
158
159 static inline void
160 xpc_allow_hb(partid_t partid, struct xpc_vars *vars)
161 {
162         u64 old_mask, new_mask;
163
164         do {
165                 old_mask = vars->heartbeating_to_mask;
166                 new_mask = (old_mask | (1UL << partid));
167         } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
168                                                         old_mask);
169 }
170
171 static inline void
172 xpc_disallow_hb(partid_t partid, struct xpc_vars *vars)
173 {
174         u64 old_mask, new_mask;
175
176         do {
177                 old_mask = vars->heartbeating_to_mask;
178                 new_mask = (old_mask & ~(1UL << partid));
179         } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
180                                                         old_mask);
181 }
182
183
184 /*
185  * The AMOs page consists of a number of AMO variables which are divided into
186  * four groups, The first two groups are used to identify an IRQ's sender.
187  * These two groups consist of 64 and 16 AMO variables respectively. The last
188  * two groups, consisting of just one AMO variable each, are used to identify
189  * the remote partitions that are currently engaged (from the viewpoint of
190  * the XPC running on the remote partition).
191  */
192 #define XPC_NOTIFY_IRQ_AMOS        0
193 #define XPC_ACTIVATE_IRQ_AMOS      (XPC_NOTIFY_IRQ_AMOS + XP_MAX_PARTITIONS)
194 #define XPC_ENGAGED_PARTITIONS_AMO (XPC_ACTIVATE_IRQ_AMOS + XP_NASID_MASK_WORDS)
195 #define XPC_DISENGAGE_REQUEST_AMO  (XPC_ENGAGED_PARTITIONS_AMO + 1)
196
197
198 /*
199  * The following structure describes the per partition specific variables.
200  *
201  * An array of these structures, one per partition, will be defined. As a
202  * partition becomes active XPC will copy the array entry corresponding to
203  * itself from that partition. It is desirable that the size of this
204  * structure evenly divide into a cacheline, such that none of the entries
205  * in this array crosses a cacheline boundary. As it is now, each entry
206  * occupies half a cacheline.
207  */
208 struct xpc_vars_part {
209         volatile u64 magic;
210
211         u64 openclose_args_pa;  /* physical address of open and close args */
212         u64 GPs_pa;             /* physical address of Get/Put values */
213
214         u64 IPI_amo_pa;         /* physical address of IPI AMO_t structure */
215         int IPI_nasid;          /* nasid of where to send IPIs */
216         int IPI_phys_cpuid;     /* physical CPU ID of where to send IPIs */
217
218         u8 nchannels;           /* #of defined channels supported */
219
220         u8 reserved[23];        /* pad to a full 64 bytes */
221 };
222
223 /*
224  * The vars_part MAGIC numbers play a part in the first contact protocol.
225  *
226  * MAGIC1 indicates that the per partition specific variables for a remote
227  * partition have been initialized by this partition.
228  *
229  * MAGIC2 indicates that this partition has pulled the remote partititions
230  * per partition variables that pertain to this partition.
231  */
232 #define XPC_VP_MAGIC1   0x0053524156435058L  /* 'XPCVARS\0'L (little endian) */
233 #define XPC_VP_MAGIC2   0x0073726176435058L  /* 'XPCvars\0'L (little endian) */
234
235
236
237 /*
238  * Functions registered by add_timer() or called by kernel_thread() only
239  * allow for a single 64-bit argument. The following macros can be used to
240  * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
241  * the passed argument.
242  */
243 #define XPC_PACK_ARGS(_arg1, _arg2) \
244                         ((((u64) _arg1) & 0xffffffff) | \
245                         ((((u64) _arg2) & 0xffffffff) << 32))
246
247 #define XPC_UNPACK_ARG1(_args)  (((u64) _args) & 0xffffffff)
248 #define XPC_UNPACK_ARG2(_args)  ((((u64) _args) >> 32) & 0xffffffff)
249
250
251
252 /*
253  * Define a Get/Put value pair (pointers) used with a message queue.
254  */
255 struct xpc_gp {
256         volatile s64 get;       /* Get value */
257         volatile s64 put;       /* Put value */
258 };
259
260 #define XPC_GP_SIZE \
261                 L1_CACHE_ALIGN(sizeof(struct xpc_gp) * XPC_NCHANNELS)
262
263
264
265 /*
266  * Define a structure that contains arguments associated with opening and
267  * closing a channel.
268  */
269 struct xpc_openclose_args {
270         u16 reason;             /* reason why channel is closing */
271         u16 msg_size;           /* sizeof each message entry */
272         u16 remote_nentries;    /* #of message entries in remote msg queue */
273         u16 local_nentries;     /* #of message entries in local msg queue */
274         u64 local_msgqueue_pa;  /* physical address of local message queue */
275 };
276
277 #define XPC_OPENCLOSE_ARGS_SIZE \
278               L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * XPC_NCHANNELS)
279
280
281
282 /* struct xpc_msg flags */
283
284 #define XPC_M_DONE              0x01    /* msg has been received/consumed */
285 #define XPC_M_READY             0x02    /* msg is ready to be sent */
286 #define XPC_M_INTERRUPT         0x04    /* send interrupt when msg consumed */
287
288
289 #define XPC_MSG_ADDRESS(_payload) \
290                 ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET))
291
292
293
294 /*
295  * Defines notify entry.
296  *
297  * This is used to notify a message's sender that their message was received
298  * and consumed by the intended recipient.
299  */
300 struct xpc_notify {
301         struct semaphore sema;          /* notify semaphore */
302         volatile u8 type;                       /* type of notification */
303
304         /* the following two fields are only used if type == XPC_N_CALL */
305         xpc_notify_func func;           /* user's notify function */
306         void *key;                      /* pointer to user's key */
307 };
308
309 /* struct xpc_notify type of notification */
310
311 #define XPC_N_CALL              0x01    /* notify function provided by user */
312
313
314
315 /*
316  * Define the structure that manages all the stuff required by a channel. In
317  * particular, they are used to manage the messages sent across the channel.
318  *
319  * This structure is private to a partition, and is NOT shared across the
320  * partition boundary.
321  *
322  * There is an array of these structures for each remote partition. It is
323  * allocated at the time a partition becomes active. The array contains one
324  * of these structures for each potential channel connection to that partition.
325  *
326  * Each of these structures manages two message queues (circular buffers).
327  * They are allocated at the time a channel connection is made. One of
328  * these message queues (local_msgqueue) holds the locally created messages
329  * that are destined for the remote partition. The other of these message
330  * queues (remote_msgqueue) is a locally cached copy of the remote partition's
331  * own local_msgqueue.
332  *
333  * The following is a description of the Get/Put pointers used to manage these
334  * two message queues. Consider the local_msgqueue to be on one partition
335  * and the remote_msgqueue to be its cached copy on another partition. A
336  * description of what each of the lettered areas contains is included.
337  *
338  *
339  *                     local_msgqueue      remote_msgqueue
340  *
341  *                        |/////////|      |/////////|
342  *    w_remote_GP.get --> +---------+      |/////////|
343  *                        |    F    |      |/////////|
344  *     remote_GP.get  --> +---------+      +---------+ <-- local_GP->get
345  *                        |         |      |         |
346  *                        |         |      |    E    |
347  *                        |         |      |         |
348  *                        |         |      +---------+ <-- w_local_GP.get
349  *                        |    B    |      |/////////|
350  *                        |         |      |////D////|
351  *                        |         |      |/////////|
352  *                        |         |      +---------+ <-- w_remote_GP.put
353  *                        |         |      |////C////|
354  *      local_GP->put --> +---------+      +---------+ <-- remote_GP.put
355  *                        |         |      |/////////|
356  *                        |    A    |      |/////////|
357  *                        |         |      |/////////|
358  *     w_local_GP.put --> +---------+      |/////////|
359  *                        |/////////|      |/////////|
360  *
361  *
362  *          ( remote_GP.[get|put] are cached copies of the remote
363  *            partition's local_GP->[get|put], and thus their values can
364  *            lag behind their counterparts on the remote partition. )
365  *
366  *
367  *  A - Messages that have been allocated, but have not yet been sent to the
368  *      remote partition.
369  *
370  *  B - Messages that have been sent, but have not yet been acknowledged by the
371  *      remote partition as having been received.
372  *
373  *  C - Area that needs to be prepared for the copying of sent messages, by
374  *      the clearing of the message flags of any previously received messages.
375  *
376  *  D - Area into which sent messages are to be copied from the remote
377  *      partition's local_msgqueue and then delivered to their intended
378  *      recipients. [ To allow for a multi-message copy, another pointer
379  *      (next_msg_to_pull) has been added to keep track of the next message
380  *      number needing to be copied (pulled). It chases after w_remote_GP.put.
381  *      Any messages lying between w_local_GP.get and next_msg_to_pull have
382  *      been copied and are ready to be delivered. ]
383  *
384  *  E - Messages that have been copied and delivered, but have not yet been
385  *      acknowledged by the recipient as having been received.
386  *
387  *  F - Messages that have been acknowledged, but XPC has not yet notified the
388  *      sender that the message was received by its intended recipient.
389  *      This is also an area that needs to be prepared for the allocating of
390  *      new messages, by the clearing of the message flags of the acknowledged
391  *      messages.
392  */
393 struct xpc_channel {
394         partid_t partid;                /* ID of remote partition connected */
395         spinlock_t lock;                /* lock for updating this structure */
396         u32 flags;                      /* general flags */
397
398         enum xpc_retval reason;         /* reason why channel is disconnect'g */
399         int reason_line;                /* line# disconnect initiated from */
400
401         u16 number;                     /* channel # */
402
403         u16 msg_size;                   /* sizeof each msg entry */
404         u16 local_nentries;             /* #of msg entries in local msg queue */
405         u16 remote_nentries;            /* #of msg entries in remote msg queue*/
406
407         void *local_msgqueue_base;      /* base address of kmalloc'd space */
408         struct xpc_msg *local_msgqueue; /* local message queue */
409         void *remote_msgqueue_base;     /* base address of kmalloc'd space */
410         struct xpc_msg *remote_msgqueue;/* cached copy of remote partition's */
411                                         /* local message queue */
412         u64 remote_msgqueue_pa;         /* phys addr of remote partition's */
413                                         /* local message queue */
414
415         atomic_t references;            /* #of external references to queues */
416
417         atomic_t n_on_msg_allocate_wq;   /* #on msg allocation wait queue */
418         wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
419
420         /* queue of msg senders who want to be notified when msg received */
421
422         atomic_t n_to_notify;           /* #of msg senders to notify */
423         struct xpc_notify *notify_queue;/* notify queue for messages sent */
424
425         xpc_channel_func func;          /* user's channel function */
426         void *key;                      /* pointer to user's key */
427
428         struct semaphore msg_to_pull_sema; /* next msg to pull serialization */
429         struct semaphore wdisconnect_sema; /* wait for channel disconnect */
430
431         struct xpc_openclose_args *local_openclose_args; /* args passed on */
432                                         /* opening or closing of channel */
433
434         /* various flavors of local and remote Get/Put values */
435
436         struct xpc_gp *local_GP;        /* local Get/Put values */
437         struct xpc_gp remote_GP;        /* remote Get/Put values */
438         struct xpc_gp w_local_GP;       /* working local Get/Put values */
439         struct xpc_gp w_remote_GP;      /* working remote Get/Put values */
440         s64 next_msg_to_pull;           /* Put value of next msg to pull */
441
442         /* kthread management related fields */
443
444 // >>> rethink having kthreads_assigned_limit and kthreads_idle_limit; perhaps
445 // >>> allow the assigned limit be unbounded and let the idle limit be dynamic
446 // >>> dependent on activity over the last interval of time
447         atomic_t kthreads_assigned;     /* #of kthreads assigned to channel */
448         u32 kthreads_assigned_limit;    /* limit on #of kthreads assigned */
449         atomic_t kthreads_idle;         /* #of kthreads idle waiting for work */
450         u32 kthreads_idle_limit;        /* limit on #of kthreads idle */
451         atomic_t kthreads_active;       /* #of kthreads actively working */
452         // >>> following field is temporary
453         u32 kthreads_created;           /* total #of kthreads created */
454
455         wait_queue_head_t idle_wq;      /* idle kthread wait queue */
456
457 } ____cacheline_aligned;
458
459
460 /* struct xpc_channel flags */
461
462 #define XPC_C_WASCONNECTED      0x00000001 /* channel was connected */
463
464 #define XPC_C_ROPENREPLY        0x00000002 /* remote open channel reply */
465 #define XPC_C_OPENREPLY         0x00000004 /* local open channel reply */
466 #define XPC_C_ROPENREQUEST      0x00000008 /* remote open channel request */
467 #define XPC_C_OPENREQUEST       0x00000010 /* local open channel request */
468
469 #define XPC_C_SETUP             0x00000020 /* channel's msgqueues are alloc'd */
470 #define XPC_C_CONNECTCALLOUT    0x00000040 /* channel connected callout made */
471 #define XPC_C_CONNECTED         0x00000080 /* local channel is connected */
472 #define XPC_C_CONNECTING        0x00000100 /* channel is being connected */
473
474 #define XPC_C_RCLOSEREPLY       0x00000200 /* remote close channel reply */
475 #define XPC_C_CLOSEREPLY        0x00000400 /* local close channel reply */
476 #define XPC_C_RCLOSEREQUEST     0x00000800 /* remote close channel request */
477 #define XPC_C_CLOSEREQUEST      0x00001000 /* local close channel request */
478
479 #define XPC_C_DISCONNECTED      0x00002000 /* channel is disconnected */
480 #define XPC_C_DISCONNECTING     0x00004000 /* channel is being disconnected */
481 #define XPC_C_WDISCONNECT       0x00008000 /* waiting for channel disconnect */
482
483
484
485 /*
486  * Manages channels on a partition basis. There is one of these structures
487  * for each partition (a partition will never utilize the structure that
488  * represents itself).
489  */
490 struct xpc_partition {
491
492         /* XPC HB infrastructure */
493
494         u8 remote_rp_version;           /* version# of partition's rsvd pg */
495         struct timespec remote_rp_stamp;/* time when rsvd pg was initialized */
496         u64 remote_rp_pa;               /* phys addr of partition's rsvd pg */
497         u64 remote_vars_pa;             /* phys addr of partition's vars */
498         u64 remote_vars_part_pa;        /* phys addr of partition's vars part */
499         u64 last_heartbeat;             /* HB at last read */
500         u64 remote_amos_page_pa;        /* phys addr of partition's amos page */
501         int remote_act_nasid;           /* active part's act/deact nasid */
502         int remote_act_phys_cpuid;      /* active part's act/deact phys cpuid */
503         u32 act_IRQ_rcvd;               /* IRQs since activation */
504         spinlock_t act_lock;            /* protect updating of act_state */
505         u8 act_state;                   /* from XPC HB viewpoint */
506         u8 remote_vars_version;         /* version# of partition's vars */
507         enum xpc_retval reason;         /* reason partition is deactivating */
508         int reason_line;                /* line# deactivation initiated from */
509         int reactivate_nasid;           /* nasid in partition to reactivate */
510
511         unsigned long disengage_request_timeout; /* timeout in XPC_TICKS */
512         struct timer_list disengage_request_timer;
513
514
515         /* XPC infrastructure referencing and teardown control */
516
517         volatile u8 setup_state;                        /* infrastructure setup state */
518         wait_queue_head_t teardown_wq;  /* kthread waiting to teardown infra */
519         atomic_t references;            /* #of references to infrastructure */
520
521
522         /*
523          * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN
524          * XPC SETS UP THE NECESSARY INFRASTRUCTURE TO SUPPORT CROSS PARTITION
525          * COMMUNICATION. ALL OF THE FOLLOWING FIELDS WILL BE CLEARED. (THE
526          * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.)
527          */
528
529
530         u8 nchannels;              /* #of defined channels supported */
531         atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
532         atomic_t nchannels_engaged;/* #of channels engaged with remote part */
533         struct xpc_channel *channels;/* array of channel structures */
534
535         void *local_GPs_base;     /* base address of kmalloc'd space */
536         struct xpc_gp *local_GPs; /* local Get/Put values */
537         void *remote_GPs_base;    /* base address of kmalloc'd space */
538         struct xpc_gp *remote_GPs;/* copy of remote partition's local Get/Put */
539                                   /* values */
540         u64 remote_GPs_pa;        /* phys address of remote partition's local */
541                                   /* Get/Put values */
542
543
544         /* fields used to pass args when opening or closing a channel */
545
546         void *local_openclose_args_base;  /* base address of kmalloc'd space */
547         struct xpc_openclose_args *local_openclose_args;  /* local's args */
548         void *remote_openclose_args_base; /* base address of kmalloc'd space */
549         struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
550                                           /* args */
551         u64 remote_openclose_args_pa;     /* phys addr of remote's args */
552
553
554         /* IPI sending, receiving and handling related fields */
555
556         int remote_IPI_nasid;       /* nasid of where to send IPIs */
557         int remote_IPI_phys_cpuid;  /* phys CPU ID of where to send IPIs */
558         AMO_t *remote_IPI_amo_va;   /* address of remote IPI AMO_t structure */
559
560         AMO_t *local_IPI_amo_va;    /* address of IPI AMO_t structure */
561         u64 local_IPI_amo;          /* IPI amo flags yet to be handled */
562         char IPI_owner[8];          /* IPI owner's name */
563         struct timer_list dropped_IPI_timer; /* dropped IPI timer */
564
565         spinlock_t IPI_lock;        /* IPI handler lock */
566
567
568         /* channel manager related fields */
569
570         atomic_t channel_mgr_requests;  /* #of requests to activate chan mgr */
571         wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
572
573 } ____cacheline_aligned;
574
575
576 /* struct xpc_partition act_state values (for XPC HB) */
577
578 #define XPC_P_INACTIVE          0x00    /* partition is not active */
579 #define XPC_P_ACTIVATION_REQ    0x01    /* created thread to activate */
580 #define XPC_P_ACTIVATING        0x02    /* activation thread started */
581 #define XPC_P_ACTIVE            0x03    /* xpc_partition_up() was called */
582 #define XPC_P_DEACTIVATING      0x04    /* partition deactivation initiated */
583
584
585 #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
586                         xpc_deactivate_partition(__LINE__, (_p), (_reason))
587
588
589 /* struct xpc_partition setup_state values */
590
591 #define XPC_P_UNSET             0x00    /* infrastructure was never setup */
592 #define XPC_P_SETUP             0x01    /* infrastructure is setup */
593 #define XPC_P_WTEARDOWN         0x02    /* waiting to teardown infrastructure */
594 #define XPC_P_TORNDOWN          0x03    /* infrastructure is torndown */
595
596
597
598 /*
599  * struct xpc_partition IPI_timer #of seconds to wait before checking for
600  * dropped IPIs. These occur whenever an IPI amo write doesn't complete until
601  * after the IPI was received.
602  */
603 #define XPC_P_DROPPED_IPI_WAIT  (0.25 * HZ)
604
605
606 /* number of seconds to wait for other partitions to disengage */
607 #define XPC_DISENGAGE_REQUEST_TIMELIMIT 90
608
609 /* interval in seconds to print 'waiting disengagement' messages */
610 #define XPC_DISENGAGE_PRINTMSG_INTERVAL         10
611
612
613 #define XPC_PARTID(_p)  ((partid_t) ((_p) - &xpc_partitions[0]))
614
615
616
617 /* found in xp_main.c */
618 extern struct xpc_registration xpc_registrations[];
619
620
621 /* >>> found in xpc_main.c only */
622 extern struct device *xpc_part;
623 extern struct device *xpc_chan;
624 extern irqreturn_t xpc_notify_IRQ_handler(int, void *, struct pt_regs *);
625 extern void xpc_dropped_IPI_check(struct xpc_partition *);
626 extern void xpc_activate_kthreads(struct xpc_channel *, int);
627 extern void xpc_create_kthreads(struct xpc_channel *, int);
628 extern void xpc_disconnect_wait(int);
629
630
631 /* found in xpc_main.c and efi-xpc.c */
632 extern void xpc_activate_partition(struct xpc_partition *);
633
634
635 /* found in xpc_partition.c */
636 extern int xpc_exiting;
637 extern struct xpc_vars *xpc_vars;
638 extern struct xpc_rsvd_page *xpc_rsvd_page;
639 extern struct xpc_vars_part *xpc_vars_part;
640 extern struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
641 extern char xpc_remote_copy_buffer[];
642 extern struct xpc_rsvd_page *xpc_rsvd_page_init(void);
643 extern void xpc_allow_IPI_ops(void);
644 extern void xpc_restrict_IPI_ops(void);
645 extern int xpc_identify_act_IRQ_sender(void);
646 extern int xpc_partition_disengaged(struct xpc_partition *);
647 extern enum xpc_retval xpc_mark_partition_active(struct xpc_partition *);
648 extern void xpc_mark_partition_inactive(struct xpc_partition *);
649 extern void xpc_discovery(void);
650 extern void xpc_check_remote_hb(void);
651 extern void xpc_deactivate_partition(const int, struct xpc_partition *,
652                                                 enum xpc_retval);
653 extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *);
654
655
656 /* found in xpc_channel.c */
657 extern void xpc_initiate_connect(int);
658 extern void xpc_initiate_disconnect(int);
659 extern enum xpc_retval xpc_initiate_allocate(partid_t, int, u32, void **);
660 extern enum xpc_retval xpc_initiate_send(partid_t, int, void *);
661 extern enum xpc_retval xpc_initiate_send_notify(partid_t, int, void *,
662                                                 xpc_notify_func, void *);
663 extern void xpc_initiate_received(partid_t, int, void *);
664 extern enum xpc_retval xpc_setup_infrastructure(struct xpc_partition *);
665 extern enum xpc_retval xpc_pull_remote_vars_part(struct xpc_partition *);
666 extern void xpc_process_channel_activity(struct xpc_partition *);
667 extern void xpc_connected_callout(struct xpc_channel *);
668 extern void xpc_deliver_msg(struct xpc_channel *);
669 extern void xpc_disconnect_channel(const int, struct xpc_channel *,
670                                         enum xpc_retval, unsigned long *);
671 extern void xpc_disconnecting_callout(struct xpc_channel *);
672 extern void xpc_partition_going_down(struct xpc_partition *, enum xpc_retval);
673 extern void xpc_teardown_infrastructure(struct xpc_partition *);
674
675
676
677 static inline void
678 xpc_wakeup_channel_mgr(struct xpc_partition *part)
679 {
680         if (atomic_inc_return(&part->channel_mgr_requests) == 1) {
681                 wake_up(&part->channel_mgr_wq);
682         }
683 }
684
685
686
687 /*
688  * These next two inlines are used to keep us from tearing down a channel's
689  * msg queues while a thread may be referencing them.
690  */
691 static inline void
692 xpc_msgqueue_ref(struct xpc_channel *ch)
693 {
694         atomic_inc(&ch->references);
695 }
696
697 static inline void
698 xpc_msgqueue_deref(struct xpc_channel *ch)
699 {
700         s32 refs = atomic_dec_return(&ch->references);
701
702         DBUG_ON(refs < 0);
703         if (refs == 0) {
704                 xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
705         }
706 }
707
708
709
710 #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
711                 xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
712
713
714 /*
715  * These two inlines are used to keep us from tearing down a partition's
716  * setup infrastructure while a thread may be referencing it.
717  */
718 static inline void
719 xpc_part_deref(struct xpc_partition *part)
720 {
721         s32 refs = atomic_dec_return(&part->references);
722
723
724         DBUG_ON(refs < 0);
725         if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN) {
726                 wake_up(&part->teardown_wq);
727         }
728 }
729
730 static inline int
731 xpc_part_ref(struct xpc_partition *part)
732 {
733         int setup;
734
735
736         atomic_inc(&part->references);
737         setup = (part->setup_state == XPC_P_SETUP);
738         if (!setup) {
739                 xpc_part_deref(part);
740         }
741         return setup;
742 }
743
744
745
746 /*
747  * The following macro is to be used for the setting of the reason and
748  * reason_line fields in both the struct xpc_channel and struct xpc_partition
749  * structures.
750  */
751 #define XPC_SET_REASON(_p, _reason, _line) \
752         { \
753                 (_p)->reason = _reason; \
754                 (_p)->reason_line = _line; \
755         }
756
757
758
759 /*
760  * This next set of inlines are used to keep track of when a partition is
761  * potentially engaged in accessing memory belonging to another partition.
762  */
763
764 static inline void
765 xpc_mark_partition_engaged(struct xpc_partition *part)
766 {
767         unsigned long irq_flags;
768         AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
769                                 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
770
771
772         local_irq_save(irq_flags);
773
774         /* set bit corresponding to our partid in remote partition's AMO */
775         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
776                                                 (1UL << sn_partition_id));
777         /*
778          * We must always use the nofault function regardless of whether we
779          * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
780          * didn't, we'd never know that the other partition is down and would
781          * keep sending IPIs and AMOs to it until the heartbeat times out.
782          */
783         (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
784                                 variable), xp_nofault_PIOR_target));
785
786         local_irq_restore(irq_flags);
787 }
788
789 static inline void
790 xpc_mark_partition_disengaged(struct xpc_partition *part)
791 {
792         unsigned long irq_flags;
793         AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
794                                 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
795
796
797         local_irq_save(irq_flags);
798
799         /* clear bit corresponding to our partid in remote partition's AMO */
800         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
801                                                 ~(1UL << sn_partition_id));
802         /*
803          * We must always use the nofault function regardless of whether we
804          * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
805          * didn't, we'd never know that the other partition is down and would
806          * keep sending IPIs and AMOs to it until the heartbeat times out.
807          */
808         (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
809                                 variable), xp_nofault_PIOR_target));
810
811         local_irq_restore(irq_flags);
812 }
813
814 static inline void
815 xpc_request_partition_disengage(struct xpc_partition *part)
816 {
817         unsigned long irq_flags;
818         AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
819                                 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
820
821
822         local_irq_save(irq_flags);
823
824         /* set bit corresponding to our partid in remote partition's AMO */
825         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
826                                                 (1UL << sn_partition_id));
827         /*
828          * We must always use the nofault function regardless of whether we
829          * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
830          * didn't, we'd never know that the other partition is down and would
831          * keep sending IPIs and AMOs to it until the heartbeat times out.
832          */
833         (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
834                                 variable), xp_nofault_PIOR_target));
835
836         local_irq_restore(irq_flags);
837 }
838
839 static inline void
840 xpc_cancel_partition_disengage_request(struct xpc_partition *part)
841 {
842         unsigned long irq_flags;
843         AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
844                                 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
845
846
847         local_irq_save(irq_flags);
848
849         /* clear bit corresponding to our partid in remote partition's AMO */
850         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
851                                                 ~(1UL << sn_partition_id));
852         /*
853          * We must always use the nofault function regardless of whether we
854          * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
855          * didn't, we'd never know that the other partition is down and would
856          * keep sending IPIs and AMOs to it until the heartbeat times out.
857          */
858         (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
859                                 variable), xp_nofault_PIOR_target));
860
861         local_irq_restore(irq_flags);
862 }
863
864 static inline u64
865 xpc_partition_engaged(u64 partid_mask)
866 {
867         AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
868
869
870         /* return our partition's AMO variable ANDed with partid_mask */
871         return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
872                                                                 partid_mask);
873 }
874
875 static inline u64
876 xpc_partition_disengage_requested(u64 partid_mask)
877 {
878         AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
879
880
881         /* return our partition's AMO variable ANDed with partid_mask */
882         return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
883                                                                 partid_mask);
884 }
885
886 static inline void
887 xpc_clear_partition_engaged(u64 partid_mask)
888 {
889         AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
890
891
892         /* clear bit(s) based on partid_mask in our partition's AMO */
893         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
894                                                                 ~partid_mask);
895 }
896
897 static inline void
898 xpc_clear_partition_disengage_request(u64 partid_mask)
899 {
900         AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
901
902
903         /* clear bit(s) based on partid_mask in our partition's AMO */
904         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
905                                                                 ~partid_mask);
906 }
907
908
909
910 /*
911  * The following set of macros and inlines are used for the sending and
912  * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
913  * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
914  * the other that is associated with channel activity (SGI_XPC_NOTIFY).
915  */
916
917 static inline u64
918 xpc_IPI_receive(AMO_t *amo)
919 {
920         return FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_CLEAR);
921 }
922
923
924 static inline enum xpc_retval
925 xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
926 {
927         int ret = 0;
928         unsigned long irq_flags;
929
930
931         local_irq_save(irq_flags);
932
933         FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, flag);
934         sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
935
936         /*
937          * We must always use the nofault function regardless of whether we
938          * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
939          * didn't, we'd never know that the other partition is down and would
940          * keep sending IPIs and AMOs to it until the heartbeat times out.
941          */
942         ret = xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
943                                 xp_nofault_PIOR_target));
944
945         local_irq_restore(irq_flags);
946
947         return ((ret == 0) ? xpcSuccess : xpcPioReadError);
948 }
949
950
951 /*
952  * IPIs associated with SGI_XPC_ACTIVATE IRQ.
953  */
954
955 /*
956  * Flag the appropriate AMO variable and send an IPI to the specified node.
957  */
958 static inline void
959 xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid,
960                         int to_phys_cpuid)
961 {
962         int w_index = XPC_NASID_W_INDEX(from_nasid);
963         int b_index = XPC_NASID_B_INDEX(from_nasid);
964         AMO_t *amos = (AMO_t *) __va(amos_page_pa +
965                                 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
966
967
968         (void) xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
969                                 to_phys_cpuid, SGI_XPC_ACTIVATE);
970 }
971
972 static inline void
973 xpc_IPI_send_activate(struct xpc_vars *vars)
974 {
975         xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
976                                 vars->act_nasid, vars->act_phys_cpuid);
977 }
978
979 static inline void
980 xpc_IPI_send_activated(struct xpc_partition *part)
981 {
982         xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
983                         part->remote_act_nasid, part->remote_act_phys_cpuid);
984 }
985
986 static inline void
987 xpc_IPI_send_reactivate(struct xpc_partition *part)
988 {
989         xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
990                                 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
991 }
992
993 static inline void
994 xpc_IPI_send_disengage(struct xpc_partition *part)
995 {
996         xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
997                         part->remote_act_nasid, part->remote_act_phys_cpuid);
998 }
999
1000
1001 /*
1002  * IPIs associated with SGI_XPC_NOTIFY IRQ.
1003  */
1004
1005 /*
1006  * Send an IPI to the remote partition that is associated with the
1007  * specified channel.
1008  */
1009 #define XPC_NOTIFY_IRQ_SEND(_ch, _ipi_f, _irq_f) \
1010                 xpc_notify_IRQ_send(_ch, _ipi_f, #_ipi_f, _irq_f)
1011
1012 static inline void
1013 xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
1014                         unsigned long *irq_flags)
1015 {
1016         struct xpc_partition *part = &xpc_partitions[ch->partid];
1017         enum xpc_retval ret;
1018
1019
1020         if (likely(part->act_state != XPC_P_DEACTIVATING)) {
1021                 ret = xpc_IPI_send(part->remote_IPI_amo_va,
1022                                         (u64) ipi_flag << (ch->number * 8),
1023                                         part->remote_IPI_nasid,
1024                                         part->remote_IPI_phys_cpuid,
1025                                         SGI_XPC_NOTIFY);
1026                 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
1027                         ipi_flag_string, ch->partid, ch->number, ret);
1028                 if (unlikely(ret != xpcSuccess)) {
1029                         if (irq_flags != NULL) {
1030                                 spin_unlock_irqrestore(&ch->lock, *irq_flags);
1031                         }
1032                         XPC_DEACTIVATE_PARTITION(part, ret);
1033                         if (irq_flags != NULL) {
1034                                 spin_lock_irqsave(&ch->lock, *irq_flags);
1035                         }
1036                 }
1037         }
1038 }
1039
1040
1041 /*
1042  * Make it look like the remote partition, which is associated with the
1043  * specified channel, sent us an IPI. This faked IPI will be handled
1044  * by xpc_dropped_IPI_check().
1045  */
1046 #define XPC_NOTIFY_IRQ_SEND_LOCAL(_ch, _ipi_f) \
1047                 xpc_notify_IRQ_send_local(_ch, _ipi_f, #_ipi_f)
1048
1049 static inline void
1050 xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1051                                 char *ipi_flag_string)
1052 {
1053         struct xpc_partition *part = &xpc_partitions[ch->partid];
1054
1055
1056         FETCHOP_STORE_OP(TO_AMO((u64) &part->local_IPI_amo_va->variable),
1057                         FETCHOP_OR, ((u64) ipi_flag << (ch->number * 8)));
1058         dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
1059                 ipi_flag_string, ch->partid, ch->number);
1060 }
1061
1062
1063 /*
1064  * The sending and receiving of IPIs includes the setting of an AMO variable
1065  * to indicate the reason the IPI was sent. The 64-bit variable is divided
1066  * up into eight bytes, ordered from right to left. Byte zero pertains to
1067  * channel 0, byte one to channel 1, and so on. Each byte is described by
1068  * the following IPI flags.
1069  */
1070
1071 #define XPC_IPI_CLOSEREQUEST    0x01
1072 #define XPC_IPI_CLOSEREPLY      0x02
1073 #define XPC_IPI_OPENREQUEST     0x04
1074 #define XPC_IPI_OPENREPLY       0x08
1075 #define XPC_IPI_MSGREQUEST      0x10
1076
1077
1078 /* given an AMO variable and a channel#, get its associated IPI flags */
1079 #define XPC_GET_IPI_FLAGS(_amo, _c)     ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
1080
1081 #define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0f)
1082 #define XPC_ANY_MSG_IPI_FLAGS_SET(_amo)       ((_amo) & 0x1010101010101010)
1083
1084
1085 static inline void
1086 xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
1087 {
1088         struct xpc_openclose_args *args = ch->local_openclose_args;
1089
1090
1091         args->reason = ch->reason;
1092
1093         XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
1094 }
1095
1096 static inline void
1097 xpc_IPI_send_closereply(struct xpc_channel *ch, unsigned long *irq_flags)
1098 {
1099         XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREPLY, irq_flags);
1100 }
1101
1102 static inline void
1103 xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
1104 {
1105         struct xpc_openclose_args *args = ch->local_openclose_args;
1106
1107
1108         args->msg_size = ch->msg_size;
1109         args->local_nentries = ch->local_nentries;
1110
1111         XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREQUEST, irq_flags);
1112 }
1113
1114 static inline void
1115 xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
1116 {
1117         struct xpc_openclose_args *args = ch->local_openclose_args;
1118
1119
1120         args->remote_nentries = ch->remote_nentries;
1121         args->local_nentries = ch->local_nentries;
1122         args->local_msgqueue_pa = __pa(ch->local_msgqueue);
1123
1124         XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREPLY, irq_flags);
1125 }
1126
1127 static inline void
1128 xpc_IPI_send_msgrequest(struct xpc_channel *ch)
1129 {
1130         XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_MSGREQUEST, NULL);
1131 }
1132
1133 static inline void
1134 xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
1135 {
1136         XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
1137 }
1138
1139
1140 /*
1141  * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
1142  * pages are located in the lowest granule. The lowest granule uses 4k pages
1143  * for cached references and an alternate TLB handler to never provide a
1144  * cacheable mapping for the entire region. This will prevent speculative
1145  * reading of cached copies of our lines from being issued which will cause
1146  * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
1147  * (XP_MAX_PARTITIONS) AMO variables for message notification and an
1148  * additional 16 (XP_NASID_MASK_WORDS) AMO variables for partition activation
1149  * and 2 AMO variables for partition deactivation.
1150  */
1151 static inline AMO_t *
1152 xpc_IPI_init(int index)
1153 {
1154         AMO_t *amo = xpc_vars->amos_page + index;
1155
1156
1157         (void) xpc_IPI_receive(amo);    /* clear AMO variable */
1158         return amo;
1159 }
1160
1161
1162
1163 static inline enum xpc_retval
1164 xpc_map_bte_errors(bte_result_t error)
1165 {
1166         switch (error) {
1167         case BTE_SUCCESS:       return xpcSuccess;
1168         case BTEFAIL_DIR:       return xpcBteDirectoryError;
1169         case BTEFAIL_POISON:    return xpcBtePoisonError;
1170         case BTEFAIL_WERR:      return xpcBteWriteError;
1171         case BTEFAIL_ACCESS:    return xpcBteAccessError;
1172         case BTEFAIL_PWERR:     return xpcBtePWriteError;
1173         case BTEFAIL_PRERR:     return xpcBtePReadError;
1174         case BTEFAIL_TOUT:      return xpcBteTimeOutError;
1175         case BTEFAIL_XTERR:     return xpcBteXtalkError;
1176         case BTEFAIL_NOTAVAIL:  return xpcBteNotAvailable;
1177         default:                return xpcBteUnmappedError;
1178         }
1179 }
1180
1181
1182
1183 static inline void *
1184 xpc_kmalloc_cacheline_aligned(size_t size, int flags, void **base)
1185 {
1186         /* see if kmalloc will give us cachline aligned memory by default */
1187         *base = kmalloc(size, flags);
1188         if (*base == NULL) {
1189                 return NULL;
1190         }
1191         if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
1192                 return *base;
1193         }
1194         kfree(*base);
1195
1196         /* nope, we'll have to do it ourselves */
1197         *base = kmalloc(size + L1_CACHE_BYTES, flags);
1198         if (*base == NULL) {
1199                 return NULL;
1200         }
1201         return (void *) L1_CACHE_ALIGN((u64) *base);
1202 }
1203
1204
1205 /*
1206  * Check to see if there is any channel activity to/from the specified
1207  * partition.
1208  */
1209 static inline void
1210 xpc_check_for_channel_activity(struct xpc_partition *part)
1211 {
1212         u64 IPI_amo;
1213         unsigned long irq_flags;
1214
1215
1216         IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
1217         if (IPI_amo == 0) {
1218                 return;
1219         }
1220
1221         spin_lock_irqsave(&part->IPI_lock, irq_flags);
1222         part->local_IPI_amo |= IPI_amo;
1223         spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
1224
1225         dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
1226                 XPC_PARTID(part), IPI_amo);
1227
1228         xpc_wakeup_channel_mgr(part);
1229 }
1230
1231
1232 #endif /* _IA64_SN_KERNEL_XPC_H */
1233