xref: /OK3568_Linux_fs/kernel/drivers/misc/sgi-xp/xpc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun  * for more details.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (c) 2004-2009 Silicon Graphics, Inc.  All Rights Reserved.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun  * Cross Partition Communication (XPC) structures and macros.
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #ifndef _DRIVERS_MISC_SGIXP_XPC_H
14*4882a593Smuzhiyun #define _DRIVERS_MISC_SGIXP_XPC_H
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <linux/wait.h>
17*4882a593Smuzhiyun #include <linux/completion.h>
18*4882a593Smuzhiyun #include <linux/timer.h>
19*4882a593Smuzhiyun #include <linux/sched.h>
20*4882a593Smuzhiyun #include "xp.h"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * XPC Version numbers consist of a major and minor number. XPC can always
24*4882a593Smuzhiyun  * talk to versions with same major #, and never talk to versions with a
25*4882a593Smuzhiyun  * different major #.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun #define _XPC_VERSION(_maj, _min)	(((_maj) << 4) | ((_min) & 0xf))
28*4882a593Smuzhiyun #define XPC_VERSION_MAJOR(_v)		((_v) >> 4)
29*4882a593Smuzhiyun #define XPC_VERSION_MINOR(_v)		((_v) & 0xf)
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* define frequency of the heartbeat and frequency how often it's checked */
32*4882a593Smuzhiyun #define XPC_HB_DEFAULT_INTERVAL		5	/* incr HB every x secs */
33*4882a593Smuzhiyun #define XPC_HB_CHECK_DEFAULT_INTERVAL	20	/* check HB every x secs */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /* define the process name of HB checker and the CPU it is pinned to */
36*4882a593Smuzhiyun #define XPC_HB_CHECK_THREAD_NAME	"xpc_hb"
37*4882a593Smuzhiyun #define XPC_HB_CHECK_CPU		0
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* define the process name of the discovery thread */
40*4882a593Smuzhiyun #define XPC_DISCOVERY_THREAD_NAME	"xpc_discovery"
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /*
43*4882a593Smuzhiyun  * the reserved page
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  *   SAL reserves one page of memory per partition for XPC. Though a full page
46*4882a593Smuzhiyun  *   in length (16384 bytes), its starting address is not page aligned, but it
47*4882a593Smuzhiyun  *   is cacheline aligned. The reserved page consists of the following:
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  *   reserved page header
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  *     The first two 64-byte cachelines of the reserved page contain the
52*4882a593Smuzhiyun  *     header (struct xpc_rsvd_page). Before SAL initialization has completed,
53*4882a593Smuzhiyun  *     SAL has set up the following fields of the reserved page header:
54*4882a593Smuzhiyun  *     SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The
55*4882a593Smuzhiyun  *     other fields are set up by XPC. (xpc_rsvd_page points to the local
56*4882a593Smuzhiyun  *     partition's reserved page.)
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  *   part_nasids mask
59*4882a593Smuzhiyun  *   mach_nasids mask
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  *     SAL also sets up two bitmaps (or masks), one that reflects the actual
62*4882a593Smuzhiyun  *     nasids in this partition (part_nasids), and the other that reflects
63*4882a593Smuzhiyun  *     the actual nasids in the entire machine (mach_nasids). We're only
64*4882a593Smuzhiyun  *     interested in the even numbered nasids (which contain the processors
65*4882a593Smuzhiyun  *     and/or memory), so we only need half as many bits to represent the
66*4882a593Smuzhiyun  *     nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure
67*4882a593Smuzhiyun  *     to either divide or multiply by 2. The part_nasids mask is located
68*4882a593Smuzhiyun  *     starting at the first cacheline following the reserved page header. The
69*4882a593Smuzhiyun  *     mach_nasids mask follows right after the part_nasids mask. The size in
70*4882a593Smuzhiyun  *     bytes of each mask is reflected by the reserved page header field
71*4882a593Smuzhiyun  *     'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids
72*4882a593Smuzhiyun  *     and xpc_mach_nasids.)
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  *     Immediately following the mach_nasids mask are the XPC variables
75*4882a593Smuzhiyun  *     required by other partitions. First are those that are generic to all
76*4882a593Smuzhiyun  *     partitions (vars), followed on the next available cacheline by those
77*4882a593Smuzhiyun  *     which are partition specific (vars part). These are setup by XPC.
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been
80*4882a593Smuzhiyun  *       initialized.
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun struct xpc_rsvd_page {
83*4882a593Smuzhiyun 	u64 SAL_signature;	/* SAL: unique signature */
84*4882a593Smuzhiyun 	u64 SAL_version;	/* SAL: version */
85*4882a593Smuzhiyun 	short SAL_partid;	/* SAL: partition ID */
86*4882a593Smuzhiyun 	short max_npartitions;	/* value of XPC_MAX_PARTITIONS */
87*4882a593Smuzhiyun 	u8 version;
88*4882a593Smuzhiyun 	u8 pad1[3];		/* align to next u64 in 1st 64-byte cacheline */
89*4882a593Smuzhiyun 	unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
90*4882a593Smuzhiyun 	union {
91*4882a593Smuzhiyun 		struct {
92*4882a593Smuzhiyun 			unsigned long heartbeat_gpa; /* phys addr */
93*4882a593Smuzhiyun 			unsigned long activate_gru_mq_desc_gpa; /* phys addr */
94*4882a593Smuzhiyun 		} uv;
95*4882a593Smuzhiyun 	} sn;
96*4882a593Smuzhiyun 	u64 pad2[9];		/* align to last u64 in 2nd 64-byte cacheline */
97*4882a593Smuzhiyun 	u64 SAL_nasids_size;	/* SAL: size of each nasid mask in bytes */
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun /* the reserved page sizes and offsets */
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define XPC_RP_HEADER_SIZE	L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
107*4882a593Smuzhiyun 				 XPC_RP_HEADER_SIZE))
108*4882a593Smuzhiyun #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
109*4882a593Smuzhiyun 				 xpc_nasid_mask_nlongs)
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /*
113*4882a593Smuzhiyun  * The following structure describes the partition's heartbeat info which
114*4882a593Smuzhiyun  * will be periodically read by other partitions to determine whether this
115*4882a593Smuzhiyun  * XPC is still 'alive'.
116*4882a593Smuzhiyun  */
117*4882a593Smuzhiyun struct xpc_heartbeat_uv {
118*4882a593Smuzhiyun 	unsigned long value;
119*4882a593Smuzhiyun 	unsigned long offline;	/* if 0, heartbeat should be changing */
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /*
123*4882a593Smuzhiyun  * Info pertinent to a GRU message queue using a watch list for irq generation.
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun struct xpc_gru_mq_uv {
126*4882a593Smuzhiyun 	void *address;		/* address of GRU message queue */
127*4882a593Smuzhiyun 	unsigned int order;	/* size of GRU message queue as a power of 2 */
128*4882a593Smuzhiyun 	int irq;		/* irq raised when message is received in mq */
129*4882a593Smuzhiyun 	int mmr_blade;		/* blade where watchlist was allocated from */
130*4882a593Smuzhiyun 	unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
131*4882a593Smuzhiyun 	unsigned long mmr_value; /* value of irq mmr located on mmr_blade */
132*4882a593Smuzhiyun 	int watchlist_num;	/* number of watchlist allocatd by BIOS */
133*4882a593Smuzhiyun 	void *gru_mq_desc;	/* opaque structure used by the GRU driver */
134*4882a593Smuzhiyun };
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /*
137*4882a593Smuzhiyun  * The activate_mq is used to send/receive GRU messages that affect XPC's
138*4882a593Smuzhiyun  * partition active state and channel state. This is uv only.
139*4882a593Smuzhiyun  */
140*4882a593Smuzhiyun struct xpc_activate_mq_msghdr_uv {
141*4882a593Smuzhiyun 	unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
142*4882a593Smuzhiyun 	short partid;		/* sender's partid */
143*4882a593Smuzhiyun 	u8 act_state;		/* sender's act_state at time msg sent */
144*4882a593Smuzhiyun 	u8 type;		/* message's type */
145*4882a593Smuzhiyun 	unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /* activate_mq defined message types */
149*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV		0
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV		1
152*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV		2
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV	3
155*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV		4
156*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV	5
157*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV		6
158*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV	7
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV		8
161*4882a593Smuzhiyun #define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV		9
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun struct xpc_activate_mq_msg_uv {
164*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
165*4882a593Smuzhiyun };
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun struct xpc_activate_mq_msg_activate_req_uv {
168*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
169*4882a593Smuzhiyun 	unsigned long rp_gpa;
170*4882a593Smuzhiyun 	unsigned long heartbeat_gpa;
171*4882a593Smuzhiyun 	unsigned long activate_gru_mq_desc_gpa;
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun struct xpc_activate_mq_msg_deactivate_req_uv {
175*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
176*4882a593Smuzhiyun 	enum xp_retval reason;
177*4882a593Smuzhiyun };
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun struct xpc_activate_mq_msg_chctl_closerequest_uv {
180*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
181*4882a593Smuzhiyun 	short ch_number;
182*4882a593Smuzhiyun 	enum xp_retval reason;
183*4882a593Smuzhiyun };
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun struct xpc_activate_mq_msg_chctl_closereply_uv {
186*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
187*4882a593Smuzhiyun 	short ch_number;
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun struct xpc_activate_mq_msg_chctl_openrequest_uv {
191*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
192*4882a593Smuzhiyun 	short ch_number;
193*4882a593Smuzhiyun 	short entry_size;	/* size of notify_mq's GRU messages */
194*4882a593Smuzhiyun 	short local_nentries;	/* ??? Is this needed? What is? */
195*4882a593Smuzhiyun };
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun struct xpc_activate_mq_msg_chctl_openreply_uv {
198*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
199*4882a593Smuzhiyun 	short ch_number;
200*4882a593Smuzhiyun 	short remote_nentries;	/* ??? Is this needed? What is? */
201*4882a593Smuzhiyun 	short local_nentries;	/* ??? Is this needed? What is? */
202*4882a593Smuzhiyun 	unsigned long notify_gru_mq_desc_gpa;
203*4882a593Smuzhiyun };
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun struct xpc_activate_mq_msg_chctl_opencomplete_uv {
206*4882a593Smuzhiyun 	struct xpc_activate_mq_msghdr_uv hdr;
207*4882a593Smuzhiyun 	short ch_number;
208*4882a593Smuzhiyun };
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun /*
211*4882a593Smuzhiyun  * Functions registered by add_timer() or called by kernel_thread() only
212*4882a593Smuzhiyun  * allow for a single 64-bit argument. The following macros can be used to
213*4882a593Smuzhiyun  * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
214*4882a593Smuzhiyun  * the passed argument.
215*4882a593Smuzhiyun  */
216*4882a593Smuzhiyun #define XPC_PACK_ARGS(_arg1, _arg2) \
217*4882a593Smuzhiyun 			((((u64)_arg1) & 0xffffffff) | \
218*4882a593Smuzhiyun 			((((u64)_arg2) & 0xffffffff) << 32))
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun #define XPC_UNPACK_ARG1(_args)	(((u64)_args) & 0xffffffff)
221*4882a593Smuzhiyun #define XPC_UNPACK_ARG2(_args)	((((u64)_args) >> 32) & 0xffffffff)
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun /*
224*4882a593Smuzhiyun  * Define a structure that contains arguments associated with opening and
225*4882a593Smuzhiyun  * closing a channel.
226*4882a593Smuzhiyun  */
227*4882a593Smuzhiyun struct xpc_openclose_args {
228*4882a593Smuzhiyun 	u16 reason;		/* reason why channel is closing */
229*4882a593Smuzhiyun 	u16 entry_size;		/* sizeof each message entry */
230*4882a593Smuzhiyun 	u16 remote_nentries;	/* #of message entries in remote msg queue */
231*4882a593Smuzhiyun 	u16 local_nentries;	/* #of message entries in local msg queue */
232*4882a593Smuzhiyun 	unsigned long local_msgqueue_pa; /* phys addr of local message queue */
233*4882a593Smuzhiyun };
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun #define XPC_OPENCLOSE_ARGS_SIZE \
236*4882a593Smuzhiyun 	      L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
237*4882a593Smuzhiyun 	      XPC_MAX_NCHANNELS)
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun /*
241*4882a593Smuzhiyun  * Structures to define a fifo singly-linked list.
242*4882a593Smuzhiyun  */
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun struct xpc_fifo_entry_uv {
245*4882a593Smuzhiyun 	struct xpc_fifo_entry_uv *next;
246*4882a593Smuzhiyun };
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun struct xpc_fifo_head_uv {
249*4882a593Smuzhiyun 	struct xpc_fifo_entry_uv *first;
250*4882a593Smuzhiyun 	struct xpc_fifo_entry_uv *last;
251*4882a593Smuzhiyun 	spinlock_t lock;
252*4882a593Smuzhiyun 	int n_entries;
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun /*
256*4882a593Smuzhiyun  * The format of a uv XPC notify_mq GRU message is as follows:
257*4882a593Smuzhiyun  *
258*4882a593Smuzhiyun  * A user-defined message resides in the payload area. The max size of the
259*4882a593Smuzhiyun  * payload is defined by the user via xpc_connect().
260*4882a593Smuzhiyun  *
261*4882a593Smuzhiyun  * The size of a message (payload and header) sent via the GRU must be either 1
262*4882a593Smuzhiyun  * or 2 GRU_CACHE_LINE_BYTES in length.
263*4882a593Smuzhiyun  */
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun struct xpc_notify_mq_msghdr_uv {
266*4882a593Smuzhiyun 	union {
267*4882a593Smuzhiyun 		unsigned int gru_msg_hdr;	/* FOR GRU INTERNAL USE ONLY */
268*4882a593Smuzhiyun 		struct xpc_fifo_entry_uv next;	/* FOR XPC INTERNAL USE ONLY */
269*4882a593Smuzhiyun 	} u;
270*4882a593Smuzhiyun 	short partid;		/* FOR XPC INTERNAL USE ONLY */
271*4882a593Smuzhiyun 	u8 ch_number;		/* FOR XPC INTERNAL USE ONLY */
272*4882a593Smuzhiyun 	u8 size;		/* FOR XPC INTERNAL USE ONLY */
273*4882a593Smuzhiyun 	unsigned int msg_slot_number;	/* FOR XPC INTERNAL USE ONLY */
274*4882a593Smuzhiyun };
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun struct xpc_notify_mq_msg_uv {
277*4882a593Smuzhiyun 	struct xpc_notify_mq_msghdr_uv hdr;
278*4882a593Smuzhiyun 	unsigned long payload;
279*4882a593Smuzhiyun };
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun /* struct xpc_notify_sn2 type of notification */
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun #define	XPC_N_CALL	0x01	/* notify function provided by user */
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun /*
286*4882a593Smuzhiyun  * Define uv's version of the notify entry. It additionally is used to allocate
287*4882a593Smuzhiyun  * a msg slot on the remote partition into which is copied a sent message.
288*4882a593Smuzhiyun  */
289*4882a593Smuzhiyun struct xpc_send_msg_slot_uv {
290*4882a593Smuzhiyun 	struct xpc_fifo_entry_uv next;
291*4882a593Smuzhiyun 	unsigned int msg_slot_number;
292*4882a593Smuzhiyun 	xpc_notify_func func;	/* user's notify function */
293*4882a593Smuzhiyun 	void *key;		/* pointer to user's key */
294*4882a593Smuzhiyun };
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun /*
297*4882a593Smuzhiyun  * Define the structure that manages all the stuff required by a channel. In
298*4882a593Smuzhiyun  * particular, they are used to manage the messages sent across the channel.
299*4882a593Smuzhiyun  *
300*4882a593Smuzhiyun  * This structure is private to a partition, and is NOT shared across the
301*4882a593Smuzhiyun  * partition boundary.
302*4882a593Smuzhiyun  *
303*4882a593Smuzhiyun  * There is an array of these structures for each remote partition. It is
304*4882a593Smuzhiyun  * allocated at the time a partition becomes active. The array contains one
305*4882a593Smuzhiyun  * of these structures for each potential channel connection to that partition.
306*4882a593Smuzhiyun  */
307*4882a593Smuzhiyun 
308*4882a593Smuzhiyun struct xpc_channel_uv {
309*4882a593Smuzhiyun 	void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */
310*4882a593Smuzhiyun 					 /* gru mq descriptor */
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	struct xpc_send_msg_slot_uv *send_msg_slots;
313*4882a593Smuzhiyun 	void *recv_msg_slots;	/* each slot will hold a xpc_notify_mq_msg_uv */
314*4882a593Smuzhiyun 				/* structure plus the user's payload */
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun 	struct xpc_fifo_head_uv msg_slot_free_list;
317*4882a593Smuzhiyun 	struct xpc_fifo_head_uv recv_msg_list;	/* deliverable payloads */
318*4882a593Smuzhiyun };
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun struct xpc_channel {
321*4882a593Smuzhiyun 	short partid;		/* ID of remote partition connected */
322*4882a593Smuzhiyun 	spinlock_t lock;	/* lock for updating this structure */
323*4882a593Smuzhiyun 	unsigned int flags;	/* general flags */
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	enum xp_retval reason;	/* reason why channel is disconnect'g */
326*4882a593Smuzhiyun 	int reason_line;	/* line# disconnect initiated from */
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun 	u16 number;		/* channel # */
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	u16 entry_size;		/* sizeof each msg entry */
331*4882a593Smuzhiyun 	u16 local_nentries;	/* #of msg entries in local msg queue */
332*4882a593Smuzhiyun 	u16 remote_nentries;	/* #of msg entries in remote msg queue */
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	atomic_t references;	/* #of external references to queues */
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	atomic_t n_on_msg_allocate_wq;	/* #on msg allocation wait queue */
337*4882a593Smuzhiyun 	wait_queue_head_t msg_allocate_wq;	/* msg allocation wait queue */
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	u8 delayed_chctl_flags;	/* chctl flags received, but delayed */
340*4882a593Smuzhiyun 				/* action until channel disconnected */
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	atomic_t n_to_notify;	/* #of msg senders to notify */
343*4882a593Smuzhiyun 
344*4882a593Smuzhiyun 	xpc_channel_func func;	/* user's channel function */
345*4882a593Smuzhiyun 	void *key;		/* pointer to user's key */
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun 	struct completion wdisconnect_wait;    /* wait for channel disconnect */
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	/* kthread management related fields */
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	atomic_t kthreads_assigned;	/* #of kthreads assigned to channel */
352*4882a593Smuzhiyun 	u32 kthreads_assigned_limit;	/* limit on #of kthreads assigned */
353*4882a593Smuzhiyun 	atomic_t kthreads_idle;	/* #of kthreads idle waiting for work */
354*4882a593Smuzhiyun 	u32 kthreads_idle_limit;	/* limit on #of kthreads idle */
355*4882a593Smuzhiyun 	atomic_t kthreads_active;	/* #of kthreads actively working */
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun 	wait_queue_head_t idle_wq;	/* idle kthread wait queue */
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun 	union {
360*4882a593Smuzhiyun 		struct xpc_channel_uv uv;
361*4882a593Smuzhiyun 	} sn;
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun } ____cacheline_aligned;
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun /* struct xpc_channel flags */
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun #define	XPC_C_WASCONNECTED	0x00000001	/* channel was connected */
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun #define XPC_C_ROPENCOMPLETE	0x00000002    /* remote open channel complete */
370*4882a593Smuzhiyun #define XPC_C_OPENCOMPLETE	0x00000004     /* local open channel complete */
371*4882a593Smuzhiyun #define	XPC_C_ROPENREPLY	0x00000008	/* remote open channel reply */
372*4882a593Smuzhiyun #define	XPC_C_OPENREPLY		0x00000010	/* local open channel reply */
373*4882a593Smuzhiyun #define	XPC_C_ROPENREQUEST	0x00000020     /* remote open channel request */
374*4882a593Smuzhiyun #define	XPC_C_OPENREQUEST	0x00000040	/* local open channel request */
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun #define	XPC_C_SETUP		0x00000080 /* channel's msgqueues are alloc'd */
377*4882a593Smuzhiyun #define	XPC_C_CONNECTEDCALLOUT	0x00000100     /* connected callout initiated */
378*4882a593Smuzhiyun #define	XPC_C_CONNECTEDCALLOUT_MADE \
379*4882a593Smuzhiyun 				0x00000200     /* connected callout completed */
380*4882a593Smuzhiyun #define	XPC_C_CONNECTED		0x00000400	/* local channel is connected */
381*4882a593Smuzhiyun #define	XPC_C_CONNECTING	0x00000800	/* channel is being connected */
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun #define	XPC_C_RCLOSEREPLY	0x00001000	/* remote close channel reply */
384*4882a593Smuzhiyun #define	XPC_C_CLOSEREPLY	0x00002000	/* local close channel reply */
385*4882a593Smuzhiyun #define	XPC_C_RCLOSEREQUEST	0x00004000    /* remote close channel request */
386*4882a593Smuzhiyun #define	XPC_C_CLOSEREQUEST	0x00008000     /* local close channel request */
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun #define	XPC_C_DISCONNECTED	0x00010000	/* channel is disconnected */
389*4882a593Smuzhiyun #define	XPC_C_DISCONNECTING	0x00020000   /* channel is being disconnected */
390*4882a593Smuzhiyun #define	XPC_C_DISCONNECTINGCALLOUT \
391*4882a593Smuzhiyun 				0x00040000 /* disconnecting callout initiated */
392*4882a593Smuzhiyun #define	XPC_C_DISCONNECTINGCALLOUT_MADE \
393*4882a593Smuzhiyun 				0x00080000 /* disconnecting callout completed */
394*4882a593Smuzhiyun #define	XPC_C_WDISCONNECT	0x00100000  /* waiting for channel disconnect */
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun /*
397*4882a593Smuzhiyun  * The channel control flags (chctl) union consists of a 64-bit variable which
398*4882a593Smuzhiyun  * is divided up into eight bytes, ordered from right to left. Byte zero
399*4882a593Smuzhiyun  * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
400*4882a593Smuzhiyun  * can have one or more of the chctl flags set in it.
401*4882a593Smuzhiyun  */
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun union xpc_channel_ctl_flags {
404*4882a593Smuzhiyun 	u64 all_flags;
405*4882a593Smuzhiyun 	u8 flags[XPC_MAX_NCHANNELS];
406*4882a593Smuzhiyun };
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun /* chctl flags */
409*4882a593Smuzhiyun #define	XPC_CHCTL_CLOSEREQUEST	0x01
410*4882a593Smuzhiyun #define	XPC_CHCTL_CLOSEREPLY	0x02
411*4882a593Smuzhiyun #define	XPC_CHCTL_OPENREQUEST	0x04
412*4882a593Smuzhiyun #define	XPC_CHCTL_OPENREPLY	0x08
413*4882a593Smuzhiyun #define XPC_CHCTL_OPENCOMPLETE	0x10
414*4882a593Smuzhiyun #define	XPC_CHCTL_MSGREQUEST	0x20
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun #define XPC_OPENCLOSE_CHCTL_FLAGS \
417*4882a593Smuzhiyun 			(XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
418*4882a593Smuzhiyun 			 XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \
419*4882a593Smuzhiyun 			 XPC_CHCTL_OPENCOMPLETE)
420*4882a593Smuzhiyun #define XPC_MSG_CHCTL_FLAGS	XPC_CHCTL_MSGREQUEST
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun static inline int
xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags * chctl)423*4882a593Smuzhiyun xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun 	int ch_number;
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
428*4882a593Smuzhiyun 		if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
429*4882a593Smuzhiyun 			return 1;
430*4882a593Smuzhiyun 	}
431*4882a593Smuzhiyun 	return 0;
432*4882a593Smuzhiyun }
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun static inline int
xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags * chctl)435*4882a593Smuzhiyun xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
436*4882a593Smuzhiyun {
437*4882a593Smuzhiyun 	int ch_number;
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun 	for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
440*4882a593Smuzhiyun 		if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
441*4882a593Smuzhiyun 			return 1;
442*4882a593Smuzhiyun 	}
443*4882a593Smuzhiyun 	return 0;
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun struct xpc_partition_uv {
447*4882a593Smuzhiyun 	unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */
448*4882a593Smuzhiyun 	struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */
449*4882a593Smuzhiyun 						  /* partition's heartbeat */
450*4882a593Smuzhiyun 	unsigned long activate_gru_mq_desc_gpa;	/* phys addr of parititon's */
451*4882a593Smuzhiyun 						/* activate mq's gru mq */
452*4882a593Smuzhiyun 						/* descriptor */
453*4882a593Smuzhiyun 	void *cached_activate_gru_mq_desc; /* cached copy of partition's */
454*4882a593Smuzhiyun 					   /* activate mq's gru mq descriptor */
455*4882a593Smuzhiyun 	struct mutex cached_activate_gru_mq_desc_mutex;
456*4882a593Smuzhiyun 	spinlock_t flags_lock;	/* protect updating of flags */
457*4882a593Smuzhiyun 	unsigned int flags;	/* general flags */
458*4882a593Smuzhiyun 	u8 remote_act_state;	/* remote partition's act_state */
459*4882a593Smuzhiyun 	u8 act_state_req;	/* act_state request from remote partition */
460*4882a593Smuzhiyun 	enum xp_retval reason;	/* reason for deactivate act_state request */
461*4882a593Smuzhiyun };
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun /* struct xpc_partition_uv flags */
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun #define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV	0x00000001
466*4882a593Smuzhiyun #define XPC_P_ENGAGED_UV			0x00000002
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /* struct xpc_partition_uv act_state change requests */
469*4882a593Smuzhiyun 
470*4882a593Smuzhiyun #define XPC_P_ASR_ACTIVATE_UV		0x01
471*4882a593Smuzhiyun #define XPC_P_ASR_REACTIVATE_UV		0x02
472*4882a593Smuzhiyun #define XPC_P_ASR_DEACTIVATE_UV		0x03
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun struct xpc_partition {
475*4882a593Smuzhiyun 
476*4882a593Smuzhiyun 	/* XPC HB infrastructure */
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun 	u8 remote_rp_version;	/* version# of partition's rsvd pg */
479*4882a593Smuzhiyun 	unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
480*4882a593Smuzhiyun 	unsigned long remote_rp_pa;	/* phys addr of partition's rsvd pg */
481*4882a593Smuzhiyun 	u64 last_heartbeat;	/* HB at last read */
482*4882a593Smuzhiyun 	u32 activate_IRQ_rcvd;	/* IRQs since activation */
483*4882a593Smuzhiyun 	spinlock_t act_lock;	/* protect updating of act_state */
484*4882a593Smuzhiyun 	u8 act_state;		/* from XPC HB viewpoint */
485*4882a593Smuzhiyun 	enum xp_retval reason;	/* reason partition is deactivating */
486*4882a593Smuzhiyun 	int reason_line;	/* line# deactivation initiated from */
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun 	unsigned long disengage_timeout;	/* timeout in jiffies */
489*4882a593Smuzhiyun 	struct timer_list disengage_timer;
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun 	/* XPC infrastructure referencing and teardown control */
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun 	u8 setup_state;		/* infrastructure setup state */
494*4882a593Smuzhiyun 	wait_queue_head_t teardown_wq;	/* kthread waiting to teardown infra */
495*4882a593Smuzhiyun 	atomic_t references;	/* #of references to infrastructure */
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun 	u8 nchannels;		/* #of defined channels supported */
498*4882a593Smuzhiyun 	atomic_t nchannels_active;  /* #of channels that are not DISCONNECTED */
499*4882a593Smuzhiyun 	atomic_t nchannels_engaged;  /* #of channels engaged with remote part */
500*4882a593Smuzhiyun 	struct xpc_channel *channels;	/* array of channel structures */
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 	/* fields used for managing channel avialability and activity */
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun 	union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
505*4882a593Smuzhiyun 	spinlock_t chctl_lock;	/* chctl flags lock */
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	void *remote_openclose_args_base;  /* base address of kmalloc'd space */
508*4882a593Smuzhiyun 	struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
509*4882a593Smuzhiyun 							  /* args */
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 	/* channel manager related fields */
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun 	atomic_t channel_mgr_requests;	/* #of requests to activate chan mgr */
514*4882a593Smuzhiyun 	wait_queue_head_t channel_mgr_wq;	/* channel mgr's wait queue */
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 	union {
517*4882a593Smuzhiyun 		struct xpc_partition_uv uv;
518*4882a593Smuzhiyun 	} sn;
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun } ____cacheline_aligned;
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun struct xpc_arch_operations {
523*4882a593Smuzhiyun 	int (*setup_partitions) (void);
524*4882a593Smuzhiyun 	void (*teardown_partitions) (void);
525*4882a593Smuzhiyun 	void (*process_activate_IRQ_rcvd) (void);
526*4882a593Smuzhiyun 	enum xp_retval (*get_partition_rsvd_page_pa)
527*4882a593Smuzhiyun 		(void *, u64 *, unsigned long *, size_t *);
528*4882a593Smuzhiyun 	int (*setup_rsvd_page) (struct xpc_rsvd_page *);
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 	void (*allow_hb) (short);
531*4882a593Smuzhiyun 	void (*disallow_hb) (short);
532*4882a593Smuzhiyun 	void (*disallow_all_hbs) (void);
533*4882a593Smuzhiyun 	void (*increment_heartbeat) (void);
534*4882a593Smuzhiyun 	void (*offline_heartbeat) (void);
535*4882a593Smuzhiyun 	void (*online_heartbeat) (void);
536*4882a593Smuzhiyun 	void (*heartbeat_init) (void);
537*4882a593Smuzhiyun 	void (*heartbeat_exit) (void);
538*4882a593Smuzhiyun 	enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);
539*4882a593Smuzhiyun 
540*4882a593Smuzhiyun 	void (*request_partition_activation) (struct xpc_rsvd_page *,
541*4882a593Smuzhiyun 						 unsigned long, int);
542*4882a593Smuzhiyun 	void (*request_partition_reactivation) (struct xpc_partition *);
543*4882a593Smuzhiyun 	void (*request_partition_deactivation) (struct xpc_partition *);
544*4882a593Smuzhiyun 	void (*cancel_partition_deactivation_request) (struct xpc_partition *);
545*4882a593Smuzhiyun 	enum xp_retval (*setup_ch_structures) (struct xpc_partition *);
546*4882a593Smuzhiyun 	void (*teardown_ch_structures) (struct xpc_partition *);
547*4882a593Smuzhiyun 
548*4882a593Smuzhiyun 	enum xp_retval (*make_first_contact) (struct xpc_partition *);
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun 	u64 (*get_chctl_all_flags) (struct xpc_partition *);
551*4882a593Smuzhiyun 	void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);
552*4882a593Smuzhiyun 	void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);
553*4882a593Smuzhiyun 	void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);
554*4882a593Smuzhiyun 	void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);
555*4882a593Smuzhiyun 	void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);
556*4882a593Smuzhiyun 	void (*process_msg_chctl_flags) (struct xpc_partition *, int);
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun 	enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,
559*4882a593Smuzhiyun 						      unsigned long);
560*4882a593Smuzhiyun 
561*4882a593Smuzhiyun 	enum xp_retval (*setup_msg_structures) (struct xpc_channel *);
562*4882a593Smuzhiyun 	void (*teardown_msg_structures) (struct xpc_channel *);
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	void (*indicate_partition_engaged) (struct xpc_partition *);
565*4882a593Smuzhiyun 	void (*indicate_partition_disengaged) (struct xpc_partition *);
566*4882a593Smuzhiyun 	void (*assume_partition_disengaged) (short);
567*4882a593Smuzhiyun 	int (*partition_engaged) (short);
568*4882a593Smuzhiyun 	int (*any_partition_engaged) (void);
569*4882a593Smuzhiyun 
570*4882a593Smuzhiyun 	int (*n_of_deliverable_payloads) (struct xpc_channel *);
571*4882a593Smuzhiyun 	enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,
572*4882a593Smuzhiyun 					   u16, u8, xpc_notify_func, void *);
573*4882a593Smuzhiyun 	void *(*get_deliverable_payload) (struct xpc_channel *);
574*4882a593Smuzhiyun 	void (*received_payload) (struct xpc_channel *, void *);
575*4882a593Smuzhiyun 	void (*notify_senders_of_disconnect) (struct xpc_channel *);
576*4882a593Smuzhiyun };
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun /* struct xpc_partition act_state values (for XPC HB) */
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun #define	XPC_P_AS_INACTIVE	0x00	/* partition is not active */
581*4882a593Smuzhiyun #define XPC_P_AS_ACTIVATION_REQ	0x01	/* created thread to activate */
582*4882a593Smuzhiyun #define XPC_P_AS_ACTIVATING	0x02	/* activation thread started */
583*4882a593Smuzhiyun #define XPC_P_AS_ACTIVE		0x03	/* xpc_partition_up() was called */
584*4882a593Smuzhiyun #define XPC_P_AS_DEACTIVATING	0x04	/* partition deactivation initiated */
585*4882a593Smuzhiyun 
586*4882a593Smuzhiyun #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
587*4882a593Smuzhiyun 			xpc_deactivate_partition(__LINE__, (_p), (_reason))
588*4882a593Smuzhiyun 
589*4882a593Smuzhiyun /* struct xpc_partition setup_state values */
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun #define XPC_P_SS_UNSET		0x00	/* infrastructure was never setup */
592*4882a593Smuzhiyun #define XPC_P_SS_SETUP		0x01	/* infrastructure is setup */
593*4882a593Smuzhiyun #define XPC_P_SS_WTEARDOWN	0x02	/* waiting to teardown infrastructure */
594*4882a593Smuzhiyun #define XPC_P_SS_TORNDOWN	0x03	/* infrastructure is torndown */
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun /* number of seconds to wait for other partitions to disengage */
597*4882a593Smuzhiyun #define XPC_DISENGAGE_DEFAULT_TIMELIMIT		90
598*4882a593Smuzhiyun 
599*4882a593Smuzhiyun /* interval in seconds to print 'waiting deactivation' messages */
600*4882a593Smuzhiyun #define XPC_DEACTIVATE_PRINTMSG_INTERVAL	10
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun #define XPC_PARTID(_p)	((short)((_p) - &xpc_partitions[0]))
603*4882a593Smuzhiyun 
604*4882a593Smuzhiyun /* found in xp_main.c */
605*4882a593Smuzhiyun extern struct xpc_registration xpc_registrations[];
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun /* found in xpc_main.c */
608*4882a593Smuzhiyun extern struct device *xpc_part;
609*4882a593Smuzhiyun extern struct device *xpc_chan;
610*4882a593Smuzhiyun extern struct xpc_arch_operations xpc_arch_ops;
611*4882a593Smuzhiyun extern int xpc_disengage_timelimit;
612*4882a593Smuzhiyun extern int xpc_disengage_timedout;
613*4882a593Smuzhiyun extern int xpc_activate_IRQ_rcvd;
614*4882a593Smuzhiyun extern spinlock_t xpc_activate_IRQ_rcvd_lock;
615*4882a593Smuzhiyun extern wait_queue_head_t xpc_activate_IRQ_wq;
616*4882a593Smuzhiyun extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
617*4882a593Smuzhiyun extern void xpc_activate_partition(struct xpc_partition *);
618*4882a593Smuzhiyun extern void xpc_activate_kthreads(struct xpc_channel *, int);
619*4882a593Smuzhiyun extern void xpc_create_kthreads(struct xpc_channel *, int, int);
620*4882a593Smuzhiyun extern void xpc_disconnect_wait(int);
621*4882a593Smuzhiyun 
622*4882a593Smuzhiyun /* found in xpc_uv.c */
623*4882a593Smuzhiyun extern int xpc_init_uv(void);
624*4882a593Smuzhiyun extern void xpc_exit_uv(void);
625*4882a593Smuzhiyun 
626*4882a593Smuzhiyun /* found in xpc_partition.c */
627*4882a593Smuzhiyun extern int xpc_exiting;
628*4882a593Smuzhiyun extern int xpc_nasid_mask_nlongs;
629*4882a593Smuzhiyun extern struct xpc_rsvd_page *xpc_rsvd_page;
630*4882a593Smuzhiyun extern unsigned long *xpc_mach_nasids;
631*4882a593Smuzhiyun extern struct xpc_partition *xpc_partitions;
632*4882a593Smuzhiyun extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
633*4882a593Smuzhiyun extern int xpc_setup_rsvd_page(void);
634*4882a593Smuzhiyun extern void xpc_teardown_rsvd_page(void);
635*4882a593Smuzhiyun extern int xpc_identify_activate_IRQ_sender(void);
636*4882a593Smuzhiyun extern int xpc_partition_disengaged(struct xpc_partition *);
637*4882a593Smuzhiyun extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
638*4882a593Smuzhiyun extern void xpc_mark_partition_inactive(struct xpc_partition *);
639*4882a593Smuzhiyun extern void xpc_discovery(void);
640*4882a593Smuzhiyun extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
641*4882a593Smuzhiyun 					struct xpc_rsvd_page *,
642*4882a593Smuzhiyun 					unsigned long *);
643*4882a593Smuzhiyun extern void xpc_deactivate_partition(const int, struct xpc_partition *,
644*4882a593Smuzhiyun 				     enum xp_retval);
645*4882a593Smuzhiyun extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun /* found in xpc_channel.c */
648*4882a593Smuzhiyun extern void xpc_initiate_connect(int);
649*4882a593Smuzhiyun extern void xpc_initiate_disconnect(int);
650*4882a593Smuzhiyun extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
651*4882a593Smuzhiyun extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
652*4882a593Smuzhiyun extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
653*4882a593Smuzhiyun 					       xpc_notify_func, void *);
654*4882a593Smuzhiyun extern void xpc_initiate_received(short, int, void *);
655*4882a593Smuzhiyun extern void xpc_process_sent_chctl_flags(struct xpc_partition *);
656*4882a593Smuzhiyun extern void xpc_connected_callout(struct xpc_channel *);
657*4882a593Smuzhiyun extern void xpc_deliver_payload(struct xpc_channel *);
658*4882a593Smuzhiyun extern void xpc_disconnect_channel(const int, struct xpc_channel *,
659*4882a593Smuzhiyun 				   enum xp_retval, unsigned long *);
660*4882a593Smuzhiyun extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
661*4882a593Smuzhiyun extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun static inline void
xpc_wakeup_channel_mgr(struct xpc_partition * part)664*4882a593Smuzhiyun xpc_wakeup_channel_mgr(struct xpc_partition *part)
665*4882a593Smuzhiyun {
666*4882a593Smuzhiyun 	if (atomic_inc_return(&part->channel_mgr_requests) == 1)
667*4882a593Smuzhiyun 		wake_up(&part->channel_mgr_wq);
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun /*
671*4882a593Smuzhiyun  * These next two inlines are used to keep us from tearing down a channel's
672*4882a593Smuzhiyun  * msg queues while a thread may be referencing them.
673*4882a593Smuzhiyun  */
674*4882a593Smuzhiyun static inline void
xpc_msgqueue_ref(struct xpc_channel * ch)675*4882a593Smuzhiyun xpc_msgqueue_ref(struct xpc_channel *ch)
676*4882a593Smuzhiyun {
677*4882a593Smuzhiyun 	atomic_inc(&ch->references);
678*4882a593Smuzhiyun }
679*4882a593Smuzhiyun 
680*4882a593Smuzhiyun static inline void
xpc_msgqueue_deref(struct xpc_channel * ch)681*4882a593Smuzhiyun xpc_msgqueue_deref(struct xpc_channel *ch)
682*4882a593Smuzhiyun {
683*4882a593Smuzhiyun 	s32 refs = atomic_dec_return(&ch->references);
684*4882a593Smuzhiyun 
685*4882a593Smuzhiyun 	DBUG_ON(refs < 0);
686*4882a593Smuzhiyun 	if (refs == 0)
687*4882a593Smuzhiyun 		xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
688*4882a593Smuzhiyun }
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
691*4882a593Smuzhiyun 		xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun /*
694*4882a593Smuzhiyun  * These two inlines are used to keep us from tearing down a partition's
695*4882a593Smuzhiyun  * setup infrastructure while a thread may be referencing it.
696*4882a593Smuzhiyun  */
697*4882a593Smuzhiyun static inline void
xpc_part_deref(struct xpc_partition * part)698*4882a593Smuzhiyun xpc_part_deref(struct xpc_partition *part)
699*4882a593Smuzhiyun {
700*4882a593Smuzhiyun 	s32 refs = atomic_dec_return(&part->references);
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun 	DBUG_ON(refs < 0);
703*4882a593Smuzhiyun 	if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)
704*4882a593Smuzhiyun 		wake_up(&part->teardown_wq);
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun static inline int
xpc_part_ref(struct xpc_partition * part)708*4882a593Smuzhiyun xpc_part_ref(struct xpc_partition *part)
709*4882a593Smuzhiyun {
710*4882a593Smuzhiyun 	int setup;
711*4882a593Smuzhiyun 
712*4882a593Smuzhiyun 	atomic_inc(&part->references);
713*4882a593Smuzhiyun 	setup = (part->setup_state == XPC_P_SS_SETUP);
714*4882a593Smuzhiyun 	if (!setup)
715*4882a593Smuzhiyun 		xpc_part_deref(part);
716*4882a593Smuzhiyun 
717*4882a593Smuzhiyun 	return setup;
718*4882a593Smuzhiyun }
719*4882a593Smuzhiyun 
720*4882a593Smuzhiyun /*
721*4882a593Smuzhiyun  * The following macro is to be used for the setting of the reason and
722*4882a593Smuzhiyun  * reason_line fields in both the struct xpc_channel and struct xpc_partition
723*4882a593Smuzhiyun  * structures.
724*4882a593Smuzhiyun  */
725*4882a593Smuzhiyun #define XPC_SET_REASON(_p, _reason, _line) \
726*4882a593Smuzhiyun 	{ \
727*4882a593Smuzhiyun 		(_p)->reason = _reason; \
728*4882a593Smuzhiyun 		(_p)->reason_line = _line; \
729*4882a593Smuzhiyun 	}
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun #endif /* _DRIVERS_MISC_SGIXP_XPC_H */
732