145d9ca49SDean Nelson /*
245d9ca49SDean Nelson * This file is subject to the terms and conditions of the GNU General Public
345d9ca49SDean Nelson * License. See the file "COPYING" in the main directory of this archive
445d9ca49SDean Nelson * for more details.
545d9ca49SDean Nelson *
6361916a9SDean Nelson * Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved.
745d9ca49SDean Nelson */
845d9ca49SDean Nelson
945d9ca49SDean Nelson /*
1045d9ca49SDean Nelson * Cross Partition Communication (XPC) structures and macros.
1145d9ca49SDean Nelson */
1245d9ca49SDean Nelson
1345d9ca49SDean Nelson #ifndef _DRIVERS_MISC_SGIXP_XPC_H
1445d9ca49SDean Nelson #define _DRIVERS_MISC_SGIXP_XPC_H
1545d9ca49SDean Nelson
16261f3b49SDean Nelson #include <linux/wait.h>
1745d9ca49SDean Nelson #include <linux/completion.h>
18261f3b49SDean Nelson #include <linux/timer.h>
19261f3b49SDean Nelson #include <linux/sched.h>
2045d9ca49SDean Nelson #include "xp.h"
2145d9ca49SDean Nelson
2245d9ca49SDean Nelson /*
2345d9ca49SDean Nelson * XPC Version numbers consist of a major and minor number. XPC can always
2445d9ca49SDean Nelson * talk to versions with same major #, and never talk to versions with a
2545d9ca49SDean Nelson * different major #.
2645d9ca49SDean Nelson */
2745d9ca49SDean Nelson #define _XPC_VERSION(_maj, _min) (((_maj) << 4) | ((_min) & 0xf))
2845d9ca49SDean Nelson #define XPC_VERSION_MAJOR(_v) ((_v) >> 4)
2945d9ca49SDean Nelson #define XPC_VERSION_MINOR(_v) ((_v) & 0xf)
3045d9ca49SDean Nelson
3104de7418SDean Nelson /* define frequency of the heartbeat and frequency how often it's checked */
3245d9ca49SDean Nelson #define XPC_HB_DEFAULT_INTERVAL 5 /* incr HB every x secs */
3345d9ca49SDean Nelson #define XPC_HB_CHECK_DEFAULT_INTERVAL 20 /* check HB every x secs */
3445d9ca49SDean Nelson
3545d9ca49SDean Nelson /* define the process name of HB checker and the CPU it is pinned to */
3645d9ca49SDean Nelson #define XPC_HB_CHECK_THREAD_NAME "xpc_hb"
3745d9ca49SDean Nelson #define XPC_HB_CHECK_CPU 0
3845d9ca49SDean Nelson
3945d9ca49SDean Nelson /* define the process name of the discovery thread */
4045d9ca49SDean Nelson #define XPC_DISCOVERY_THREAD_NAME "xpc_discovery"
4145d9ca49SDean Nelson
4245d9ca49SDean Nelson /*
4345d9ca49SDean Nelson * the reserved page
4445d9ca49SDean Nelson *
4545d9ca49SDean Nelson * SAL reserves one page of memory per partition for XPC. Though a full page
4645d9ca49SDean Nelson * in length (16384 bytes), its starting address is not page aligned, but it
4745d9ca49SDean Nelson * is cacheline aligned. The reserved page consists of the following:
4845d9ca49SDean Nelson *
4945d9ca49SDean Nelson * reserved page header
5045d9ca49SDean Nelson *
5194bd2708SDean Nelson * The first two 64-byte cachelines of the reserved page contain the
5294bd2708SDean Nelson * header (struct xpc_rsvd_page). Before SAL initialization has completed,
5345d9ca49SDean Nelson * SAL has set up the following fields of the reserved page header:
5494bd2708SDean Nelson * SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The
5594bd2708SDean Nelson * other fields are set up by XPC. (xpc_rsvd_page points to the local
5645d9ca49SDean Nelson * partition's reserved page.)
5745d9ca49SDean Nelson *
5845d9ca49SDean Nelson * part_nasids mask
5945d9ca49SDean Nelson * mach_nasids mask
6045d9ca49SDean Nelson *
6145d9ca49SDean Nelson * SAL also sets up two bitmaps (or masks), one that reflects the actual
6245d9ca49SDean Nelson * nasids in this partition (part_nasids), and the other that reflects
6345d9ca49SDean Nelson * the actual nasids in the entire machine (mach_nasids). We're only
6445d9ca49SDean Nelson * interested in the even numbered nasids (which contain the processors
6545d9ca49SDean Nelson * and/or memory), so we only need half as many bits to represent the
6604de7418SDean Nelson * nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure
6704de7418SDean Nelson * to either divide or multiply by 2. The part_nasids mask is located
6804de7418SDean Nelson * starting at the first cacheline following the reserved page header. The
6904de7418SDean Nelson * mach_nasids mask follows right after the part_nasids mask. The size in
7004de7418SDean Nelson * bytes of each mask is reflected by the reserved page header field
7104de7418SDean Nelson * 'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids
7204de7418SDean Nelson * and xpc_mach_nasids.)
7345d9ca49SDean Nelson *
7445d9ca49SDean Nelson * Immediately following the mach_nasids mask are the XPC variables
7545d9ca49SDean Nelson * required by other partitions. First are those that are generic to all
7645d9ca49SDean Nelson * partitions (vars), followed on the next available cacheline by those
7745d9ca49SDean Nelson * which are partition specific (vars part). These are setup by XPC.
7845d9ca49SDean Nelson *
7981fe7883SDean Nelson * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been
8094bd2708SDean Nelson * initialized.
8145d9ca49SDean Nelson */
8245d9ca49SDean Nelson struct xpc_rsvd_page {
8345d9ca49SDean Nelson u64 SAL_signature; /* SAL: unique signature */
8445d9ca49SDean Nelson u64 SAL_version; /* SAL: version */
8594bd2708SDean Nelson short SAL_partid; /* SAL: partition ID */
8694bd2708SDean Nelson short max_npartitions; /* value of XPC_MAX_PARTITIONS */
8745d9ca49SDean Nelson u8 version;
8894bd2708SDean Nelson u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */
8981fe7883SDean Nelson unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
90a374c57bSRobin Holt union {
91a374c57bSRobin Holt struct {
92a374c57bSRobin Holt unsigned long heartbeat_gpa; /* phys addr */
93a374c57bSRobin Holt unsigned long activate_gru_mq_desc_gpa; /* phys addr */
94a374c57bSRobin Holt } uv;
95a374c57bSRobin Holt } sn;
96a374c57bSRobin Holt u64 pad2[9]; /* align to last u64 in 2nd 64-byte cacheline */
9794bd2708SDean Nelson u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */
9845d9ca49SDean Nelson };
9945d9ca49SDean Nelson
100a374c57bSRobin Holt #define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */
10145d9ca49SDean Nelson
10245d9ca49SDean Nelson /* the reserved page sizes and offsets */
10345d9ca49SDean Nelson
10445d9ca49SDean Nelson #define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
10545d9ca49SDean Nelson
106261f3b49SDean Nelson #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
107261f3b49SDean Nelson XPC_RP_HEADER_SIZE))
10804de7418SDean Nelson #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
10904de7418SDean Nelson xpc_nasid_mask_nlongs)
11045d9ca49SDean Nelson
111a374c57bSRobin Holt
112a374c57bSRobin Holt /*
113a374c57bSRobin Holt * The following structure describes the partition's heartbeat info which
114a374c57bSRobin Holt * will be periodically read by other partitions to determine whether this
115a374c57bSRobin Holt * XPC is still 'alive'.
116a374c57bSRobin Holt */
117a374c57bSRobin Holt struct xpc_heartbeat_uv {
118a374c57bSRobin Holt unsigned long value;
119a374c57bSRobin Holt unsigned long offline; /* if 0, heartbeat should be changing */
120a374c57bSRobin Holt };
121a374c57bSRobin Holt
12245d9ca49SDean Nelson /*
1232525789bSDean Nelson * Info pertinent to a GRU message queue using a watch list for irq generation.
1242525789bSDean Nelson */
1252525789bSDean Nelson struct xpc_gru_mq_uv {
1262525789bSDean Nelson void *address; /* address of GRU message queue */
1272525789bSDean Nelson unsigned int order; /* size of GRU message queue as a power of 2 */
1282525789bSDean Nelson int irq; /* irq raised when message is received in mq */
1292525789bSDean Nelson int mmr_blade; /* blade where watchlist was allocated from */
1302525789bSDean Nelson unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
1316f2584f4SJack Steiner unsigned long mmr_value; /* value of irq mmr located on mmr_blade */
1322525789bSDean Nelson int watchlist_num; /* number of watchlist allocatd by BIOS */
1336f2584f4SJack Steiner void *gru_mq_desc; /* opaque structure used by the GRU driver */
1342525789bSDean Nelson };
1352525789bSDean Nelson
1362525789bSDean Nelson /*
137bd3e64c1SDean Nelson * The activate_mq is used to send/receive GRU messages that affect XPC's
138a374c57bSRobin Holt * partition active state and channel state. This is uv only.
1395b8669dfSDean Nelson */
1405b8669dfSDean Nelson struct xpc_activate_mq_msghdr_uv {
1416f2584f4SJack Steiner unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
1425b8669dfSDean Nelson short partid; /* sender's partid */
1435b8669dfSDean Nelson u8 act_state; /* sender's act_state at time msg sent */
1445b8669dfSDean Nelson u8 type; /* message's type */
1455b8669dfSDean Nelson unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */
1465b8669dfSDean Nelson };
1475b8669dfSDean Nelson
1485b8669dfSDean Nelson /* activate_mq defined message types */
1495b8669dfSDean Nelson #define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV 0
1505b8669dfSDean Nelson
151a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV 1
152a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV 2
1535b8669dfSDean Nelson
154a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV 3
155a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV 4
156a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV 5
157a374c57bSRobin Holt #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV 6
158efdd06edSRobin Holt #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV 7
1595b8669dfSDean Nelson
160efdd06edSRobin Holt #define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV 8
161efdd06edSRobin Holt #define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV 9
1625b8669dfSDean Nelson
1635b8669dfSDean Nelson struct xpc_activate_mq_msg_uv {
164bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1655b8669dfSDean Nelson };
1665b8669dfSDean Nelson
1675b8669dfSDean Nelson struct xpc_activate_mq_msg_activate_req_uv {
168bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1695b8669dfSDean Nelson unsigned long rp_gpa;
170a374c57bSRobin Holt unsigned long heartbeat_gpa;
1716f2584f4SJack Steiner unsigned long activate_gru_mq_desc_gpa;
1725b8669dfSDean Nelson };
1735b8669dfSDean Nelson
1745b8669dfSDean Nelson struct xpc_activate_mq_msg_deactivate_req_uv {
175bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1765b8669dfSDean Nelson enum xp_retval reason;
1775b8669dfSDean Nelson };
1785b8669dfSDean Nelson
1795b8669dfSDean Nelson struct xpc_activate_mq_msg_chctl_closerequest_uv {
180bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1815b8669dfSDean Nelson short ch_number;
1825b8669dfSDean Nelson enum xp_retval reason;
1835b8669dfSDean Nelson };
1845b8669dfSDean Nelson
1855b8669dfSDean Nelson struct xpc_activate_mq_msg_chctl_closereply_uv {
186bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1875b8669dfSDean Nelson short ch_number;
1885b8669dfSDean Nelson };
1895b8669dfSDean Nelson
1905b8669dfSDean Nelson struct xpc_activate_mq_msg_chctl_openrequest_uv {
191bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1925b8669dfSDean Nelson short ch_number;
193bd3e64c1SDean Nelson short entry_size; /* size of notify_mq's GRU messages */
1945b8669dfSDean Nelson short local_nentries; /* ??? Is this needed? What is? */
1955b8669dfSDean Nelson };
1965b8669dfSDean Nelson
1975b8669dfSDean Nelson struct xpc_activate_mq_msg_chctl_openreply_uv {
198bd3e64c1SDean Nelson struct xpc_activate_mq_msghdr_uv hdr;
1995b8669dfSDean Nelson short ch_number;
2005b8669dfSDean Nelson short remote_nentries; /* ??? Is this needed? What is? */
2015b8669dfSDean Nelson short local_nentries; /* ??? Is this needed? What is? */
2026f2584f4SJack Steiner unsigned long notify_gru_mq_desc_gpa;
2035b8669dfSDean Nelson };
2045b8669dfSDean Nelson
205efdd06edSRobin Holt struct xpc_activate_mq_msg_chctl_opencomplete_uv {
206efdd06edSRobin Holt struct xpc_activate_mq_msghdr_uv hdr;
207efdd06edSRobin Holt short ch_number;
208efdd06edSRobin Holt };
209efdd06edSRobin Holt
2105b8669dfSDean Nelson /*
21145d9ca49SDean Nelson * Functions registered by add_timer() or called by kernel_thread() only
21245d9ca49SDean Nelson * allow for a single 64-bit argument. The following macros can be used to
21345d9ca49SDean Nelson * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
21445d9ca49SDean Nelson * the passed argument.
21545d9ca49SDean Nelson */
21645d9ca49SDean Nelson #define XPC_PACK_ARGS(_arg1, _arg2) \
21745d9ca49SDean Nelson ((((u64)_arg1) & 0xffffffff) | \
21845d9ca49SDean Nelson ((((u64)_arg2) & 0xffffffff) << 32))
21945d9ca49SDean Nelson
22045d9ca49SDean Nelson #define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff)
22145d9ca49SDean Nelson #define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff)
22245d9ca49SDean Nelson
22345d9ca49SDean Nelson /*
22445d9ca49SDean Nelson * Define a structure that contains arguments associated with opening and
22545d9ca49SDean Nelson * closing a channel.
22645d9ca49SDean Nelson */
22745d9ca49SDean Nelson struct xpc_openclose_args {
22845d9ca49SDean Nelson u16 reason; /* reason why channel is closing */
229bd3e64c1SDean Nelson u16 entry_size; /* sizeof each message entry */
23045d9ca49SDean Nelson u16 remote_nentries; /* #of message entries in remote msg queue */
23145d9ca49SDean Nelson u16 local_nentries; /* #of message entries in local msg queue */
232a812dcc3SDean Nelson unsigned long local_msgqueue_pa; /* phys addr of local message queue */
23345d9ca49SDean Nelson };
23445d9ca49SDean Nelson
23545d9ca49SDean Nelson #define XPC_OPENCLOSE_ARGS_SIZE \
236bc63d387SDean Nelson L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
237bc63d387SDean Nelson XPC_MAX_NCHANNELS)
23845d9ca49SDean Nelson
23945d9ca49SDean Nelson
24045d9ca49SDean Nelson /*
241bd3e64c1SDean Nelson * Structures to define a fifo singly-linked list.
242bd3e64c1SDean Nelson */
243bd3e64c1SDean Nelson
244bd3e64c1SDean Nelson struct xpc_fifo_entry_uv {
245bd3e64c1SDean Nelson struct xpc_fifo_entry_uv *next;
246bd3e64c1SDean Nelson };
247bd3e64c1SDean Nelson
248bd3e64c1SDean Nelson struct xpc_fifo_head_uv {
249bd3e64c1SDean Nelson struct xpc_fifo_entry_uv *first;
250bd3e64c1SDean Nelson struct xpc_fifo_entry_uv *last;
251bd3e64c1SDean Nelson spinlock_t lock;
252bd3e64c1SDean Nelson int n_entries;
253bd3e64c1SDean Nelson };
254bd3e64c1SDean Nelson
255bd3e64c1SDean Nelson /*
256bd3e64c1SDean Nelson * The format of a uv XPC notify_mq GRU message is as follows:
257bd3e64c1SDean Nelson *
258bd3e64c1SDean Nelson * A user-defined message resides in the payload area. The max size of the
259bd3e64c1SDean Nelson * payload is defined by the user via xpc_connect().
260bd3e64c1SDean Nelson *
261bd3e64c1SDean Nelson * The size of a message (payload and header) sent via the GRU must be either 1
262bd3e64c1SDean Nelson * or 2 GRU_CACHE_LINE_BYTES in length.
263bd3e64c1SDean Nelson */
264bd3e64c1SDean Nelson
265bd3e64c1SDean Nelson struct xpc_notify_mq_msghdr_uv {
266bd3e64c1SDean Nelson union {
267bd3e64c1SDean Nelson unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
268bd3e64c1SDean Nelson struct xpc_fifo_entry_uv next; /* FOR XPC INTERNAL USE ONLY */
269bd3e64c1SDean Nelson } u;
270bd3e64c1SDean Nelson short partid; /* FOR XPC INTERNAL USE ONLY */
271bd3e64c1SDean Nelson u8 ch_number; /* FOR XPC INTERNAL USE ONLY */
272bd3e64c1SDean Nelson u8 size; /* FOR XPC INTERNAL USE ONLY */
273bd3e64c1SDean Nelson unsigned int msg_slot_number; /* FOR XPC INTERNAL USE ONLY */
274bd3e64c1SDean Nelson };
275bd3e64c1SDean Nelson
276bd3e64c1SDean Nelson struct xpc_notify_mq_msg_uv {
277bd3e64c1SDean Nelson struct xpc_notify_mq_msghdr_uv hdr;
278bd3e64c1SDean Nelson unsigned long payload;
279bd3e64c1SDean Nelson };
280bd3e64c1SDean Nelson
281bd3e64c1SDean Nelson /* struct xpc_notify_sn2 type of notification */
28245d9ca49SDean Nelson
28345d9ca49SDean Nelson #define XPC_N_CALL 0x01 /* notify function provided by user */
28445d9ca49SDean Nelson
28545d9ca49SDean Nelson /*
286bd3e64c1SDean Nelson * Define uv's version of the notify entry. It additionally is used to allocate
287bd3e64c1SDean Nelson * a msg slot on the remote partition into which is copied a sent message.
288bd3e64c1SDean Nelson */
289bd3e64c1SDean Nelson struct xpc_send_msg_slot_uv {
290bd3e64c1SDean Nelson struct xpc_fifo_entry_uv next;
291bd3e64c1SDean Nelson unsigned int msg_slot_number;
292bd3e64c1SDean Nelson xpc_notify_func func; /* user's notify function */
293bd3e64c1SDean Nelson void *key; /* pointer to user's key */
294bd3e64c1SDean Nelson };
295bd3e64c1SDean Nelson
296bd3e64c1SDean Nelson /*
29745d9ca49SDean Nelson * Define the structure that manages all the stuff required by a channel. In
29845d9ca49SDean Nelson * particular, they are used to manage the messages sent across the channel.
29945d9ca49SDean Nelson *
30045d9ca49SDean Nelson * This structure is private to a partition, and is NOT shared across the
30145d9ca49SDean Nelson * partition boundary.
30245d9ca49SDean Nelson *
30345d9ca49SDean Nelson * There is an array of these structures for each remote partition. It is
30445d9ca49SDean Nelson * allocated at the time a partition becomes active. The array contains one
30545d9ca49SDean Nelson * of these structures for each potential channel connection to that partition.
306ea57f80cSDean Nelson */
307ea57f80cSDean Nelson
308a47d5dacSDean Nelson struct xpc_channel_uv {
3096f2584f4SJack Steiner void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */
3106f2584f4SJack Steiner /* gru mq descriptor */
311bd3e64c1SDean Nelson
312bd3e64c1SDean Nelson struct xpc_send_msg_slot_uv *send_msg_slots;
313361916a9SDean Nelson void *recv_msg_slots; /* each slot will hold a xpc_notify_mq_msg_uv */
314361916a9SDean Nelson /* structure plus the user's payload */
315bd3e64c1SDean Nelson
316bd3e64c1SDean Nelson struct xpc_fifo_head_uv msg_slot_free_list;
317bd3e64c1SDean Nelson struct xpc_fifo_head_uv recv_msg_list; /* deliverable payloads */
318a47d5dacSDean Nelson };
319a47d5dacSDean Nelson
32045d9ca49SDean Nelson struct xpc_channel {
32164d032baSDean Nelson short partid; /* ID of remote partition connected */
32245d9ca49SDean Nelson spinlock_t lock; /* lock for updating this structure */
3235b8669dfSDean Nelson unsigned int flags; /* general flags */
32445d9ca49SDean Nelson
32565c17b80SDean Nelson enum xp_retval reason; /* reason why channel is disconnect'g */
32645d9ca49SDean Nelson int reason_line; /* line# disconnect initiated from */
32745d9ca49SDean Nelson
32845d9ca49SDean Nelson u16 number; /* channel # */
32945d9ca49SDean Nelson
330bd3e64c1SDean Nelson u16 entry_size; /* sizeof each msg entry */
33145d9ca49SDean Nelson u16 local_nentries; /* #of msg entries in local msg queue */
33245d9ca49SDean Nelson u16 remote_nentries; /* #of msg entries in remote msg queue */
33345d9ca49SDean Nelson
33445d9ca49SDean Nelson atomic_t references; /* #of external references to queues */
33545d9ca49SDean Nelson
33645d9ca49SDean Nelson atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
33745d9ca49SDean Nelson wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
33845d9ca49SDean Nelson
3397fb5e59dSDean Nelson u8 delayed_chctl_flags; /* chctl flags received, but delayed */
34045d9ca49SDean Nelson /* action until channel disconnected */
34145d9ca49SDean Nelson
34245d9ca49SDean Nelson atomic_t n_to_notify; /* #of msg senders to notify */
34345d9ca49SDean Nelson
34445d9ca49SDean Nelson xpc_channel_func func; /* user's channel function */
34545d9ca49SDean Nelson void *key; /* pointer to user's key */
34645d9ca49SDean Nelson
34745d9ca49SDean Nelson struct completion wdisconnect_wait; /* wait for channel disconnect */
34845d9ca49SDean Nelson
34945d9ca49SDean Nelson /* kthread management related fields */
35045d9ca49SDean Nelson
35145d9ca49SDean Nelson atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
35245d9ca49SDean Nelson u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
35345d9ca49SDean Nelson atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
35445d9ca49SDean Nelson u32 kthreads_idle_limit; /* limit on #of kthreads idle */
35545d9ca49SDean Nelson atomic_t kthreads_active; /* #of kthreads actively working */
35645d9ca49SDean Nelson
35745d9ca49SDean Nelson wait_queue_head_t idle_wq; /* idle kthread wait queue */
35845d9ca49SDean Nelson
359a47d5dacSDean Nelson union {
360a47d5dacSDean Nelson struct xpc_channel_uv uv;
361a47d5dacSDean Nelson } sn;
362a47d5dacSDean Nelson
36345d9ca49SDean Nelson } ____cacheline_aligned;
36445d9ca49SDean Nelson
36545d9ca49SDean Nelson /* struct xpc_channel flags */
36645d9ca49SDean Nelson
36745d9ca49SDean Nelson #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
36845d9ca49SDean Nelson
369efdd06edSRobin Holt #define XPC_C_ROPENCOMPLETE 0x00000002 /* remote open channel complete */
370efdd06edSRobin Holt #define XPC_C_OPENCOMPLETE 0x00000004 /* local open channel complete */
371efdd06edSRobin Holt #define XPC_C_ROPENREPLY 0x00000008 /* remote open channel reply */
372efdd06edSRobin Holt #define XPC_C_OPENREPLY 0x00000010 /* local open channel reply */
373efdd06edSRobin Holt #define XPC_C_ROPENREQUEST 0x00000020 /* remote open channel request */
374efdd06edSRobin Holt #define XPC_C_OPENREQUEST 0x00000040 /* local open channel request */
37545d9ca49SDean Nelson
376efdd06edSRobin Holt #define XPC_C_SETUP 0x00000080 /* channel's msgqueues are alloc'd */
377efdd06edSRobin Holt #define XPC_C_CONNECTEDCALLOUT 0x00000100 /* connected callout initiated */
37845d9ca49SDean Nelson #define XPC_C_CONNECTEDCALLOUT_MADE \
379efdd06edSRobin Holt 0x00000200 /* connected callout completed */
380efdd06edSRobin Holt #define XPC_C_CONNECTED 0x00000400 /* local channel is connected */
381efdd06edSRobin Holt #define XPC_C_CONNECTING 0x00000800 /* channel is being connected */
38245d9ca49SDean Nelson
383efdd06edSRobin Holt #define XPC_C_RCLOSEREPLY 0x00001000 /* remote close channel reply */
384efdd06edSRobin Holt #define XPC_C_CLOSEREPLY 0x00002000 /* local close channel reply */
385efdd06edSRobin Holt #define XPC_C_RCLOSEREQUEST 0x00004000 /* remote close channel request */
386efdd06edSRobin Holt #define XPC_C_CLOSEREQUEST 0x00008000 /* local close channel request */
38745d9ca49SDean Nelson
388efdd06edSRobin Holt #define XPC_C_DISCONNECTED 0x00010000 /* channel is disconnected */
389efdd06edSRobin Holt #define XPC_C_DISCONNECTING 0x00020000 /* channel is being disconnected */
39045d9ca49SDean Nelson #define XPC_C_DISCONNECTINGCALLOUT \
391efdd06edSRobin Holt 0x00040000 /* disconnecting callout initiated */
39245d9ca49SDean Nelson #define XPC_C_DISCONNECTINGCALLOUT_MADE \
393efdd06edSRobin Holt 0x00080000 /* disconnecting callout completed */
394efdd06edSRobin Holt #define XPC_C_WDISCONNECT 0x00100000 /* waiting for channel disconnect */
39545d9ca49SDean Nelson
39645d9ca49SDean Nelson /*
3977fb5e59dSDean Nelson * The channel control flags (chctl) union consists of a 64-bit variable which
3987fb5e59dSDean Nelson * is divided up into eight bytes, ordered from right to left. Byte zero
3997fb5e59dSDean Nelson * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
4007fb5e59dSDean Nelson * can have one or more of the chctl flags set in it.
4017fb5e59dSDean Nelson */
4027fb5e59dSDean Nelson
4037fb5e59dSDean Nelson union xpc_channel_ctl_flags {
4047fb5e59dSDean Nelson u64 all_flags;
4057fb5e59dSDean Nelson u8 flags[XPC_MAX_NCHANNELS];
4067fb5e59dSDean Nelson };
4077fb5e59dSDean Nelson
4087fb5e59dSDean Nelson /* chctl flags */
4097fb5e59dSDean Nelson #define XPC_CHCTL_CLOSEREQUEST 0x01
4107fb5e59dSDean Nelson #define XPC_CHCTL_CLOSEREPLY 0x02
4117fb5e59dSDean Nelson #define XPC_CHCTL_OPENREQUEST 0x04
4127fb5e59dSDean Nelson #define XPC_CHCTL_OPENREPLY 0x08
413efdd06edSRobin Holt #define XPC_CHCTL_OPENCOMPLETE 0x10
414efdd06edSRobin Holt #define XPC_CHCTL_MSGREQUEST 0x20
4157fb5e59dSDean Nelson
4167fb5e59dSDean Nelson #define XPC_OPENCLOSE_CHCTL_FLAGS \
4177fb5e59dSDean Nelson (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
418efdd06edSRobin Holt XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \
419efdd06edSRobin Holt XPC_CHCTL_OPENCOMPLETE)
4207fb5e59dSDean Nelson #define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST
4217fb5e59dSDean Nelson
4227fb5e59dSDean Nelson static inline int
xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags * chctl)4237fb5e59dSDean Nelson xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
4247fb5e59dSDean Nelson {
4257fb5e59dSDean Nelson int ch_number;
4267fb5e59dSDean Nelson
4277fb5e59dSDean Nelson for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
4287fb5e59dSDean Nelson if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
4297fb5e59dSDean Nelson return 1;
4307fb5e59dSDean Nelson }
4317fb5e59dSDean Nelson return 0;
4327fb5e59dSDean Nelson }
4337fb5e59dSDean Nelson
4347fb5e59dSDean Nelson static inline int
xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags * chctl)4357fb5e59dSDean Nelson xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
4367fb5e59dSDean Nelson {
4377fb5e59dSDean Nelson int ch_number;
4387fb5e59dSDean Nelson
4397fb5e59dSDean Nelson for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
4407fb5e59dSDean Nelson if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
4417fb5e59dSDean Nelson return 1;
4427fb5e59dSDean Nelson }
4437fb5e59dSDean Nelson return 0;
4447fb5e59dSDean Nelson }
4457fb5e59dSDean Nelson
446a47d5dacSDean Nelson struct xpc_partition_uv {
447a374c57bSRobin Holt unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */
448a374c57bSRobin Holt struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */
449a374c57bSRobin Holt /* partition's heartbeat */
4506f2584f4SJack Steiner unsigned long activate_gru_mq_desc_gpa; /* phys addr of parititon's */
4516f2584f4SJack Steiner /* activate mq's gru mq */
4526f2584f4SJack Steiner /* descriptor */
4536f2584f4SJack Steiner void *cached_activate_gru_mq_desc; /* cached copy of partition's */
4546f2584f4SJack Steiner /* activate mq's gru mq descriptor */
4556f2584f4SJack Steiner struct mutex cached_activate_gru_mq_desc_mutex;
4565b8669dfSDean Nelson spinlock_t flags_lock; /* protect updating of flags */
4575b8669dfSDean Nelson unsigned int flags; /* general flags */
4585b8669dfSDean Nelson u8 remote_act_state; /* remote partition's act_state */
4595b8669dfSDean Nelson u8 act_state_req; /* act_state request from remote partition */
4605b8669dfSDean Nelson enum xp_retval reason; /* reason for deactivate act_state request */
461a47d5dacSDean Nelson };
462a47d5dacSDean Nelson
4635b8669dfSDean Nelson /* struct xpc_partition_uv flags */
4645b8669dfSDean Nelson
465a374c57bSRobin Holt #define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV 0x00000001
4665b8669dfSDean Nelson #define XPC_P_ENGAGED_UV 0x00000002
4675b8669dfSDean Nelson
4685b8669dfSDean Nelson /* struct xpc_partition_uv act_state change requests */
4695b8669dfSDean Nelson
4705b8669dfSDean Nelson #define XPC_P_ASR_ACTIVATE_UV 0x01
4715b8669dfSDean Nelson #define XPC_P_ASR_REACTIVATE_UV 0x02
4725b8669dfSDean Nelson #define XPC_P_ASR_DEACTIVATE_UV 0x03
4735b8669dfSDean Nelson
47445d9ca49SDean Nelson struct xpc_partition {
47545d9ca49SDean Nelson
47645d9ca49SDean Nelson /* XPC HB infrastructure */
47745d9ca49SDean Nelson
47845d9ca49SDean Nelson u8 remote_rp_version; /* version# of partition's rsvd pg */
47981fe7883SDean Nelson unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
480a812dcc3SDean Nelson unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */
48145d9ca49SDean Nelson u64 last_heartbeat; /* HB at last read */
4826e41017aSDean Nelson u32 activate_IRQ_rcvd; /* IRQs since activation */
48345d9ca49SDean Nelson spinlock_t act_lock; /* protect updating of act_state */
48445d9ca49SDean Nelson u8 act_state; /* from XPC HB viewpoint */
48565c17b80SDean Nelson enum xp_retval reason; /* reason partition is deactivating */
48645d9ca49SDean Nelson int reason_line; /* line# deactivation initiated from */
48745d9ca49SDean Nelson
488a47d5dacSDean Nelson unsigned long disengage_timeout; /* timeout in jiffies */
489a47d5dacSDean Nelson struct timer_list disengage_timer;
49045d9ca49SDean Nelson
49145d9ca49SDean Nelson /* XPC infrastructure referencing and teardown control */
49245d9ca49SDean Nelson
4932c2b94f9SDean Nelson u8 setup_state; /* infrastructure setup state */
49445d9ca49SDean Nelson wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
49545d9ca49SDean Nelson atomic_t references; /* #of references to infrastructure */
49645d9ca49SDean Nelson
49745d9ca49SDean Nelson u8 nchannels; /* #of defined channels supported */
49845d9ca49SDean Nelson atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
49945d9ca49SDean Nelson atomic_t nchannels_engaged; /* #of channels engaged with remote part */
50045d9ca49SDean Nelson struct xpc_channel *channels; /* array of channel structures */
50145d9ca49SDean Nelson
5027fb5e59dSDean Nelson /* fields used for managing channel avialability and activity */
5037fb5e59dSDean Nelson
5047fb5e59dSDean Nelson union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
5057fb5e59dSDean Nelson spinlock_t chctl_lock; /* chctl flags lock */
50645d9ca49SDean Nelson
50745d9ca49SDean Nelson void *remote_openclose_args_base; /* base address of kmalloc'd space */
50845d9ca49SDean Nelson struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
50945d9ca49SDean Nelson /* args */
51045d9ca49SDean Nelson
51145d9ca49SDean Nelson /* channel manager related fields */
51245d9ca49SDean Nelson
51345d9ca49SDean Nelson atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
51445d9ca49SDean Nelson wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
51545d9ca49SDean Nelson
516a47d5dacSDean Nelson union {
517a47d5dacSDean Nelson struct xpc_partition_uv uv;
518a47d5dacSDean Nelson } sn;
519a47d5dacSDean Nelson
52045d9ca49SDean Nelson } ____cacheline_aligned;
52145d9ca49SDean Nelson
522a7665b0aSRobin Holt struct xpc_arch_operations {
523a7665b0aSRobin Holt int (*setup_partitions) (void);
524a7665b0aSRobin Holt void (*teardown_partitions) (void);
525a7665b0aSRobin Holt void (*process_activate_IRQ_rcvd) (void);
526a7665b0aSRobin Holt enum xp_retval (*get_partition_rsvd_page_pa)
527a7665b0aSRobin Holt (void *, u64 *, unsigned long *, size_t *);
528a7665b0aSRobin Holt int (*setup_rsvd_page) (struct xpc_rsvd_page *);
529a7665b0aSRobin Holt
530a7665b0aSRobin Holt void (*allow_hb) (short);
531a7665b0aSRobin Holt void (*disallow_hb) (short);
532a7665b0aSRobin Holt void (*disallow_all_hbs) (void);
533a7665b0aSRobin Holt void (*increment_heartbeat) (void);
534a7665b0aSRobin Holt void (*offline_heartbeat) (void);
535a7665b0aSRobin Holt void (*online_heartbeat) (void);
536a7665b0aSRobin Holt void (*heartbeat_init) (void);
537a7665b0aSRobin Holt void (*heartbeat_exit) (void);
538a7665b0aSRobin Holt enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);
539a7665b0aSRobin Holt
540a7665b0aSRobin Holt void (*request_partition_activation) (struct xpc_rsvd_page *,
541a7665b0aSRobin Holt unsigned long, int);
542a7665b0aSRobin Holt void (*request_partition_reactivation) (struct xpc_partition *);
543a7665b0aSRobin Holt void (*request_partition_deactivation) (struct xpc_partition *);
544a7665b0aSRobin Holt void (*cancel_partition_deactivation_request) (struct xpc_partition *);
545a7665b0aSRobin Holt enum xp_retval (*setup_ch_structures) (struct xpc_partition *);
546a7665b0aSRobin Holt void (*teardown_ch_structures) (struct xpc_partition *);
547a7665b0aSRobin Holt
548a7665b0aSRobin Holt enum xp_retval (*make_first_contact) (struct xpc_partition *);
549a7665b0aSRobin Holt
550a7665b0aSRobin Holt u64 (*get_chctl_all_flags) (struct xpc_partition *);
551a7665b0aSRobin Holt void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);
552a7665b0aSRobin Holt void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);
553a7665b0aSRobin Holt void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);
554a7665b0aSRobin Holt void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);
555a7665b0aSRobin Holt void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);
556a7665b0aSRobin Holt void (*process_msg_chctl_flags) (struct xpc_partition *, int);
557a7665b0aSRobin Holt
558a7665b0aSRobin Holt enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,
559a7665b0aSRobin Holt unsigned long);
560a7665b0aSRobin Holt
561a7665b0aSRobin Holt enum xp_retval (*setup_msg_structures) (struct xpc_channel *);
562a7665b0aSRobin Holt void (*teardown_msg_structures) (struct xpc_channel *);
563a7665b0aSRobin Holt
564a7665b0aSRobin Holt void (*indicate_partition_engaged) (struct xpc_partition *);
565a7665b0aSRobin Holt void (*indicate_partition_disengaged) (struct xpc_partition *);
566a7665b0aSRobin Holt void (*assume_partition_disengaged) (short);
567a7665b0aSRobin Holt int (*partition_engaged) (short);
568a7665b0aSRobin Holt int (*any_partition_engaged) (void);
569a7665b0aSRobin Holt
570a7665b0aSRobin Holt int (*n_of_deliverable_payloads) (struct xpc_channel *);
571a7665b0aSRobin Holt enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,
572a7665b0aSRobin Holt u16, u8, xpc_notify_func, void *);
573a7665b0aSRobin Holt void *(*get_deliverable_payload) (struct xpc_channel *);
574a7665b0aSRobin Holt void (*received_payload) (struct xpc_channel *, void *);
575a7665b0aSRobin Holt void (*notify_senders_of_disconnect) (struct xpc_channel *);
576a7665b0aSRobin Holt };
577a7665b0aSRobin Holt
57845d9ca49SDean Nelson /* struct xpc_partition act_state values (for XPC HB) */
57945d9ca49SDean Nelson
58083469b55SDean Nelson #define XPC_P_AS_INACTIVE 0x00 /* partition is not active */
58183469b55SDean Nelson #define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */
58283469b55SDean Nelson #define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */
58383469b55SDean Nelson #define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */
58483469b55SDean Nelson #define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */
58545d9ca49SDean Nelson
58645d9ca49SDean Nelson #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
58745d9ca49SDean Nelson xpc_deactivate_partition(__LINE__, (_p), (_reason))
58845d9ca49SDean Nelson
58945d9ca49SDean Nelson /* struct xpc_partition setup_state values */
59045d9ca49SDean Nelson
59183469b55SDean Nelson #define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */
59283469b55SDean Nelson #define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */
59383469b55SDean Nelson #define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
59483469b55SDean Nelson #define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */
59545d9ca49SDean Nelson
59645d9ca49SDean Nelson /* number of seconds to wait for other partitions to disengage */
597a47d5dacSDean Nelson #define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90
59845d9ca49SDean Nelson
599a47d5dacSDean Nelson /* interval in seconds to print 'waiting deactivation' messages */
600a47d5dacSDean Nelson #define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10
60145d9ca49SDean Nelson
60264d032baSDean Nelson #define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0]))
60345d9ca49SDean Nelson
60445d9ca49SDean Nelson /* found in xp_main.c */
60545d9ca49SDean Nelson extern struct xpc_registration xpc_registrations[];
60645d9ca49SDean Nelson
60745d9ca49SDean Nelson /* found in xpc_main.c */
60845d9ca49SDean Nelson extern struct device *xpc_part;
60945d9ca49SDean Nelson extern struct device *xpc_chan;
610a7665b0aSRobin Holt extern struct xpc_arch_operations xpc_arch_ops;
611a47d5dacSDean Nelson extern int xpc_disengage_timelimit;
612a47d5dacSDean Nelson extern int xpc_disengage_timedout;
6135b8669dfSDean Nelson extern int xpc_activate_IRQ_rcvd;
6145b8669dfSDean Nelson extern spinlock_t xpc_activate_IRQ_rcvd_lock;
6156e41017aSDean Nelson extern wait_queue_head_t xpc_activate_IRQ_wq;
6165b8669dfSDean Nelson extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
61745d9ca49SDean Nelson extern void xpc_activate_partition(struct xpc_partition *);
61845d9ca49SDean Nelson extern void xpc_activate_kthreads(struct xpc_channel *, int);
61945d9ca49SDean Nelson extern void xpc_create_kthreads(struct xpc_channel *, int, int);
62045d9ca49SDean Nelson extern void xpc_disconnect_wait(int);
62194bd2708SDean Nelson
62294bd2708SDean Nelson /* found in xpc_uv.c */
6235b8669dfSDean Nelson extern int xpc_init_uv(void);
6246e41017aSDean Nelson extern void xpc_exit_uv(void);
62594bd2708SDean Nelson
62645d9ca49SDean Nelson /* found in xpc_partition.c */
62745d9ca49SDean Nelson extern int xpc_exiting;
62804de7418SDean Nelson extern int xpc_nasid_mask_nlongs;
62945d9ca49SDean Nelson extern struct xpc_rsvd_page *xpc_rsvd_page;
63004de7418SDean Nelson extern unsigned long *xpc_mach_nasids;
631bc63d387SDean Nelson extern struct xpc_partition *xpc_partitions;
63245d9ca49SDean Nelson extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
6335b8669dfSDean Nelson extern int xpc_setup_rsvd_page(void);
6345b8669dfSDean Nelson extern void xpc_teardown_rsvd_page(void);
6356e41017aSDean Nelson extern int xpc_identify_activate_IRQ_sender(void);
63645d9ca49SDean Nelson extern int xpc_partition_disengaged(struct xpc_partition *);
637*997754f1SThomas Gleixner extern int xpc_partition_disengaged_from_timer(struct xpc_partition *part);
63865c17b80SDean Nelson extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
63945d9ca49SDean Nelson extern void xpc_mark_partition_inactive(struct xpc_partition *);
64045d9ca49SDean Nelson extern void xpc_discovery(void);
64104de7418SDean Nelson extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
642a812dcc3SDean Nelson struct xpc_rsvd_page *,
643a812dcc3SDean Nelson unsigned long *);
64445d9ca49SDean Nelson extern void xpc_deactivate_partition(const int, struct xpc_partition *,
64565c17b80SDean Nelson enum xp_retval);
64664d032baSDean Nelson extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
64745d9ca49SDean Nelson
64845d9ca49SDean Nelson /* found in xpc_channel.c */
64945d9ca49SDean Nelson extern void xpc_initiate_connect(int);
65045d9ca49SDean Nelson extern void xpc_initiate_disconnect(int);
65133ba3c77SDean Nelson extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
65297bf1aa1SDean Nelson extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
65397bf1aa1SDean Nelson extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
65445d9ca49SDean Nelson xpc_notify_func, void *);
65564d032baSDean Nelson extern void xpc_initiate_received(short, int, void *);
6567fb5e59dSDean Nelson extern void xpc_process_sent_chctl_flags(struct xpc_partition *);
65745d9ca49SDean Nelson extern void xpc_connected_callout(struct xpc_channel *);
658bd3e64c1SDean Nelson extern void xpc_deliver_payload(struct xpc_channel *);
65945d9ca49SDean Nelson extern void xpc_disconnect_channel(const int, struct xpc_channel *,
66065c17b80SDean Nelson enum xp_retval, unsigned long *);
66165c17b80SDean Nelson extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
66265c17b80SDean Nelson extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
66345d9ca49SDean Nelson
66445d9ca49SDean Nelson static inline void
xpc_wakeup_channel_mgr(struct xpc_partition * part)66545d9ca49SDean Nelson xpc_wakeup_channel_mgr(struct xpc_partition *part)
66645d9ca49SDean Nelson {
6672c2b94f9SDean Nelson if (atomic_inc_return(&part->channel_mgr_requests) == 1)
66845d9ca49SDean Nelson wake_up(&part->channel_mgr_wq);
66945d9ca49SDean Nelson }
67045d9ca49SDean Nelson
67145d9ca49SDean Nelson /*
67245d9ca49SDean Nelson * These next two inlines are used to keep us from tearing down a channel's
67345d9ca49SDean Nelson * msg queues while a thread may be referencing them.
67445d9ca49SDean Nelson */
67545d9ca49SDean Nelson static inline void
xpc_msgqueue_ref(struct xpc_channel * ch)67645d9ca49SDean Nelson xpc_msgqueue_ref(struct xpc_channel *ch)
67745d9ca49SDean Nelson {
67845d9ca49SDean Nelson atomic_inc(&ch->references);
67945d9ca49SDean Nelson }
68045d9ca49SDean Nelson
68145d9ca49SDean Nelson static inline void
xpc_msgqueue_deref(struct xpc_channel * ch)68245d9ca49SDean Nelson xpc_msgqueue_deref(struct xpc_channel *ch)
68345d9ca49SDean Nelson {
68445d9ca49SDean Nelson s32 refs = atomic_dec_return(&ch->references);
68545d9ca49SDean Nelson
68645d9ca49SDean Nelson DBUG_ON(refs < 0);
6872c2b94f9SDean Nelson if (refs == 0)
68845d9ca49SDean Nelson xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
68945d9ca49SDean Nelson }
69045d9ca49SDean Nelson
69145d9ca49SDean Nelson #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
69245d9ca49SDean Nelson xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
69345d9ca49SDean Nelson
69445d9ca49SDean Nelson /*
69545d9ca49SDean Nelson * These two inlines are used to keep us from tearing down a partition's
69645d9ca49SDean Nelson * setup infrastructure while a thread may be referencing it.
69745d9ca49SDean Nelson */
69845d9ca49SDean Nelson static inline void
xpc_part_deref(struct xpc_partition * part)69945d9ca49SDean Nelson xpc_part_deref(struct xpc_partition *part)
70045d9ca49SDean Nelson {
70145d9ca49SDean Nelson s32 refs = atomic_dec_return(&part->references);
70245d9ca49SDean Nelson
70345d9ca49SDean Nelson DBUG_ON(refs < 0);
70483469b55SDean Nelson if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)
70545d9ca49SDean Nelson wake_up(&part->teardown_wq);
70645d9ca49SDean Nelson }
70745d9ca49SDean Nelson
70845d9ca49SDean Nelson static inline int
xpc_part_ref(struct xpc_partition * part)70945d9ca49SDean Nelson xpc_part_ref(struct xpc_partition *part)
71045d9ca49SDean Nelson {
71145d9ca49SDean Nelson int setup;
71245d9ca49SDean Nelson
71345d9ca49SDean Nelson atomic_inc(&part->references);
71483469b55SDean Nelson setup = (part->setup_state == XPC_P_SS_SETUP);
7152c2b94f9SDean Nelson if (!setup)
71645d9ca49SDean Nelson xpc_part_deref(part);
7172c2b94f9SDean Nelson
71845d9ca49SDean Nelson return setup;
71945d9ca49SDean Nelson }
72045d9ca49SDean Nelson
72145d9ca49SDean Nelson /*
72245d9ca49SDean Nelson * The following macro is to be used for the setting of the reason and
72345d9ca49SDean Nelson * reason_line fields in both the struct xpc_channel and struct xpc_partition
72445d9ca49SDean Nelson * structures.
72545d9ca49SDean Nelson */
72645d9ca49SDean Nelson #define XPC_SET_REASON(_p, _reason, _line) \
72745d9ca49SDean Nelson { \
72845d9ca49SDean Nelson (_p)->reason = _reason; \
72945d9ca49SDean Nelson (_p)->reason_line = _line; \
73045d9ca49SDean Nelson }
73145d9ca49SDean Nelson
73245d9ca49SDean Nelson #endif /* _DRIVERS_MISC_SGIXP_XPC_H */
733