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 * 645d9ca49SDean Nelson * Copyright (c) 2004-2008 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 * 7494bd2708SDean Nelson * vars (ia64-sn2 only) 7594bd2708SDean Nelson * vars part (ia64-sn2 only) 7645d9ca49SDean Nelson * 7745d9ca49SDean Nelson * Immediately following the mach_nasids mask are the XPC variables 7845d9ca49SDean Nelson * required by other partitions. First are those that are generic to all 7945d9ca49SDean Nelson * partitions (vars), followed on the next available cacheline by those 8045d9ca49SDean Nelson * which are partition specific (vars part). These are setup by XPC. 8145d9ca49SDean Nelson * (Local partition's vars pointers are xpc_vars and xpc_vars_part.) 8245d9ca49SDean Nelson * 8381fe7883SDean Nelson * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been 8494bd2708SDean Nelson * initialized. 8545d9ca49SDean Nelson */ 8645d9ca49SDean Nelson struct xpc_rsvd_page { 8745d9ca49SDean Nelson u64 SAL_signature; /* SAL: unique signature */ 8845d9ca49SDean Nelson u64 SAL_version; /* SAL: version */ 8994bd2708SDean Nelson short SAL_partid; /* SAL: partition ID */ 9094bd2708SDean Nelson short max_npartitions; /* value of XPC_MAX_PARTITIONS */ 9145d9ca49SDean Nelson u8 version; 9294bd2708SDean Nelson u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */ 9394bd2708SDean Nelson union { 94a812dcc3SDean Nelson unsigned long vars_pa; /* phys address of struct xpc_vars */ 95a812dcc3SDean Nelson unsigned long activate_mq_gpa; /* gru phy addr of activate_mq */ 9694bd2708SDean Nelson } sn; 9781fe7883SDean Nelson unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */ 98aaa3cd69SDean Nelson u64 pad2[10]; /* align to last u64 in 2nd 64-byte cacheline */ 9994bd2708SDean Nelson u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */ 10045d9ca49SDean Nelson }; 10145d9ca49SDean Nelson 10294bd2708SDean Nelson #define XPC_RP_VERSION _XPC_VERSION(2, 0) /* version 2.0 of the reserved page */ 10345d9ca49SDean Nelson 10445d9ca49SDean Nelson /* 10545d9ca49SDean Nelson * Define the structures by which XPC variables can be exported to other 10645d9ca49SDean Nelson * partitions. (There are two: struct xpc_vars and struct xpc_vars_part) 10745d9ca49SDean Nelson */ 10845d9ca49SDean Nelson 10945d9ca49SDean Nelson /* 11045d9ca49SDean Nelson * The following structure describes the partition generic variables 11145d9ca49SDean Nelson * needed by other partitions in order to properly initialize. 11245d9ca49SDean Nelson * 11345d9ca49SDean Nelson * struct xpc_vars version number also applies to struct xpc_vars_part. 11445d9ca49SDean Nelson * Changes to either structure and/or related functionality should be 11545d9ca49SDean Nelson * reflected by incrementing either the major or minor version numbers 11645d9ca49SDean Nelson * of struct xpc_vars. 11745d9ca49SDean Nelson */ 11833ba3c77SDean Nelson struct xpc_vars_sn2 { 11945d9ca49SDean Nelson u8 version; 12045d9ca49SDean Nelson u64 heartbeat; 12133ba3c77SDean Nelson DECLARE_BITMAP(heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2); 12245d9ca49SDean Nelson u64 heartbeat_offline; /* if 0, heartbeat should be changing */ 123a47d5dacSDean Nelson int activate_IRQ_nasid; 124a47d5dacSDean Nelson int activate_IRQ_phys_cpuid; 125a812dcc3SDean Nelson unsigned long vars_part_pa; 126a812dcc3SDean Nelson unsigned long amos_page_pa;/* paddr of page of amos from MSPEC driver */ 127c39838ceSDean Nelson struct amo *amos_page; /* vaddr of page of amos from MSPEC driver */ 12845d9ca49SDean Nelson }; 12945d9ca49SDean Nelson 13045d9ca49SDean Nelson #define XPC_V_VERSION _XPC_VERSION(3, 1) /* version 3.1 of the cross vars */ 13145d9ca49SDean Nelson 13245d9ca49SDean Nelson /* 13345d9ca49SDean Nelson * The following structure describes the per partition specific variables. 13445d9ca49SDean Nelson * 13545d9ca49SDean Nelson * An array of these structures, one per partition, will be defined. As a 13645d9ca49SDean Nelson * partition becomes active XPC will copy the array entry corresponding to 13794bd2708SDean Nelson * itself from that partition. It is desirable that the size of this structure 13894bd2708SDean Nelson * evenly divides into a 128-byte cacheline, such that none of the entries in 13994bd2708SDean Nelson * this array crosses a 128-byte cacheline boundary. As it is now, each entry 140e17d416bSDean Nelson * occupies 64-bytes. 14145d9ca49SDean Nelson */ 142e17d416bSDean Nelson struct xpc_vars_part_sn2 { 1432c2b94f9SDean Nelson u64 magic; 14445d9ca49SDean Nelson 145a812dcc3SDean Nelson unsigned long openclose_args_pa; /* phys addr of open and close args */ 146a812dcc3SDean Nelson unsigned long GPs_pa; /* physical address of Get/Put values */ 14745d9ca49SDean Nelson 148a812dcc3SDean Nelson unsigned long chctl_amo_pa; /* physical address of chctl flags' amo */ 1497fb5e59dSDean Nelson 1507fb5e59dSDean Nelson int notify_IRQ_nasid; /* nasid of where to send notify IRQs */ 1517fb5e59dSDean Nelson int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */ 15245d9ca49SDean Nelson 15345d9ca49SDean Nelson u8 nchannels; /* #of defined channels supported */ 15445d9ca49SDean Nelson 15545d9ca49SDean Nelson u8 reserved[23]; /* pad to a full 64 bytes */ 15645d9ca49SDean Nelson }; 15745d9ca49SDean Nelson 15845d9ca49SDean Nelson /* 15945d9ca49SDean Nelson * The vars_part MAGIC numbers play a part in the first contact protocol. 16045d9ca49SDean Nelson * 16145d9ca49SDean Nelson * MAGIC1 indicates that the per partition specific variables for a remote 16245d9ca49SDean Nelson * partition have been initialized by this partition. 16345d9ca49SDean Nelson * 16445d9ca49SDean Nelson * MAGIC2 indicates that this partition has pulled the remote partititions 16545d9ca49SDean Nelson * per partition variables that pertain to this partition. 16645d9ca49SDean Nelson */ 16745d9ca49SDean Nelson #define XPC_VP_MAGIC1 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */ 16845d9ca49SDean Nelson #define XPC_VP_MAGIC2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */ 16945d9ca49SDean Nelson 17045d9ca49SDean Nelson /* the reserved page sizes and offsets */ 17145d9ca49SDean Nelson 17245d9ca49SDean Nelson #define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)) 17333ba3c77SDean Nelson #define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars_sn2)) 17445d9ca49SDean Nelson 175261f3b49SDean Nelson #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \ 176261f3b49SDean Nelson XPC_RP_HEADER_SIZE)) 17704de7418SDean Nelson #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \ 17804de7418SDean Nelson xpc_nasid_mask_nlongs) 179ee6665e3SDean Nelson #define XPC_RP_VARS(_rp) ((struct xpc_vars_sn2 *) \ 180ee6665e3SDean Nelson (XPC_RP_MACH_NASIDS(_rp) + \ 18104de7418SDean Nelson xpc_nasid_mask_nlongs)) 18245d9ca49SDean Nelson 18345d9ca49SDean Nelson /* 18445d9ca49SDean Nelson * Functions registered by add_timer() or called by kernel_thread() only 18545d9ca49SDean Nelson * allow for a single 64-bit argument. The following macros can be used to 18645d9ca49SDean Nelson * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from 18745d9ca49SDean Nelson * the passed argument. 18845d9ca49SDean Nelson */ 18945d9ca49SDean Nelson #define XPC_PACK_ARGS(_arg1, _arg2) \ 19045d9ca49SDean Nelson ((((u64)_arg1) & 0xffffffff) | \ 19145d9ca49SDean Nelson ((((u64)_arg2) & 0xffffffff) << 32)) 19245d9ca49SDean Nelson 19345d9ca49SDean Nelson #define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff) 19445d9ca49SDean Nelson #define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff) 19545d9ca49SDean Nelson 19645d9ca49SDean Nelson /* 19745d9ca49SDean Nelson * Define a Get/Put value pair (pointers) used with a message queue. 19845d9ca49SDean Nelson */ 199261f3b49SDean Nelson struct xpc_gp_sn2 { 2002c2b94f9SDean Nelson s64 get; /* Get value */ 2012c2b94f9SDean Nelson s64 put; /* Put value */ 20245d9ca49SDean Nelson }; 20345d9ca49SDean Nelson 20445d9ca49SDean Nelson #define XPC_GP_SIZE \ 205261f3b49SDean Nelson L1_CACHE_ALIGN(sizeof(struct xpc_gp_sn2) * XPC_MAX_NCHANNELS) 20645d9ca49SDean Nelson 20745d9ca49SDean Nelson /* 20845d9ca49SDean Nelson * Define a structure that contains arguments associated with opening and 20945d9ca49SDean Nelson * closing a channel. 21045d9ca49SDean Nelson */ 21145d9ca49SDean Nelson struct xpc_openclose_args { 21245d9ca49SDean Nelson u16 reason; /* reason why channel is closing */ 21345d9ca49SDean Nelson u16 msg_size; /* sizeof each message entry */ 21445d9ca49SDean Nelson u16 remote_nentries; /* #of message entries in remote msg queue */ 21545d9ca49SDean Nelson u16 local_nentries; /* #of message entries in local msg queue */ 216a812dcc3SDean Nelson unsigned long local_msgqueue_pa; /* phys addr of local message queue */ 21745d9ca49SDean Nelson }; 21845d9ca49SDean Nelson 21945d9ca49SDean Nelson #define XPC_OPENCLOSE_ARGS_SIZE \ 220bc63d387SDean Nelson L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \ 221bc63d387SDean Nelson XPC_MAX_NCHANNELS) 22245d9ca49SDean Nelson 22345d9ca49SDean Nelson /* struct xpc_msg flags */ 22445d9ca49SDean Nelson 22545d9ca49SDean Nelson #define XPC_M_DONE 0x01 /* msg has been received/consumed */ 22645d9ca49SDean Nelson #define XPC_M_READY 0x02 /* msg is ready to be sent */ 22745d9ca49SDean Nelson #define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */ 22845d9ca49SDean Nelson 22945d9ca49SDean Nelson #define XPC_MSG_ADDRESS(_payload) \ 23045d9ca49SDean Nelson ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET)) 23145d9ca49SDean Nelson 23245d9ca49SDean Nelson /* 23345d9ca49SDean Nelson * Defines notify entry. 23445d9ca49SDean Nelson * 23545d9ca49SDean Nelson * This is used to notify a message's sender that their message was received 23645d9ca49SDean Nelson * and consumed by the intended recipient. 23745d9ca49SDean Nelson */ 23845d9ca49SDean Nelson struct xpc_notify { 2392c2b94f9SDean Nelson u8 type; /* type of notification */ 24045d9ca49SDean Nelson 24145d9ca49SDean Nelson /* the following two fields are only used if type == XPC_N_CALL */ 24245d9ca49SDean Nelson xpc_notify_func func; /* user's notify function */ 24345d9ca49SDean Nelson void *key; /* pointer to user's key */ 24445d9ca49SDean Nelson }; 24545d9ca49SDean Nelson 24645d9ca49SDean Nelson /* struct xpc_notify type of notification */ 24745d9ca49SDean Nelson 24845d9ca49SDean Nelson #define XPC_N_CALL 0x01 /* notify function provided by user */ 24945d9ca49SDean Nelson 25045d9ca49SDean Nelson /* 25145d9ca49SDean Nelson * Define the structure that manages all the stuff required by a channel. In 25245d9ca49SDean Nelson * particular, they are used to manage the messages sent across the channel. 25345d9ca49SDean Nelson * 25445d9ca49SDean Nelson * This structure is private to a partition, and is NOT shared across the 25545d9ca49SDean Nelson * partition boundary. 25645d9ca49SDean Nelson * 25745d9ca49SDean Nelson * There is an array of these structures for each remote partition. It is 25845d9ca49SDean Nelson * allocated at the time a partition becomes active. The array contains one 25945d9ca49SDean Nelson * of these structures for each potential channel connection to that partition. 260ea57f80cSDean Nelson */ 261ea57f80cSDean Nelson 262ea57f80cSDean Nelson /* 263ea57f80cSDean Nelson * The following is sn2 only. 26445d9ca49SDean Nelson * 265ea57f80cSDean Nelson * Each channel structure manages two message queues (circular buffers). 26645d9ca49SDean Nelson * They are allocated at the time a channel connection is made. One of 26745d9ca49SDean Nelson * these message queues (local_msgqueue) holds the locally created messages 26845d9ca49SDean Nelson * that are destined for the remote partition. The other of these message 26945d9ca49SDean Nelson * queues (remote_msgqueue) is a locally cached copy of the remote partition's 27045d9ca49SDean Nelson * own local_msgqueue. 27145d9ca49SDean Nelson * 27245d9ca49SDean Nelson * The following is a description of the Get/Put pointers used to manage these 27345d9ca49SDean Nelson * two message queues. Consider the local_msgqueue to be on one partition 27445d9ca49SDean Nelson * and the remote_msgqueue to be its cached copy on another partition. A 27545d9ca49SDean Nelson * description of what each of the lettered areas contains is included. 27645d9ca49SDean Nelson * 27745d9ca49SDean Nelson * 27845d9ca49SDean Nelson * local_msgqueue remote_msgqueue 27945d9ca49SDean Nelson * 28045d9ca49SDean Nelson * |/////////| |/////////| 28145d9ca49SDean Nelson * w_remote_GP.get --> +---------+ |/////////| 28245d9ca49SDean Nelson * | F | |/////////| 28345d9ca49SDean Nelson * remote_GP.get --> +---------+ +---------+ <-- local_GP->get 28445d9ca49SDean Nelson * | | | | 28545d9ca49SDean Nelson * | | | E | 28645d9ca49SDean Nelson * | | | | 28745d9ca49SDean Nelson * | | +---------+ <-- w_local_GP.get 28845d9ca49SDean Nelson * | B | |/////////| 28945d9ca49SDean Nelson * | | |////D////| 29045d9ca49SDean Nelson * | | |/////////| 29145d9ca49SDean Nelson * | | +---------+ <-- w_remote_GP.put 29245d9ca49SDean Nelson * | | |////C////| 29345d9ca49SDean Nelson * local_GP->put --> +---------+ +---------+ <-- remote_GP.put 29445d9ca49SDean Nelson * | | |/////////| 29545d9ca49SDean Nelson * | A | |/////////| 29645d9ca49SDean Nelson * | | |/////////| 29745d9ca49SDean Nelson * w_local_GP.put --> +---------+ |/////////| 29845d9ca49SDean Nelson * |/////////| |/////////| 29945d9ca49SDean Nelson * 30045d9ca49SDean Nelson * 30145d9ca49SDean Nelson * ( remote_GP.[get|put] are cached copies of the remote 30245d9ca49SDean Nelson * partition's local_GP->[get|put], and thus their values can 30345d9ca49SDean Nelson * lag behind their counterparts on the remote partition. ) 30445d9ca49SDean Nelson * 30545d9ca49SDean Nelson * 30645d9ca49SDean Nelson * A - Messages that have been allocated, but have not yet been sent to the 30745d9ca49SDean Nelson * remote partition. 30845d9ca49SDean Nelson * 30945d9ca49SDean Nelson * B - Messages that have been sent, but have not yet been acknowledged by the 31045d9ca49SDean Nelson * remote partition as having been received. 31145d9ca49SDean Nelson * 31245d9ca49SDean Nelson * C - Area that needs to be prepared for the copying of sent messages, by 31345d9ca49SDean Nelson * the clearing of the message flags of any previously received messages. 31445d9ca49SDean Nelson * 31545d9ca49SDean Nelson * D - Area into which sent messages are to be copied from the remote 31645d9ca49SDean Nelson * partition's local_msgqueue and then delivered to their intended 31745d9ca49SDean Nelson * recipients. [ To allow for a multi-message copy, another pointer 31845d9ca49SDean Nelson * (next_msg_to_pull) has been added to keep track of the next message 31945d9ca49SDean Nelson * number needing to be copied (pulled). It chases after w_remote_GP.put. 32045d9ca49SDean Nelson * Any messages lying between w_local_GP.get and next_msg_to_pull have 32145d9ca49SDean Nelson * been copied and are ready to be delivered. ] 32245d9ca49SDean Nelson * 32345d9ca49SDean Nelson * E - Messages that have been copied and delivered, but have not yet been 32445d9ca49SDean Nelson * acknowledged by the recipient as having been received. 32545d9ca49SDean Nelson * 32645d9ca49SDean Nelson * F - Messages that have been acknowledged, but XPC has not yet notified the 32745d9ca49SDean Nelson * sender that the message was received by its intended recipient. 32845d9ca49SDean Nelson * This is also an area that needs to be prepared for the allocating of 32945d9ca49SDean Nelson * new messages, by the clearing of the message flags of the acknowledged 33045d9ca49SDean Nelson * messages. 33145d9ca49SDean Nelson */ 332ea57f80cSDean Nelson 333a47d5dacSDean Nelson struct xpc_channel_sn2 { 334a47d5dacSDean Nelson 335a47d5dacSDean Nelson /* various flavors of local and remote Get/Put values */ 336a47d5dacSDean Nelson 337261f3b49SDean Nelson struct xpc_gp_sn2 *local_GP; /* local Get/Put values */ 338261f3b49SDean Nelson struct xpc_gp_sn2 remote_GP; /* remote Get/Put values */ 339261f3b49SDean Nelson struct xpc_gp_sn2 w_local_GP; /* working local Get/Put values */ 340261f3b49SDean Nelson struct xpc_gp_sn2 w_remote_GP; /* working remote Get/Put values */ 341a47d5dacSDean Nelson s64 next_msg_to_pull; /* Put value of next msg to pull */ 342a47d5dacSDean Nelson 343a47d5dacSDean Nelson struct mutex msg_to_pull_mutex; /* next msg to pull serialization */ 344a47d5dacSDean Nelson }; 345a47d5dacSDean Nelson 346a47d5dacSDean Nelson struct xpc_channel_uv { 347ea57f80cSDean Nelson /* !!! code is coming */ 348a47d5dacSDean Nelson }; 349a47d5dacSDean Nelson 35045d9ca49SDean Nelson struct xpc_channel { 35164d032baSDean Nelson short partid; /* ID of remote partition connected */ 35245d9ca49SDean Nelson spinlock_t lock; /* lock for updating this structure */ 35345d9ca49SDean Nelson u32 flags; /* general flags */ 35445d9ca49SDean Nelson 35565c17b80SDean Nelson enum xp_retval reason; /* reason why channel is disconnect'g */ 35645d9ca49SDean Nelson int reason_line; /* line# disconnect initiated from */ 35745d9ca49SDean Nelson 35845d9ca49SDean Nelson u16 number; /* channel # */ 35945d9ca49SDean Nelson 36045d9ca49SDean Nelson u16 msg_size; /* sizeof each msg entry */ 36145d9ca49SDean Nelson u16 local_nentries; /* #of msg entries in local msg queue */ 36245d9ca49SDean Nelson u16 remote_nentries; /* #of msg entries in remote msg queue */ 36345d9ca49SDean Nelson 36445d9ca49SDean Nelson void *local_msgqueue_base; /* base address of kmalloc'd space */ 36545d9ca49SDean Nelson struct xpc_msg *local_msgqueue; /* local message queue */ 36645d9ca49SDean Nelson void *remote_msgqueue_base; /* base address of kmalloc'd space */ 36745d9ca49SDean Nelson struct xpc_msg *remote_msgqueue; /* cached copy of remote partition's */ 36845d9ca49SDean Nelson /* local message queue */ 369a812dcc3SDean Nelson unsigned long remote_msgqueue_pa; /* phys addr of remote partition's */ 37045d9ca49SDean Nelson /* local message queue */ 37145d9ca49SDean Nelson 37245d9ca49SDean Nelson atomic_t references; /* #of external references to queues */ 37345d9ca49SDean Nelson 37445d9ca49SDean Nelson atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */ 37545d9ca49SDean Nelson wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */ 37645d9ca49SDean Nelson 3777fb5e59dSDean Nelson u8 delayed_chctl_flags; /* chctl flags received, but delayed */ 37845d9ca49SDean Nelson /* action until channel disconnected */ 37945d9ca49SDean Nelson 38045d9ca49SDean Nelson /* queue of msg senders who want to be notified when msg received */ 38145d9ca49SDean Nelson 38245d9ca49SDean Nelson atomic_t n_to_notify; /* #of msg senders to notify */ 38345d9ca49SDean Nelson struct xpc_notify *notify_queue; /* notify queue for messages sent */ 38445d9ca49SDean Nelson 38545d9ca49SDean Nelson xpc_channel_func func; /* user's channel function */ 38645d9ca49SDean Nelson void *key; /* pointer to user's key */ 38745d9ca49SDean Nelson 38845d9ca49SDean Nelson struct completion wdisconnect_wait; /* wait for channel disconnect */ 38945d9ca49SDean Nelson 39045d9ca49SDean Nelson struct xpc_openclose_args *local_openclose_args; /* args passed on */ 39145d9ca49SDean Nelson /* opening or closing of channel */ 39245d9ca49SDean Nelson 39345d9ca49SDean Nelson /* kthread management related fields */ 39445d9ca49SDean Nelson 39545d9ca49SDean Nelson atomic_t kthreads_assigned; /* #of kthreads assigned to channel */ 39645d9ca49SDean Nelson u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */ 39745d9ca49SDean Nelson atomic_t kthreads_idle; /* #of kthreads idle waiting for work */ 39845d9ca49SDean Nelson u32 kthreads_idle_limit; /* limit on #of kthreads idle */ 39945d9ca49SDean Nelson atomic_t kthreads_active; /* #of kthreads actively working */ 40045d9ca49SDean Nelson 40145d9ca49SDean Nelson wait_queue_head_t idle_wq; /* idle kthread wait queue */ 40245d9ca49SDean Nelson 403a47d5dacSDean Nelson union { 404a47d5dacSDean Nelson struct xpc_channel_sn2 sn2; 405a47d5dacSDean Nelson struct xpc_channel_uv uv; 406a47d5dacSDean Nelson } sn; 407a47d5dacSDean Nelson 40845d9ca49SDean Nelson } ____cacheline_aligned; 40945d9ca49SDean Nelson 41045d9ca49SDean Nelson /* struct xpc_channel flags */ 41145d9ca49SDean Nelson 41245d9ca49SDean Nelson #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */ 41345d9ca49SDean Nelson 41445d9ca49SDean Nelson #define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */ 41545d9ca49SDean Nelson #define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */ 41645d9ca49SDean Nelson #define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */ 41745d9ca49SDean Nelson #define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */ 41845d9ca49SDean Nelson 41945d9ca49SDean Nelson #define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */ 42045d9ca49SDean Nelson #define XPC_C_CONNECTEDCALLOUT 0x00000040 /* connected callout initiated */ 42145d9ca49SDean Nelson #define XPC_C_CONNECTEDCALLOUT_MADE \ 42245d9ca49SDean Nelson 0x00000080 /* connected callout completed */ 42345d9ca49SDean Nelson #define XPC_C_CONNECTED 0x00000100 /* local channel is connected */ 42445d9ca49SDean Nelson #define XPC_C_CONNECTING 0x00000200 /* channel is being connected */ 42545d9ca49SDean Nelson 42645d9ca49SDean Nelson #define XPC_C_RCLOSEREPLY 0x00000400 /* remote close channel reply */ 42745d9ca49SDean Nelson #define XPC_C_CLOSEREPLY 0x00000800 /* local close channel reply */ 42845d9ca49SDean Nelson #define XPC_C_RCLOSEREQUEST 0x00001000 /* remote close channel request */ 42945d9ca49SDean Nelson #define XPC_C_CLOSEREQUEST 0x00002000 /* local close channel request */ 43045d9ca49SDean Nelson 43145d9ca49SDean Nelson #define XPC_C_DISCONNECTED 0x00004000 /* channel is disconnected */ 43245d9ca49SDean Nelson #define XPC_C_DISCONNECTING 0x00008000 /* channel is being disconnected */ 43345d9ca49SDean Nelson #define XPC_C_DISCONNECTINGCALLOUT \ 43445d9ca49SDean Nelson 0x00010000 /* disconnecting callout initiated */ 43545d9ca49SDean Nelson #define XPC_C_DISCONNECTINGCALLOUT_MADE \ 43645d9ca49SDean Nelson 0x00020000 /* disconnecting callout completed */ 43745d9ca49SDean Nelson #define XPC_C_WDISCONNECT 0x00040000 /* waiting for channel disconnect */ 43845d9ca49SDean Nelson 43945d9ca49SDean Nelson /* 4407fb5e59dSDean Nelson * The channel control flags (chctl) union consists of a 64-bit variable which 4417fb5e59dSDean Nelson * is divided up into eight bytes, ordered from right to left. Byte zero 4427fb5e59dSDean Nelson * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte 4437fb5e59dSDean Nelson * can have one or more of the chctl flags set in it. 4447fb5e59dSDean Nelson */ 4457fb5e59dSDean Nelson 4467fb5e59dSDean Nelson union xpc_channel_ctl_flags { 4477fb5e59dSDean Nelson u64 all_flags; 4487fb5e59dSDean Nelson u8 flags[XPC_MAX_NCHANNELS]; 4497fb5e59dSDean Nelson }; 4507fb5e59dSDean Nelson 4517fb5e59dSDean Nelson /* chctl flags */ 4527fb5e59dSDean Nelson #define XPC_CHCTL_CLOSEREQUEST 0x01 4537fb5e59dSDean Nelson #define XPC_CHCTL_CLOSEREPLY 0x02 4547fb5e59dSDean Nelson #define XPC_CHCTL_OPENREQUEST 0x04 4557fb5e59dSDean Nelson #define XPC_CHCTL_OPENREPLY 0x08 4567fb5e59dSDean Nelson #define XPC_CHCTL_MSGREQUEST 0x10 4577fb5e59dSDean Nelson 4587fb5e59dSDean Nelson #define XPC_OPENCLOSE_CHCTL_FLAGS \ 4597fb5e59dSDean Nelson (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \ 4607fb5e59dSDean Nelson XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY) 4617fb5e59dSDean Nelson #define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST 4627fb5e59dSDean Nelson 4637fb5e59dSDean Nelson static inline int 4647fb5e59dSDean Nelson xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl) 4657fb5e59dSDean Nelson { 4667fb5e59dSDean Nelson int ch_number; 4677fb5e59dSDean Nelson 4687fb5e59dSDean Nelson for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) { 4697fb5e59dSDean Nelson if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS) 4707fb5e59dSDean Nelson return 1; 4717fb5e59dSDean Nelson } 4727fb5e59dSDean Nelson return 0; 4737fb5e59dSDean Nelson } 4747fb5e59dSDean Nelson 4757fb5e59dSDean Nelson static inline int 4767fb5e59dSDean Nelson xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl) 4777fb5e59dSDean Nelson { 4787fb5e59dSDean Nelson int ch_number; 4797fb5e59dSDean Nelson 4807fb5e59dSDean Nelson for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) { 4817fb5e59dSDean Nelson if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS) 4827fb5e59dSDean Nelson return 1; 4837fb5e59dSDean Nelson } 4847fb5e59dSDean Nelson return 0; 4857fb5e59dSDean Nelson } 4867fb5e59dSDean Nelson 4877fb5e59dSDean Nelson /* 488ea57f80cSDean Nelson * Manage channels on a partition basis. There is one of these structures 48945d9ca49SDean Nelson * for each partition (a partition will never utilize the structure that 49045d9ca49SDean Nelson * represents itself). 49145d9ca49SDean Nelson */ 492a47d5dacSDean Nelson 493a47d5dacSDean Nelson struct xpc_partition_sn2 { 494a812dcc3SDean Nelson unsigned long remote_amos_page_pa; /* paddr of partition's amos page */ 495a47d5dacSDean Nelson int activate_IRQ_nasid; /* active partition's act/deact nasid */ 496a47d5dacSDean Nelson int activate_IRQ_phys_cpuid; /* active part's act/deact phys cpuid */ 497a47d5dacSDean Nelson 498a812dcc3SDean Nelson unsigned long remote_vars_pa; /* phys addr of partition's vars */ 499a812dcc3SDean Nelson unsigned long remote_vars_part_pa; /* paddr of partition's vars part */ 500a47d5dacSDean Nelson u8 remote_vars_version; /* version# of partition's vars */ 501a47d5dacSDean Nelson 502a47d5dacSDean Nelson void *local_GPs_base; /* base address of kmalloc'd space */ 503261f3b49SDean Nelson struct xpc_gp_sn2 *local_GPs; /* local Get/Put values */ 504a47d5dacSDean Nelson void *remote_GPs_base; /* base address of kmalloc'd space */ 505261f3b49SDean Nelson struct xpc_gp_sn2 *remote_GPs; /* copy of remote partition's local */ 506a47d5dacSDean Nelson /* Get/Put values */ 507a812dcc3SDean Nelson unsigned long remote_GPs_pa; /* phys addr of remote partition's local */ 508a47d5dacSDean Nelson /* Get/Put values */ 509a47d5dacSDean Nelson 510a812dcc3SDean Nelson unsigned long remote_openclose_args_pa; /* phys addr of remote's args */ 511a47d5dacSDean Nelson 5127fb5e59dSDean Nelson int notify_IRQ_nasid; /* nasid of where to send notify IRQs */ 5137fb5e59dSDean Nelson int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */ 5147fb5e59dSDean Nelson char notify_IRQ_owner[8]; /* notify IRQ's owner's name */ 515a47d5dacSDean Nelson 516c39838ceSDean Nelson struct amo *remote_chctl_amo_va; /* addr of remote chctl flags' amo */ 517c39838ceSDean Nelson struct amo *local_chctl_amo_va; /* address of chctl flags' amo */ 518a47d5dacSDean Nelson 519a47d5dacSDean Nelson struct timer_list dropped_notify_IRQ_timer; /* dropped IRQ timer */ 520a47d5dacSDean Nelson }; 521a47d5dacSDean Nelson 522a47d5dacSDean Nelson struct xpc_partition_uv { 523ea57f80cSDean Nelson /* !!! code is coming */ 524a47d5dacSDean Nelson }; 525a47d5dacSDean Nelson 52645d9ca49SDean Nelson struct xpc_partition { 52745d9ca49SDean Nelson 52845d9ca49SDean Nelson /* XPC HB infrastructure */ 52945d9ca49SDean Nelson 53045d9ca49SDean Nelson u8 remote_rp_version; /* version# of partition's rsvd pg */ 53181fe7883SDean Nelson unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */ 532a812dcc3SDean Nelson unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */ 53345d9ca49SDean Nelson u64 last_heartbeat; /* HB at last read */ 5346e41017aSDean Nelson u32 activate_IRQ_rcvd; /* IRQs since activation */ 53545d9ca49SDean Nelson spinlock_t act_lock; /* protect updating of act_state */ 53645d9ca49SDean Nelson u8 act_state; /* from XPC HB viewpoint */ 53765c17b80SDean Nelson enum xp_retval reason; /* reason partition is deactivating */ 53845d9ca49SDean Nelson int reason_line; /* line# deactivation initiated from */ 53945d9ca49SDean Nelson 540a47d5dacSDean Nelson unsigned long disengage_timeout; /* timeout in jiffies */ 541a47d5dacSDean Nelson struct timer_list disengage_timer; 54245d9ca49SDean Nelson 54345d9ca49SDean Nelson /* XPC infrastructure referencing and teardown control */ 54445d9ca49SDean Nelson 5452c2b94f9SDean Nelson u8 setup_state; /* infrastructure setup state */ 54645d9ca49SDean Nelson wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */ 54745d9ca49SDean Nelson atomic_t references; /* #of references to infrastructure */ 54845d9ca49SDean Nelson 54945d9ca49SDean Nelson u8 nchannels; /* #of defined channels supported */ 55045d9ca49SDean Nelson atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */ 55145d9ca49SDean Nelson atomic_t nchannels_engaged; /* #of channels engaged with remote part */ 55245d9ca49SDean Nelson struct xpc_channel *channels; /* array of channel structures */ 55345d9ca49SDean Nelson 5547fb5e59dSDean Nelson /* fields used for managing channel avialability and activity */ 5557fb5e59dSDean Nelson 5567fb5e59dSDean Nelson union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */ 5577fb5e59dSDean Nelson spinlock_t chctl_lock; /* chctl flags lock */ 55845d9ca49SDean Nelson 55945d9ca49SDean Nelson void *local_openclose_args_base; /* base address of kmalloc'd space */ 56045d9ca49SDean Nelson struct xpc_openclose_args *local_openclose_args; /* local's args */ 56145d9ca49SDean Nelson void *remote_openclose_args_base; /* base address of kmalloc'd space */ 56245d9ca49SDean Nelson struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */ 56345d9ca49SDean Nelson /* args */ 56445d9ca49SDean Nelson 56545d9ca49SDean Nelson /* channel manager related fields */ 56645d9ca49SDean Nelson 56745d9ca49SDean Nelson atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */ 56845d9ca49SDean Nelson wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */ 56945d9ca49SDean Nelson 570a47d5dacSDean Nelson union { 571a47d5dacSDean Nelson struct xpc_partition_sn2 sn2; 572a47d5dacSDean Nelson struct xpc_partition_uv uv; 573a47d5dacSDean Nelson } sn; 574a47d5dacSDean Nelson 57545d9ca49SDean Nelson } ____cacheline_aligned; 57645d9ca49SDean Nelson 57745d9ca49SDean Nelson /* struct xpc_partition act_state values (for XPC HB) */ 57845d9ca49SDean Nelson 57983469b55SDean Nelson #define XPC_P_AS_INACTIVE 0x00 /* partition is not active */ 58083469b55SDean Nelson #define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */ 58183469b55SDean Nelson #define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */ 58283469b55SDean Nelson #define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */ 58383469b55SDean Nelson #define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */ 58445d9ca49SDean Nelson 58545d9ca49SDean Nelson #define XPC_DEACTIVATE_PARTITION(_p, _reason) \ 58645d9ca49SDean Nelson xpc_deactivate_partition(__LINE__, (_p), (_reason)) 58745d9ca49SDean Nelson 58845d9ca49SDean Nelson /* struct xpc_partition setup_state values */ 58945d9ca49SDean Nelson 59083469b55SDean Nelson #define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */ 59183469b55SDean Nelson #define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */ 59283469b55SDean Nelson #define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */ 59383469b55SDean Nelson #define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */ 59445d9ca49SDean Nelson 59545d9ca49SDean Nelson /* 5967fb5e59dSDean Nelson * struct xpc_partition_sn2's dropped notify IRQ timer is set to wait the 5977fb5e59dSDean Nelson * following interval #of seconds before checking for dropped notify IRQs. 5987fb5e59dSDean Nelson * These can occur whenever an IRQ's associated amo write doesn't complete 5997fb5e59dSDean Nelson * until after the IRQ was received. 60045d9ca49SDean Nelson */ 6017fb5e59dSDean Nelson #define XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL (0.25 * HZ) 60245d9ca49SDean Nelson 60345d9ca49SDean Nelson /* number of seconds to wait for other partitions to disengage */ 604a47d5dacSDean Nelson #define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90 60545d9ca49SDean Nelson 606a47d5dacSDean Nelson /* interval in seconds to print 'waiting deactivation' messages */ 607a47d5dacSDean Nelson #define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10 60845d9ca49SDean Nelson 60964d032baSDean Nelson #define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0])) 61045d9ca49SDean Nelson 61145d9ca49SDean Nelson /* found in xp_main.c */ 61245d9ca49SDean Nelson extern struct xpc_registration xpc_registrations[]; 61345d9ca49SDean Nelson 61445d9ca49SDean Nelson /* found in xpc_main.c */ 61545d9ca49SDean Nelson extern struct device *xpc_part; 61645d9ca49SDean Nelson extern struct device *xpc_chan; 617a47d5dacSDean Nelson extern int xpc_disengage_timelimit; 618a47d5dacSDean Nelson extern int xpc_disengage_timedout; 6196e41017aSDean Nelson extern atomic_t xpc_activate_IRQ_rcvd; 6206e41017aSDean Nelson extern wait_queue_head_t xpc_activate_IRQ_wq; 62133ba3c77SDean Nelson extern void *xpc_heartbeating_to_mask; 62245d9ca49SDean Nelson extern void xpc_activate_partition(struct xpc_partition *); 62345d9ca49SDean Nelson extern void xpc_activate_kthreads(struct xpc_channel *, int); 62445d9ca49SDean Nelson extern void xpc_create_kthreads(struct xpc_channel *, int, int); 62545d9ca49SDean Nelson extern void xpc_disconnect_wait(int); 626a812dcc3SDean Nelson extern enum xp_retval (*xpc_get_partition_rsvd_page_pa) (void *, u64 *, 627a812dcc3SDean Nelson unsigned long *, 628261f3b49SDean Nelson size_t *); 62994bd2708SDean Nelson extern enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *); 63033ba3c77SDean Nelson extern void (*xpc_heartbeat_init) (void); 63133ba3c77SDean Nelson extern void (*xpc_heartbeat_exit) (void); 63233ba3c77SDean Nelson extern void (*xpc_increment_heartbeat) (void); 63333ba3c77SDean Nelson extern void (*xpc_offline_heartbeat) (void); 63433ba3c77SDean Nelson extern void (*xpc_online_heartbeat) (void); 63561deb86eSDean Nelson extern enum xp_retval (*xpc_get_remote_heartbeat) (struct xpc_partition *); 636e17d416bSDean Nelson extern enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *); 6377fb5e59dSDean Nelson extern u64 (*xpc_get_chctl_all_flags) (struct xpc_partition *); 638185c3a1bSDean Nelson extern enum xp_retval (*xpc_allocate_msgqueues) (struct xpc_channel *); 639185c3a1bSDean Nelson extern void (*xpc_free_msgqueues) (struct xpc_channel *); 640a47d5dacSDean Nelson extern void (*xpc_notify_senders_of_disconnect) (struct xpc_channel *); 6417fb5e59dSDean Nelson extern void (*xpc_process_msg_chctl_flags) (struct xpc_partition *, int); 642a47d5dacSDean Nelson extern int (*xpc_n_of_deliverable_msgs) (struct xpc_channel *); 643e17d416bSDean Nelson extern struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *); 644a812dcc3SDean Nelson extern void (*xpc_request_partition_activation) (struct xpc_rsvd_page *, 645a812dcc3SDean Nelson unsigned long, int); 646a47d5dacSDean Nelson extern void (*xpc_request_partition_reactivation) (struct xpc_partition *); 647a47d5dacSDean Nelson extern void (*xpc_request_partition_deactivation) (struct xpc_partition *); 648a47d5dacSDean Nelson extern void (*xpc_cancel_partition_deactivation_request) ( 649a47d5dacSDean Nelson struct xpc_partition *); 6506e41017aSDean Nelson extern void (*xpc_process_activate_IRQ_rcvd) (int); 651e17d416bSDean Nelson extern enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *); 652e17d416bSDean Nelson extern void (*xpc_teardown_infrastructure) (struct xpc_partition *); 65333ba3c77SDean Nelson 654a47d5dacSDean Nelson extern void (*xpc_indicate_partition_engaged) (struct xpc_partition *); 655a47d5dacSDean Nelson extern int (*xpc_partition_engaged) (short); 656a47d5dacSDean Nelson extern int (*xpc_any_partition_engaged) (void); 657a47d5dacSDean Nelson extern void (*xpc_indicate_partition_disengaged) (struct xpc_partition *); 658a47d5dacSDean Nelson extern void (*xpc_assume_partition_disengaged) (short); 65933ba3c77SDean Nelson 6607fb5e59dSDean Nelson extern void (*xpc_send_chctl_closerequest) (struct xpc_channel *, 66133ba3c77SDean Nelson unsigned long *); 6627fb5e59dSDean Nelson extern void (*xpc_send_chctl_closereply) (struct xpc_channel *, 663a47d5dacSDean Nelson unsigned long *); 6647fb5e59dSDean Nelson extern void (*xpc_send_chctl_openrequest) (struct xpc_channel *, 665a47d5dacSDean Nelson unsigned long *); 6667fb5e59dSDean Nelson extern void (*xpc_send_chctl_openreply) (struct xpc_channel *, unsigned long *); 66733ba3c77SDean Nelson 66897bf1aa1SDean Nelson extern enum xp_retval (*xpc_send_msg) (struct xpc_channel *, u32, void *, u16, 66933ba3c77SDean Nelson u8, xpc_notify_func, void *); 67033ba3c77SDean Nelson extern void (*xpc_received_msg) (struct xpc_channel *, struct xpc_msg *); 67194bd2708SDean Nelson 67294bd2708SDean Nelson /* found in xpc_sn2.c */ 6736e41017aSDean Nelson extern int xpc_init_sn2(void); 6746e41017aSDean Nelson extern void xpc_exit_sn2(void); 67594bd2708SDean Nelson 67694bd2708SDean Nelson /* found in xpc_uv.c */ 67794bd2708SDean Nelson extern void xpc_init_uv(void); 6786e41017aSDean Nelson extern void xpc_exit_uv(void); 67994bd2708SDean Nelson 68045d9ca49SDean Nelson /* found in xpc_partition.c */ 68145d9ca49SDean Nelson extern int xpc_exiting; 68204de7418SDean Nelson extern int xpc_nasid_mask_nlongs; 68345d9ca49SDean Nelson extern struct xpc_rsvd_page *xpc_rsvd_page; 68404de7418SDean Nelson extern unsigned long *xpc_mach_nasids; 685bc63d387SDean Nelson extern struct xpc_partition *xpc_partitions; 68645d9ca49SDean Nelson extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **); 68794bd2708SDean Nelson extern struct xpc_rsvd_page *xpc_setup_rsvd_page(void); 6886e41017aSDean Nelson extern int xpc_identify_activate_IRQ_sender(void); 68945d9ca49SDean Nelson extern int xpc_partition_disengaged(struct xpc_partition *); 69065c17b80SDean Nelson extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *); 69145d9ca49SDean Nelson extern void xpc_mark_partition_inactive(struct xpc_partition *); 69245d9ca49SDean Nelson extern void xpc_discovery(void); 69304de7418SDean Nelson extern enum xp_retval xpc_get_remote_rp(int, unsigned long *, 694a812dcc3SDean Nelson struct xpc_rsvd_page *, 695a812dcc3SDean Nelson unsigned long *); 69645d9ca49SDean Nelson extern void xpc_deactivate_partition(const int, struct xpc_partition *, 69765c17b80SDean Nelson enum xp_retval); 69864d032baSDean Nelson extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *); 69945d9ca49SDean Nelson 70045d9ca49SDean Nelson /* found in xpc_channel.c */ 70145d9ca49SDean Nelson extern void xpc_initiate_connect(int); 70245d9ca49SDean Nelson extern void xpc_initiate_disconnect(int); 70333ba3c77SDean Nelson extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *); 70497bf1aa1SDean Nelson extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16); 70597bf1aa1SDean Nelson extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16, 70645d9ca49SDean Nelson xpc_notify_func, void *); 70764d032baSDean Nelson extern void xpc_initiate_received(short, int, void *); 7087fb5e59dSDean Nelson extern void xpc_process_sent_chctl_flags(struct xpc_partition *); 70945d9ca49SDean Nelson extern void xpc_connected_callout(struct xpc_channel *); 71045d9ca49SDean Nelson extern void xpc_deliver_msg(struct xpc_channel *); 71145d9ca49SDean Nelson extern void xpc_disconnect_channel(const int, struct xpc_channel *, 71265c17b80SDean Nelson enum xp_retval, unsigned long *); 71365c17b80SDean Nelson extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval); 71465c17b80SDean Nelson extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval); 71545d9ca49SDean Nelson 71633ba3c77SDean Nelson static inline int 71733ba3c77SDean Nelson xpc_hb_allowed(short partid, void *heartbeating_to_mask) 71833ba3c77SDean Nelson { 71933ba3c77SDean Nelson return test_bit(partid, heartbeating_to_mask); 72033ba3c77SDean Nelson } 72133ba3c77SDean Nelson 72233ba3c77SDean Nelson static inline int 72333ba3c77SDean Nelson xpc_any_hbs_allowed(void) 72433ba3c77SDean Nelson { 72533ba3c77SDean Nelson DBUG_ON(xpc_heartbeating_to_mask == NULL); 72633ba3c77SDean Nelson return !bitmap_empty(xpc_heartbeating_to_mask, xp_max_npartitions); 72733ba3c77SDean Nelson } 72833ba3c77SDean Nelson 72933ba3c77SDean Nelson static inline void 73033ba3c77SDean Nelson xpc_allow_hb(short partid) 73133ba3c77SDean Nelson { 73233ba3c77SDean Nelson DBUG_ON(xpc_heartbeating_to_mask == NULL); 73333ba3c77SDean Nelson set_bit(partid, xpc_heartbeating_to_mask); 73433ba3c77SDean Nelson } 73533ba3c77SDean Nelson 73633ba3c77SDean Nelson static inline void 73733ba3c77SDean Nelson xpc_disallow_hb(short partid) 73833ba3c77SDean Nelson { 73933ba3c77SDean Nelson DBUG_ON(xpc_heartbeating_to_mask == NULL); 74033ba3c77SDean Nelson clear_bit(partid, xpc_heartbeating_to_mask); 74133ba3c77SDean Nelson } 74233ba3c77SDean Nelson 74333ba3c77SDean Nelson static inline void 74433ba3c77SDean Nelson xpc_disallow_all_hbs(void) 74533ba3c77SDean Nelson { 74633ba3c77SDean Nelson DBUG_ON(xpc_heartbeating_to_mask == NULL); 74733ba3c77SDean Nelson bitmap_zero(xpc_heartbeating_to_mask, xp_max_npartitions); 74833ba3c77SDean Nelson } 74933ba3c77SDean Nelson 75045d9ca49SDean Nelson static inline void 75145d9ca49SDean Nelson xpc_wakeup_channel_mgr(struct xpc_partition *part) 75245d9ca49SDean Nelson { 7532c2b94f9SDean Nelson if (atomic_inc_return(&part->channel_mgr_requests) == 1) 75445d9ca49SDean Nelson wake_up(&part->channel_mgr_wq); 75545d9ca49SDean Nelson } 75645d9ca49SDean Nelson 75745d9ca49SDean Nelson /* 75845d9ca49SDean Nelson * These next two inlines are used to keep us from tearing down a channel's 75945d9ca49SDean Nelson * msg queues while a thread may be referencing them. 76045d9ca49SDean Nelson */ 76145d9ca49SDean Nelson static inline void 76245d9ca49SDean Nelson xpc_msgqueue_ref(struct xpc_channel *ch) 76345d9ca49SDean Nelson { 76445d9ca49SDean Nelson atomic_inc(&ch->references); 76545d9ca49SDean Nelson } 76645d9ca49SDean Nelson 76745d9ca49SDean Nelson static inline void 76845d9ca49SDean Nelson xpc_msgqueue_deref(struct xpc_channel *ch) 76945d9ca49SDean Nelson { 77045d9ca49SDean Nelson s32 refs = atomic_dec_return(&ch->references); 77145d9ca49SDean Nelson 77245d9ca49SDean Nelson DBUG_ON(refs < 0); 7732c2b94f9SDean Nelson if (refs == 0) 77445d9ca49SDean Nelson xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]); 77545d9ca49SDean Nelson } 77645d9ca49SDean Nelson 77745d9ca49SDean Nelson #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \ 77845d9ca49SDean Nelson xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs) 77945d9ca49SDean Nelson 78045d9ca49SDean Nelson /* 78145d9ca49SDean Nelson * These two inlines are used to keep us from tearing down a partition's 78245d9ca49SDean Nelson * setup infrastructure while a thread may be referencing it. 78345d9ca49SDean Nelson */ 78445d9ca49SDean Nelson static inline void 78545d9ca49SDean Nelson xpc_part_deref(struct xpc_partition *part) 78645d9ca49SDean Nelson { 78745d9ca49SDean Nelson s32 refs = atomic_dec_return(&part->references); 78845d9ca49SDean Nelson 78945d9ca49SDean Nelson DBUG_ON(refs < 0); 79083469b55SDean Nelson if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN) 79145d9ca49SDean Nelson wake_up(&part->teardown_wq); 79245d9ca49SDean Nelson } 79345d9ca49SDean Nelson 79445d9ca49SDean Nelson static inline int 79545d9ca49SDean Nelson xpc_part_ref(struct xpc_partition *part) 79645d9ca49SDean Nelson { 79745d9ca49SDean Nelson int setup; 79845d9ca49SDean Nelson 79945d9ca49SDean Nelson atomic_inc(&part->references); 80083469b55SDean Nelson setup = (part->setup_state == XPC_P_SS_SETUP); 8012c2b94f9SDean Nelson if (!setup) 80245d9ca49SDean Nelson xpc_part_deref(part); 8032c2b94f9SDean Nelson 80445d9ca49SDean Nelson return setup; 80545d9ca49SDean Nelson } 80645d9ca49SDean Nelson 80745d9ca49SDean Nelson /* 80845d9ca49SDean Nelson * The following macro is to be used for the setting of the reason and 80945d9ca49SDean Nelson * reason_line fields in both the struct xpc_channel and struct xpc_partition 81045d9ca49SDean Nelson * structures. 81145d9ca49SDean Nelson */ 81245d9ca49SDean Nelson #define XPC_SET_REASON(_p, _reason, _line) \ 81345d9ca49SDean Nelson { \ 81445d9ca49SDean Nelson (_p)->reason = _reason; \ 81545d9ca49SDean Nelson (_p)->reason_line = _line; \ 81645d9ca49SDean Nelson } 81745d9ca49SDean Nelson 81845d9ca49SDean Nelson #endif /* _DRIVERS_MISC_SGIXP_XPC_H */ 819