blob: ae51d7b4c42e900209dff45cf1eb939e2517fad2 [file] [log] [blame]
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001/*
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 */
Dean Nelsona607c382005-09-01 14:01:37 -050060#define XPC_HB_CHECK_DEFAULT_INTERVAL 20 /* check HB every x secs */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070061
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
Dean Nelson89eb8eb2005-03-23 19:50:00 -070070/*
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 */
79struct 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 */
Dave Jones821fe942005-06-25 14:54:29 -070085 volatile u64 vars_pa;
Dean Nelsona607c382005-09-01 14:01:37 -050086 struct timespec stamp; /* time when reserved page was initialized */
Dean Nelson89eb8eb2005-03-23 19:50:00 -070087 u64 part_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
88 u64 mach_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
89};
Dean Nelson89eb8eb2005-03-23 19:50:00 -070090
91#define XPC_RSVD_PAGE_ALIGNED_SIZE \
92 (L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)))
93
Dean Nelsona607c382005-09-01 14:01:37 -050094#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 */
106static inline int
107xpc_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
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700118
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 */
133struct 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 */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700143};
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700144
145#define XPC_VARS_ALIGNED_SIZE (L1_CACHE_ALIGN(sizeof(struct xpc_vars)))
146
Dean Nelsona607c382005-09-01 14:01:37 -0500147#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
153static inline int
154xpc_hb_allowed(partid_t partid, struct xpc_vars *vars)
155{
156 return ((vars->heartbeating_to_mask & (1UL << partid)) != 0);
157}
158
159static inline void
160xpc_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
171static inline void
172xpc_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
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700198/*
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 */
208struct xpc_vars_part {
Dave Jones821fe942005-06-25 14:54:29 -0700209 volatile u64 magic;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700210
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 */
255struct xpc_gp {
Dave Jones821fe942005-06-25 14:54:29 -0700256 volatile s64 get; /* Get value */
257 volatile s64 put; /* Put value */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700258};
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 */
269struct 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 */
300struct xpc_notify {
301 struct semaphore sema; /* notify semaphore */
Dave Jones821fe942005-06-25 14:54:29 -0700302 volatile u8 type; /* type of notification */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700303
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 */
393struct 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
Dean Nelsone54af722005-10-25 14:07:43 -0500420 u8 delayed_IPI_flags; /* IPI flags received, but delayed */
421 /* action until channel disconnected */
422
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700423 /* queue of msg senders who want to be notified when msg received */
424
425 atomic_t n_to_notify; /* #of msg senders to notify */
426 struct xpc_notify *notify_queue;/* notify queue for messages sent */
427
428 xpc_channel_func func; /* user's channel function */
429 void *key; /* pointer to user's key */
430
431 struct semaphore msg_to_pull_sema; /* next msg to pull serialization */
Dean Nelsona607c382005-09-01 14:01:37 -0500432 struct semaphore wdisconnect_sema; /* wait for channel disconnect */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700433
434 struct xpc_openclose_args *local_openclose_args; /* args passed on */
435 /* opening or closing of channel */
436
437 /* various flavors of local and remote Get/Put values */
438
439 struct xpc_gp *local_GP; /* local Get/Put values */
440 struct xpc_gp remote_GP; /* remote Get/Put values */
441 struct xpc_gp w_local_GP; /* working local Get/Put values */
442 struct xpc_gp w_remote_GP; /* working remote Get/Put values */
443 s64 next_msg_to_pull; /* Put value of next msg to pull */
444
445 /* kthread management related fields */
446
447// >>> rethink having kthreads_assigned_limit and kthreads_idle_limit; perhaps
448// >>> allow the assigned limit be unbounded and let the idle limit be dynamic
449// >>> dependent on activity over the last interval of time
450 atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
451 u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
452 atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
453 u32 kthreads_idle_limit; /* limit on #of kthreads idle */
454 atomic_t kthreads_active; /* #of kthreads actively working */
455 // >>> following field is temporary
456 u32 kthreads_created; /* total #of kthreads created */
457
458 wait_queue_head_t idle_wq; /* idle kthread wait queue */
459
460} ____cacheline_aligned;
461
462
463/* struct xpc_channel flags */
464
465#define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
466
467#define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */
468#define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */
469#define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */
470#define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */
471
472#define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */
473#define XPC_C_CONNECTCALLOUT 0x00000040 /* channel connected callout made */
474#define XPC_C_CONNECTED 0x00000080 /* local channel is connected */
475#define XPC_C_CONNECTING 0x00000100 /* channel is being connected */
476
477#define XPC_C_RCLOSEREPLY 0x00000200 /* remote close channel reply */
478#define XPC_C_CLOSEREPLY 0x00000400 /* local close channel reply */
479#define XPC_C_RCLOSEREQUEST 0x00000800 /* remote close channel request */
480#define XPC_C_CLOSEREQUEST 0x00001000 /* local close channel request */
481
482#define XPC_C_DISCONNECTED 0x00002000 /* channel is disconnected */
483#define XPC_C_DISCONNECTING 0x00004000 /* channel is being disconnected */
Dean Nelsone54af722005-10-25 14:07:43 -0500484#define XPC_C_DISCONNECTCALLOUT 0x00008000 /* chan disconnected callout made */
485#define XPC_C_WDISCONNECT 0x00010000 /* waiting for channel disconnect */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700486
487
488
489/*
490 * Manages channels on a partition basis. There is one of these structures
491 * for each partition (a partition will never utilize the structure that
492 * represents itself).
493 */
494struct xpc_partition {
495
496 /* XPC HB infrastructure */
497
Dean Nelsona607c382005-09-01 14:01:37 -0500498 u8 remote_rp_version; /* version# of partition's rsvd pg */
499 struct timespec remote_rp_stamp;/* time when rsvd pg was initialized */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700500 u64 remote_rp_pa; /* phys addr of partition's rsvd pg */
501 u64 remote_vars_pa; /* phys addr of partition's vars */
502 u64 remote_vars_part_pa; /* phys addr of partition's vars part */
503 u64 last_heartbeat; /* HB at last read */
504 u64 remote_amos_page_pa; /* phys addr of partition's amos page */
505 int remote_act_nasid; /* active part's act/deact nasid */
506 int remote_act_phys_cpuid; /* active part's act/deact phys cpuid */
507 u32 act_IRQ_rcvd; /* IRQs since activation */
508 spinlock_t act_lock; /* protect updating of act_state */
509 u8 act_state; /* from XPC HB viewpoint */
Dean Nelsona607c382005-09-01 14:01:37 -0500510 u8 remote_vars_version; /* version# of partition's vars */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700511 enum xpc_retval reason; /* reason partition is deactivating */
512 int reason_line; /* line# deactivation initiated from */
513 int reactivate_nasid; /* nasid in partition to reactivate */
514
Dean Nelsone54af722005-10-25 14:07:43 -0500515 unsigned long disengage_request_timeout; /* timeout in jiffies */
Dean Nelsona607c382005-09-01 14:01:37 -0500516 struct timer_list disengage_request_timer;
517
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700518
519 /* XPC infrastructure referencing and teardown control */
520
Dean Nelsone54af722005-10-25 14:07:43 -0500521 volatile u8 setup_state; /* infrastructure setup state */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700522 wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
523 atomic_t references; /* #of references to infrastructure */
524
525
526 /*
527 * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN
528 * XPC SETS UP THE NECESSARY INFRASTRUCTURE TO SUPPORT CROSS PARTITION
529 * COMMUNICATION. ALL OF THE FOLLOWING FIELDS WILL BE CLEARED. (THE
530 * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.)
531 */
532
533
534 u8 nchannels; /* #of defined channels supported */
535 atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
Dean Nelsona607c382005-09-01 14:01:37 -0500536 atomic_t nchannels_engaged;/* #of channels engaged with remote part */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700537 struct xpc_channel *channels;/* array of channel structures */
538
539 void *local_GPs_base; /* base address of kmalloc'd space */
540 struct xpc_gp *local_GPs; /* local Get/Put values */
541 void *remote_GPs_base; /* base address of kmalloc'd space */
542 struct xpc_gp *remote_GPs;/* copy of remote partition's local Get/Put */
543 /* values */
544 u64 remote_GPs_pa; /* phys address of remote partition's local */
545 /* Get/Put values */
546
547
548 /* fields used to pass args when opening or closing a channel */
549
550 void *local_openclose_args_base; /* base address of kmalloc'd space */
551 struct xpc_openclose_args *local_openclose_args; /* local's args */
552 void *remote_openclose_args_base; /* base address of kmalloc'd space */
553 struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
554 /* args */
555 u64 remote_openclose_args_pa; /* phys addr of remote's args */
556
557
558 /* IPI sending, receiving and handling related fields */
559
560 int remote_IPI_nasid; /* nasid of where to send IPIs */
561 int remote_IPI_phys_cpuid; /* phys CPU ID of where to send IPIs */
562 AMO_t *remote_IPI_amo_va; /* address of remote IPI AMO_t structure */
563
564 AMO_t *local_IPI_amo_va; /* address of IPI AMO_t structure */
565 u64 local_IPI_amo; /* IPI amo flags yet to be handled */
566 char IPI_owner[8]; /* IPI owner's name */
567 struct timer_list dropped_IPI_timer; /* dropped IPI timer */
568
569 spinlock_t IPI_lock; /* IPI handler lock */
570
571
572 /* channel manager related fields */
573
574 atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
575 wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
576
577} ____cacheline_aligned;
578
579
580/* struct xpc_partition act_state values (for XPC HB) */
581
582#define XPC_P_INACTIVE 0x00 /* partition is not active */
583#define XPC_P_ACTIVATION_REQ 0x01 /* created thread to activate */
584#define XPC_P_ACTIVATING 0x02 /* activation thread started */
585#define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */
586#define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */
587
588
589#define XPC_DEACTIVATE_PARTITION(_p, _reason) \
590 xpc_deactivate_partition(__LINE__, (_p), (_reason))
591
592
593/* struct xpc_partition setup_state values */
594
595#define XPC_P_UNSET 0x00 /* infrastructure was never setup */
596#define XPC_P_SETUP 0x01 /* infrastructure is setup */
597#define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
598#define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */
599
600
Dean Nelsona607c382005-09-01 14:01:37 -0500601
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700602/*
603 * struct xpc_partition IPI_timer #of seconds to wait before checking for
604 * dropped IPIs. These occur whenever an IPI amo write doesn't complete until
605 * after the IPI was received.
606 */
607#define XPC_P_DROPPED_IPI_WAIT (0.25 * HZ)
608
609
Dean Nelsona607c382005-09-01 14:01:37 -0500610/* number of seconds to wait for other partitions to disengage */
Dean Nelsone54af722005-10-25 14:07:43 -0500611#define XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT 90
Dean Nelsona607c382005-09-01 14:01:37 -0500612
613/* interval in seconds to print 'waiting disengagement' messages */
614#define XPC_DISENGAGE_PRINTMSG_INTERVAL 10
615
616
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700617#define XPC_PARTID(_p) ((partid_t) ((_p) - &xpc_partitions[0]))
618
619
620
621/* found in xp_main.c */
622extern struct xpc_registration xpc_registrations[];
623
624
Dean Nelsone54af722005-10-25 14:07:43 -0500625/* found in xpc_main.c */
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700626extern struct device *xpc_part;
627extern struct device *xpc_chan;
Dean Nelsone54af722005-10-25 14:07:43 -0500628extern int xpc_disengage_request_timelimit;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700629extern irqreturn_t xpc_notify_IRQ_handler(int, void *, struct pt_regs *);
630extern void xpc_dropped_IPI_check(struct xpc_partition *);
Dean Nelsone54af722005-10-25 14:07:43 -0500631extern void xpc_activate_partition(struct xpc_partition *);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700632extern void xpc_activate_kthreads(struct xpc_channel *, int);
633extern void xpc_create_kthreads(struct xpc_channel *, int);
634extern void xpc_disconnect_wait(int);
635
636
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700637/* found in xpc_partition.c */
638extern int xpc_exiting;
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700639extern struct xpc_vars *xpc_vars;
640extern struct xpc_rsvd_page *xpc_rsvd_page;
641extern struct xpc_vars_part *xpc_vars_part;
642extern struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
643extern char xpc_remote_copy_buffer[];
644extern struct xpc_rsvd_page *xpc_rsvd_page_init(void);
645extern void xpc_allow_IPI_ops(void);
646extern void xpc_restrict_IPI_ops(void);
647extern int xpc_identify_act_IRQ_sender(void);
Dean Nelsona607c382005-09-01 14:01:37 -0500648extern int xpc_partition_disengaged(struct xpc_partition *);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700649extern enum xpc_retval xpc_mark_partition_active(struct xpc_partition *);
650extern void xpc_mark_partition_inactive(struct xpc_partition *);
651extern void xpc_discovery(void);
652extern void xpc_check_remote_hb(void);
653extern void xpc_deactivate_partition(const int, struct xpc_partition *,
654 enum xpc_retval);
655extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *);
656
657
658/* found in xpc_channel.c */
659extern void xpc_initiate_connect(int);
660extern void xpc_initiate_disconnect(int);
661extern enum xpc_retval xpc_initiate_allocate(partid_t, int, u32, void **);
662extern enum xpc_retval xpc_initiate_send(partid_t, int, void *);
663extern enum xpc_retval xpc_initiate_send_notify(partid_t, int, void *,
664 xpc_notify_func, void *);
665extern void xpc_initiate_received(partid_t, int, void *);
666extern enum xpc_retval xpc_setup_infrastructure(struct xpc_partition *);
667extern enum xpc_retval xpc_pull_remote_vars_part(struct xpc_partition *);
668extern void xpc_process_channel_activity(struct xpc_partition *);
669extern void xpc_connected_callout(struct xpc_channel *);
670extern void xpc_deliver_msg(struct xpc_channel *);
671extern void xpc_disconnect_channel(const int, struct xpc_channel *,
672 enum xpc_retval, unsigned long *);
Dean Nelsona607c382005-09-01 14:01:37 -0500673extern void xpc_disconnecting_callout(struct xpc_channel *);
674extern void xpc_partition_going_down(struct xpc_partition *, enum xpc_retval);
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700675extern void xpc_teardown_infrastructure(struct xpc_partition *);
676
677
678
679static inline void
680xpc_wakeup_channel_mgr(struct xpc_partition *part)
681{
682 if (atomic_inc_return(&part->channel_mgr_requests) == 1) {
683 wake_up(&part->channel_mgr_wq);
684 }
685}
686
687
688
689/*
690 * These next two inlines are used to keep us from tearing down a channel's
691 * msg queues while a thread may be referencing them.
692 */
693static inline void
694xpc_msgqueue_ref(struct xpc_channel *ch)
695{
696 atomic_inc(&ch->references);
697}
698
699static inline void
700xpc_msgqueue_deref(struct xpc_channel *ch)
701{
702 s32 refs = atomic_dec_return(&ch->references);
703
704 DBUG_ON(refs < 0);
705 if (refs == 0) {
706 xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
707 }
708}
709
710
711
712#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
713 xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
714
715
716/*
717 * These two inlines are used to keep us from tearing down a partition's
718 * setup infrastructure while a thread may be referencing it.
719 */
720static inline void
721xpc_part_deref(struct xpc_partition *part)
722{
723 s32 refs = atomic_dec_return(&part->references);
724
725
726 DBUG_ON(refs < 0);
727 if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN) {
728 wake_up(&part->teardown_wq);
729 }
730}
731
732static inline int
733xpc_part_ref(struct xpc_partition *part)
734{
735 int setup;
736
737
738 atomic_inc(&part->references);
739 setup = (part->setup_state == XPC_P_SETUP);
740 if (!setup) {
741 xpc_part_deref(part);
742 }
743 return setup;
744}
745
746
747
748/*
749 * The following macro is to be used for the setting of the reason and
750 * reason_line fields in both the struct xpc_channel and struct xpc_partition
751 * structures.
752 */
753#define XPC_SET_REASON(_p, _reason, _line) \
754 { \
755 (_p)->reason = _reason; \
756 (_p)->reason_line = _line; \
757 }
758
759
760
761/*
Dean Nelsona607c382005-09-01 14:01:37 -0500762 * This next set of inlines are used to keep track of when a partition is
763 * potentially engaged in accessing memory belonging to another partition.
764 */
765
766static inline void
767xpc_mark_partition_engaged(struct xpc_partition *part)
768{
769 unsigned long irq_flags;
770 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
771 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
772
773
774 local_irq_save(irq_flags);
775
776 /* set bit corresponding to our partid in remote partition's AMO */
777 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
778 (1UL << sn_partition_id));
779 /*
780 * We must always use the nofault function regardless of whether we
781 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
782 * didn't, we'd never know that the other partition is down and would
783 * keep sending IPIs and AMOs to it until the heartbeat times out.
784 */
785 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
786 variable), xp_nofault_PIOR_target));
787
788 local_irq_restore(irq_flags);
789}
790
791static inline void
792xpc_mark_partition_disengaged(struct xpc_partition *part)
793{
794 unsigned long irq_flags;
795 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
796 (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
797
798
799 local_irq_save(irq_flags);
800
801 /* clear bit corresponding to our partid in remote partition's AMO */
802 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
803 ~(1UL << sn_partition_id));
804 /*
805 * We must always use the nofault function regardless of whether we
806 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
807 * didn't, we'd never know that the other partition is down and would
808 * keep sending IPIs and AMOs to it until the heartbeat times out.
809 */
810 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
811 variable), xp_nofault_PIOR_target));
812
813 local_irq_restore(irq_flags);
814}
815
816static inline void
817xpc_request_partition_disengage(struct xpc_partition *part)
818{
819 unsigned long irq_flags;
820 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
821 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
822
823
824 local_irq_save(irq_flags);
825
826 /* set bit corresponding to our partid in remote partition's AMO */
827 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
828 (1UL << sn_partition_id));
829 /*
830 * We must always use the nofault function regardless of whether we
831 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
832 * didn't, we'd never know that the other partition is down and would
833 * keep sending IPIs and AMOs to it until the heartbeat times out.
834 */
835 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
836 variable), xp_nofault_PIOR_target));
837
838 local_irq_restore(irq_flags);
839}
840
841static inline void
842xpc_cancel_partition_disengage_request(struct xpc_partition *part)
843{
844 unsigned long irq_flags;
845 AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
846 (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
847
848
849 local_irq_save(irq_flags);
850
851 /* clear bit corresponding to our partid in remote partition's AMO */
852 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
853 ~(1UL << sn_partition_id));
854 /*
855 * We must always use the nofault function regardless of whether we
856 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
857 * didn't, we'd never know that the other partition is down and would
858 * keep sending IPIs and AMOs to it until the heartbeat times out.
859 */
860 (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
861 variable), xp_nofault_PIOR_target));
862
863 local_irq_restore(irq_flags);
864}
865
866static inline u64
867xpc_partition_engaged(u64 partid_mask)
868{
869 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
870
871
872 /* return our partition's AMO variable ANDed with partid_mask */
873 return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
874 partid_mask);
875}
876
877static inline u64
878xpc_partition_disengage_requested(u64 partid_mask)
879{
880 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
881
882
883 /* return our partition's AMO variable ANDed with partid_mask */
884 return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
885 partid_mask);
886}
887
888static inline void
889xpc_clear_partition_engaged(u64 partid_mask)
890{
891 AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
892
893
894 /* clear bit(s) based on partid_mask in our partition's AMO */
895 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
896 ~partid_mask);
897}
898
899static inline void
900xpc_clear_partition_disengage_request(u64 partid_mask)
901{
902 AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
903
904
905 /* clear bit(s) based on partid_mask in our partition's AMO */
906 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
907 ~partid_mask);
908}
909
910
911
912/*
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700913 * The following set of macros and inlines are used for the sending and
914 * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
915 * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
916 * the other that is associated with channel activity (SGI_XPC_NOTIFY).
917 */
918
919static inline u64
920xpc_IPI_receive(AMO_t *amo)
921{
922 return FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_CLEAR);
923}
924
925
926static inline enum xpc_retval
927xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
928{
929 int ret = 0;
930 unsigned long irq_flags;
931
932
933 local_irq_save(irq_flags);
934
935 FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, flag);
936 sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
937
938 /*
939 * We must always use the nofault function regardless of whether we
940 * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
941 * didn't, we'd never know that the other partition is down and would
942 * keep sending IPIs and AMOs to it until the heartbeat times out.
943 */
944 ret = xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
945 xp_nofault_PIOR_target));
946
947 local_irq_restore(irq_flags);
948
949 return ((ret == 0) ? xpcSuccess : xpcPioReadError);
950}
951
952
953/*
954 * IPIs associated with SGI_XPC_ACTIVATE IRQ.
955 */
956
957/*
958 * Flag the appropriate AMO variable and send an IPI to the specified node.
959 */
960static inline void
Dean Nelsona607c382005-09-01 14:01:37 -0500961xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid,
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700962 int to_phys_cpuid)
963{
964 int w_index = XPC_NASID_W_INDEX(from_nasid);
965 int b_index = XPC_NASID_B_INDEX(from_nasid);
Dean Nelsona607c382005-09-01 14:01:37 -0500966 AMO_t *amos = (AMO_t *) __va(amos_page_pa +
967 (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
Dean Nelson89eb8eb2005-03-23 19:50:00 -0700968
969
970 (void) xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
971 to_phys_cpuid, SGI_XPC_ACTIVATE);
972}
973
974static inline void
975xpc_IPI_send_activate(struct xpc_vars *vars)
976{
977 xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
978 vars->act_nasid, vars->act_phys_cpuid);
979}
980
981static inline void
982xpc_IPI_send_activated(struct xpc_partition *part)
983{
984 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
985 part->remote_act_nasid, part->remote_act_phys_cpuid);
986}
987
988static inline void
989xpc_IPI_send_reactivate(struct xpc_partition *part)
990{
991 xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
992 xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
993}
994
Dean Nelsona607c382005-09-01 14:01:37 -0500995static inline void
996xpc_IPI_send_disengage(struct xpc_partition *part)
997{
998 xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
999 part->remote_act_nasid, part->remote_act_phys_cpuid);
1000}
1001
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001002
1003/*
1004 * IPIs associated with SGI_XPC_NOTIFY IRQ.
1005 */
1006
1007/*
1008 * Send an IPI to the remote partition that is associated with the
1009 * specified channel.
1010 */
1011#define XPC_NOTIFY_IRQ_SEND(_ch, _ipi_f, _irq_f) \
1012 xpc_notify_IRQ_send(_ch, _ipi_f, #_ipi_f, _irq_f)
1013
1014static inline void
1015xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
1016 unsigned long *irq_flags)
1017{
1018 struct xpc_partition *part = &xpc_partitions[ch->partid];
1019 enum xpc_retval ret;
1020
1021
1022 if (likely(part->act_state != XPC_P_DEACTIVATING)) {
1023 ret = xpc_IPI_send(part->remote_IPI_amo_va,
1024 (u64) ipi_flag << (ch->number * 8),
1025 part->remote_IPI_nasid,
1026 part->remote_IPI_phys_cpuid,
1027 SGI_XPC_NOTIFY);
1028 dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
1029 ipi_flag_string, ch->partid, ch->number, ret);
1030 if (unlikely(ret != xpcSuccess)) {
1031 if (irq_flags != NULL) {
1032 spin_unlock_irqrestore(&ch->lock, *irq_flags);
1033 }
1034 XPC_DEACTIVATE_PARTITION(part, ret);
1035 if (irq_flags != NULL) {
1036 spin_lock_irqsave(&ch->lock, *irq_flags);
1037 }
1038 }
1039 }
1040}
1041
1042
1043/*
1044 * Make it look like the remote partition, which is associated with the
1045 * specified channel, sent us an IPI. This faked IPI will be handled
1046 * by xpc_dropped_IPI_check().
1047 */
1048#define XPC_NOTIFY_IRQ_SEND_LOCAL(_ch, _ipi_f) \
1049 xpc_notify_IRQ_send_local(_ch, _ipi_f, #_ipi_f)
1050
1051static inline void
1052xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
1053 char *ipi_flag_string)
1054{
1055 struct xpc_partition *part = &xpc_partitions[ch->partid];
1056
1057
1058 FETCHOP_STORE_OP(TO_AMO((u64) &part->local_IPI_amo_va->variable),
1059 FETCHOP_OR, ((u64) ipi_flag << (ch->number * 8)));
1060 dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
1061 ipi_flag_string, ch->partid, ch->number);
1062}
1063
1064
1065/*
1066 * The sending and receiving of IPIs includes the setting of an AMO variable
1067 * to indicate the reason the IPI was sent. The 64-bit variable is divided
1068 * up into eight bytes, ordered from right to left. Byte zero pertains to
1069 * channel 0, byte one to channel 1, and so on. Each byte is described by
1070 * the following IPI flags.
1071 */
1072
1073#define XPC_IPI_CLOSEREQUEST 0x01
1074#define XPC_IPI_CLOSEREPLY 0x02
1075#define XPC_IPI_OPENREQUEST 0x04
1076#define XPC_IPI_OPENREPLY 0x08
1077#define XPC_IPI_MSGREQUEST 0x10
1078
1079
1080/* given an AMO variable and a channel#, get its associated IPI flags */
1081#define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
Dean Nelsone54af722005-10-25 14:07:43 -05001082#define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8))
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001083
1084#define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0f)
1085#define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010)
1086
1087
1088static inline void
1089xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
1090{
1091 struct xpc_openclose_args *args = ch->local_openclose_args;
1092
1093
1094 args->reason = ch->reason;
1095
1096 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
1097}
1098
1099static inline void
1100xpc_IPI_send_closereply(struct xpc_channel *ch, unsigned long *irq_flags)
1101{
1102 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREPLY, irq_flags);
1103}
1104
1105static inline void
1106xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
1107{
1108 struct xpc_openclose_args *args = ch->local_openclose_args;
1109
1110
1111 args->msg_size = ch->msg_size;
1112 args->local_nentries = ch->local_nentries;
1113
1114 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREQUEST, irq_flags);
1115}
1116
1117static inline void
1118xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
1119{
1120 struct xpc_openclose_args *args = ch->local_openclose_args;
1121
1122
1123 args->remote_nentries = ch->remote_nentries;
1124 args->local_nentries = ch->local_nentries;
1125 args->local_msgqueue_pa = __pa(ch->local_msgqueue);
1126
1127 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREPLY, irq_flags);
1128}
1129
1130static inline void
1131xpc_IPI_send_msgrequest(struct xpc_channel *ch)
1132{
1133 XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_MSGREQUEST, NULL);
1134}
1135
1136static inline void
1137xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
1138{
1139 XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
1140}
1141
1142
1143/*
1144 * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
1145 * pages are located in the lowest granule. The lowest granule uses 4k pages
1146 * for cached references and an alternate TLB handler to never provide a
1147 * cacheable mapping for the entire region. This will prevent speculative
1148 * reading of cached copies of our lines from being issued which will cause
1149 * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
Dean Nelsona607c382005-09-01 14:01:37 -05001150 * (XP_MAX_PARTITIONS) AMO variables for message notification and an
1151 * additional 16 (XP_NASID_MASK_WORDS) AMO variables for partition activation
1152 * and 2 AMO variables for partition deactivation.
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001153 */
1154static inline AMO_t *
Dean Nelsona607c382005-09-01 14:01:37 -05001155xpc_IPI_init(int index)
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001156{
Dean Nelsona607c382005-09-01 14:01:37 -05001157 AMO_t *amo = xpc_vars->amos_page + index;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001158
1159
Dean Nelsona607c382005-09-01 14:01:37 -05001160 (void) xpc_IPI_receive(amo); /* clear AMO variable */
1161 return amo;
Dean Nelson89eb8eb2005-03-23 19:50:00 -07001162}
1163
1164
1165
1166static inline enum xpc_retval
1167xpc_map_bte_errors(bte_result_t error)
1168{
1169 switch (error) {
1170 case BTE_SUCCESS: return xpcSuccess;
1171 case BTEFAIL_DIR: return xpcBteDirectoryError;
1172 case BTEFAIL_POISON: return xpcBtePoisonError;
1173 case BTEFAIL_WERR: return xpcBteWriteError;
1174 case BTEFAIL_ACCESS: return xpcBteAccessError;
1175 case BTEFAIL_PWERR: return xpcBtePWriteError;
1176 case BTEFAIL_PRERR: return xpcBtePReadError;
1177 case BTEFAIL_TOUT: return xpcBteTimeOutError;
1178 case BTEFAIL_XTERR: return xpcBteXtalkError;
1179 case BTEFAIL_NOTAVAIL: return xpcBteNotAvailable;
1180 default: return xpcBteUnmappedError;
1181 }
1182}
1183
1184
1185
1186static inline void *
1187xpc_kmalloc_cacheline_aligned(size_t size, int flags, void **base)
1188{
1189 /* see if kmalloc will give us cachline aligned memory by default */
1190 *base = kmalloc(size, flags);
1191 if (*base == NULL) {
1192 return NULL;
1193 }
1194 if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
1195 return *base;
1196 }
1197 kfree(*base);
1198
1199 /* nope, we'll have to do it ourselves */
1200 *base = kmalloc(size + L1_CACHE_BYTES, flags);
1201 if (*base == NULL) {
1202 return NULL;
1203 }
1204 return (void *) L1_CACHE_ALIGN((u64) *base);
1205}
1206
1207
1208/*
1209 * Check to see if there is any channel activity to/from the specified
1210 * partition.
1211 */
1212static inline void
1213xpc_check_for_channel_activity(struct xpc_partition *part)
1214{
1215 u64 IPI_amo;
1216 unsigned long irq_flags;
1217
1218
1219 IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
1220 if (IPI_amo == 0) {
1221 return;
1222 }
1223
1224 spin_lock_irqsave(&part->IPI_lock, irq_flags);
1225 part->local_IPI_amo |= IPI_amo;
1226 spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
1227
1228 dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
1229 XPC_PARTID(part), IPI_amo);
1230
1231 xpc_wakeup_channel_mgr(part);
1232}
1233
1234
1235#endif /* _IA64_SN_KERNEL_XPC_H */
1236