/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (c) 2004-2009 Silicon Graphics, Inc. All Rights Reserved.6*/78/*9* Cross Partition Communication (XPC) structures and macros.10*/1112#ifndef _DRIVERS_MISC_SGIXP_XPC_H13#define _DRIVERS_MISC_SGIXP_XPC_H1415#include <linux/wait.h>16#include <linux/completion.h>17#include <linux/timer.h>18#include <linux/sched.h>19#include "xp.h"2021/*22* XPC Version numbers consist of a major and minor number. XPC can always23* talk to versions with same major #, and never talk to versions with a24* different major #.25*/26#define _XPC_VERSION(_maj, _min) (((_maj) << 4) | ((_min) & 0xf))27#define XPC_VERSION_MAJOR(_v) ((_v) >> 4)28#define XPC_VERSION_MINOR(_v) ((_v) & 0xf)2930/* define frequency of the heartbeat and frequency how often it's checked */31#define XPC_HB_DEFAULT_INTERVAL 5 /* incr HB every x secs */32#define XPC_HB_CHECK_DEFAULT_INTERVAL 20 /* check HB every x secs */3334/* define the process name of HB checker and the CPU it is pinned to */35#define XPC_HB_CHECK_THREAD_NAME "xpc_hb"36#define XPC_HB_CHECK_CPU 03738/* define the process name of the discovery thread */39#define XPC_DISCOVERY_THREAD_NAME "xpc_discovery"4041/*42* the reserved page43*44* SAL reserves one page of memory per partition for XPC. Though a full page45* in length (16384 bytes), its starting address is not page aligned, but it46* is cacheline aligned. The reserved page consists of the following:47*48* reserved page header49*50* The first two 64-byte cachelines of the reserved page contain the51* header (struct xpc_rsvd_page). Before SAL initialization has completed,52* SAL has set up the following fields of the reserved page header:53* SAL_signature, SAL_version, SAL_partid, and SAL_nasids_size. The54* other fields are set up by XPC. (xpc_rsvd_page points to the local55* partition's reserved page.)56*57* part_nasids mask58* mach_nasids mask59*60* SAL also sets up two bitmaps (or masks), one that reflects the actual61* nasids in this partition (part_nasids), and the other that reflects62* the actual nasids in the entire machine (mach_nasids). We're only63* interested in the even numbered nasids (which contain the processors64* and/or memory), so we only need half as many bits to represent the65* nasids. When mapping nasid to bit in a mask (or bit to nasid) be sure66* to either divide or multiply by 2. The part_nasids mask is located67* starting at the first cacheline following the reserved page header. The68* mach_nasids mask follows right after the part_nasids mask. The size in69* bytes of each mask is reflected by the reserved page header field70* 'SAL_nasids_size'. (Local partition's mask pointers are xpc_part_nasids71* and xpc_mach_nasids.)72*73* vars (ia64-sn2 only)74* vars part (ia64-sn2 only)75*76* Immediately following the mach_nasids mask are the XPC variables77* required by other partitions. First are those that are generic to all78* partitions (vars), followed on the next available cacheline by those79* which are partition specific (vars part). These are setup by XPC.80* (Local partition's vars pointers are xpc_vars and xpc_vars_part.)81*82* Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been83* initialized.84*/85struct xpc_rsvd_page {86u64 SAL_signature; /* SAL: unique signature */87u64 SAL_version; /* SAL: version */88short SAL_partid; /* SAL: partition ID */89short max_npartitions; /* value of XPC_MAX_PARTITIONS */90u8 version;91u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */92unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */93union {94struct {95unsigned long vars_pa; /* phys addr */96} sn2;97struct {98unsigned long heartbeat_gpa; /* phys addr */99unsigned long activate_gru_mq_desc_gpa; /* phys addr */100} uv;101} sn;102u64 pad2[9]; /* align to last u64 in 2nd 64-byte cacheline */103u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */104};105106#define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */107108/*109* Define the structures by which XPC variables can be exported to other110* partitions. (There are two: struct xpc_vars and struct xpc_vars_part)111*/112113/*114* The following structure describes the partition generic variables115* needed by other partitions in order to properly initialize.116*117* struct xpc_vars version number also applies to struct xpc_vars_part.118* Changes to either structure and/or related functionality should be119* reflected by incrementing either the major or minor version numbers120* of struct xpc_vars.121*/122struct xpc_vars_sn2 {123u8 version;124u64 heartbeat;125DECLARE_BITMAP(heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);126u64 heartbeat_offline; /* if 0, heartbeat should be changing */127int activate_IRQ_nasid;128int activate_IRQ_phys_cpuid;129unsigned long vars_part_pa;130unsigned long amos_page_pa;/* paddr of page of amos from MSPEC driver */131struct amo *amos_page; /* vaddr of page of amos from MSPEC driver */132};133134#define XPC_V_VERSION _XPC_VERSION(3, 1) /* version 3.1 of the cross vars */135136/*137* The following structure describes the per partition specific variables.138*139* An array of these structures, one per partition, will be defined. As a140* partition becomes active XPC will copy the array entry corresponding to141* itself from that partition. It is desirable that the size of this structure142* evenly divides into a 128-byte cacheline, such that none of the entries in143* this array crosses a 128-byte cacheline boundary. As it is now, each entry144* occupies 64-bytes.145*/146struct xpc_vars_part_sn2 {147u64 magic;148149unsigned long openclose_args_pa; /* phys addr of open and close args */150unsigned long GPs_pa; /* physical address of Get/Put values */151152unsigned long chctl_amo_pa; /* physical address of chctl flags' amo */153154int notify_IRQ_nasid; /* nasid of where to send notify IRQs */155int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */156157u8 nchannels; /* #of defined channels supported */158159u8 reserved[23]; /* pad to a full 64 bytes */160};161162/*163* The vars_part MAGIC numbers play a part in the first contact protocol.164*165* MAGIC1 indicates that the per partition specific variables for a remote166* partition have been initialized by this partition.167*168* MAGIC2 indicates that this partition has pulled the remote partititions169* per partition variables that pertain to this partition.170*/171#define XPC_VP_MAGIC1_SN2 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */172#define XPC_VP_MAGIC2_SN2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */173174/* the reserved page sizes and offsets */175176#define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))177#define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars_sn2))178179#define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \180XPC_RP_HEADER_SIZE))181#define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \182xpc_nasid_mask_nlongs)183#define XPC_RP_VARS(_rp) ((struct xpc_vars_sn2 *) \184(XPC_RP_MACH_NASIDS(_rp) + \185xpc_nasid_mask_nlongs))186187188/*189* The following structure describes the partition's heartbeat info which190* will be periodically read by other partitions to determine whether this191* XPC is still 'alive'.192*/193struct xpc_heartbeat_uv {194unsigned long value;195unsigned long offline; /* if 0, heartbeat should be changing */196};197198/*199* Info pertinent to a GRU message queue using a watch list for irq generation.200*/201struct xpc_gru_mq_uv {202void *address; /* address of GRU message queue */203unsigned int order; /* size of GRU message queue as a power of 2 */204int irq; /* irq raised when message is received in mq */205int mmr_blade; /* blade where watchlist was allocated from */206unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */207unsigned long mmr_value; /* value of irq mmr located on mmr_blade */208int watchlist_num; /* number of watchlist allocatd by BIOS */209void *gru_mq_desc; /* opaque structure used by the GRU driver */210};211212/*213* The activate_mq is used to send/receive GRU messages that affect XPC's214* partition active state and channel state. This is uv only.215*/216struct xpc_activate_mq_msghdr_uv {217unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */218short partid; /* sender's partid */219u8 act_state; /* sender's act_state at time msg sent */220u8 type; /* message's type */221unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */222};223224/* activate_mq defined message types */225#define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV 0226227#define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV 1228#define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV 2229230#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV 3231#define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV 4232#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV 5233#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV 6234#define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV 7235236#define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV 8237#define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV 9238239struct xpc_activate_mq_msg_uv {240struct xpc_activate_mq_msghdr_uv hdr;241};242243struct xpc_activate_mq_msg_activate_req_uv {244struct xpc_activate_mq_msghdr_uv hdr;245unsigned long rp_gpa;246unsigned long heartbeat_gpa;247unsigned long activate_gru_mq_desc_gpa;248};249250struct xpc_activate_mq_msg_deactivate_req_uv {251struct xpc_activate_mq_msghdr_uv hdr;252enum xp_retval reason;253};254255struct xpc_activate_mq_msg_chctl_closerequest_uv {256struct xpc_activate_mq_msghdr_uv hdr;257short ch_number;258enum xp_retval reason;259};260261struct xpc_activate_mq_msg_chctl_closereply_uv {262struct xpc_activate_mq_msghdr_uv hdr;263short ch_number;264};265266struct xpc_activate_mq_msg_chctl_openrequest_uv {267struct xpc_activate_mq_msghdr_uv hdr;268short ch_number;269short entry_size; /* size of notify_mq's GRU messages */270short local_nentries; /* ??? Is this needed? What is? */271};272273struct xpc_activate_mq_msg_chctl_openreply_uv {274struct xpc_activate_mq_msghdr_uv hdr;275short ch_number;276short remote_nentries; /* ??? Is this needed? What is? */277short local_nentries; /* ??? Is this needed? What is? */278unsigned long notify_gru_mq_desc_gpa;279};280281struct xpc_activate_mq_msg_chctl_opencomplete_uv {282struct xpc_activate_mq_msghdr_uv hdr;283short ch_number;284};285286/*287* Functions registered by add_timer() or called by kernel_thread() only288* allow for a single 64-bit argument. The following macros can be used to289* pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from290* the passed argument.291*/292#define XPC_PACK_ARGS(_arg1, _arg2) \293((((u64)_arg1) & 0xffffffff) | \294((((u64)_arg2) & 0xffffffff) << 32))295296#define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff)297#define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff)298299/*300* Define a Get/Put value pair (pointers) used with a message queue.301*/302struct xpc_gp_sn2 {303s64 get; /* Get value */304s64 put; /* Put value */305};306307#define XPC_GP_SIZE \308L1_CACHE_ALIGN(sizeof(struct xpc_gp_sn2) * XPC_MAX_NCHANNELS)309310/*311* Define a structure that contains arguments associated with opening and312* closing a channel.313*/314struct xpc_openclose_args {315u16 reason; /* reason why channel is closing */316u16 entry_size; /* sizeof each message entry */317u16 remote_nentries; /* #of message entries in remote msg queue */318u16 local_nentries; /* #of message entries in local msg queue */319unsigned long local_msgqueue_pa; /* phys addr of local message queue */320};321322#define XPC_OPENCLOSE_ARGS_SIZE \323L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \324XPC_MAX_NCHANNELS)325326327/*328* Structures to define a fifo singly-linked list.329*/330331struct xpc_fifo_entry_uv {332struct xpc_fifo_entry_uv *next;333};334335struct xpc_fifo_head_uv {336struct xpc_fifo_entry_uv *first;337struct xpc_fifo_entry_uv *last;338spinlock_t lock;339int n_entries;340};341342/*343* Define a sn2 styled message.344*345* A user-defined message resides in the payload area. The max size of the346* payload is defined by the user via xpc_connect().347*348* The size of a message entry (within a message queue) must be a 128-byte349* cacheline sized multiple in order to facilitate the BTE transfer of messages350* from one message queue to another.351*/352struct xpc_msg_sn2 {353u8 flags; /* FOR XPC INTERNAL USE ONLY */354u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */355s64 number; /* FOR XPC INTERNAL USE ONLY */356357u64 payload; /* user defined portion of message */358};359360/* struct xpc_msg_sn2 flags */361362#define XPC_M_SN2_DONE 0x01 /* msg has been received/consumed */363#define XPC_M_SN2_READY 0x02 /* msg is ready to be sent */364#define XPC_M_SN2_INTERRUPT 0x04 /* send interrupt when msg consumed */365366/*367* The format of a uv XPC notify_mq GRU message is as follows:368*369* A user-defined message resides in the payload area. The max size of the370* payload is defined by the user via xpc_connect().371*372* The size of a message (payload and header) sent via the GRU must be either 1373* or 2 GRU_CACHE_LINE_BYTES in length.374*/375376struct xpc_notify_mq_msghdr_uv {377union {378unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */379struct xpc_fifo_entry_uv next; /* FOR XPC INTERNAL USE ONLY */380} u;381short partid; /* FOR XPC INTERNAL USE ONLY */382u8 ch_number; /* FOR XPC INTERNAL USE ONLY */383u8 size; /* FOR XPC INTERNAL USE ONLY */384unsigned int msg_slot_number; /* FOR XPC INTERNAL USE ONLY */385};386387struct xpc_notify_mq_msg_uv {388struct xpc_notify_mq_msghdr_uv hdr;389unsigned long payload;390};391392/*393* Define sn2's notify entry.394*395* This is used to notify a message's sender that their message was received396* and consumed by the intended recipient.397*/398struct xpc_notify_sn2 {399u8 type; /* type of notification */400401/* the following two fields are only used if type == XPC_N_CALL */402xpc_notify_func func; /* user's notify function */403void *key; /* pointer to user's key */404};405406/* struct xpc_notify_sn2 type of notification */407408#define XPC_N_CALL 0x01 /* notify function provided by user */409410/*411* Define uv's version of the notify entry. It additionally is used to allocate412* a msg slot on the remote partition into which is copied a sent message.413*/414struct xpc_send_msg_slot_uv {415struct xpc_fifo_entry_uv next;416unsigned int msg_slot_number;417xpc_notify_func func; /* user's notify function */418void *key; /* pointer to user's key */419};420421/*422* Define the structure that manages all the stuff required by a channel. In423* particular, they are used to manage the messages sent across the channel.424*425* This structure is private to a partition, and is NOT shared across the426* partition boundary.427*428* There is an array of these structures for each remote partition. It is429* allocated at the time a partition becomes active. The array contains one430* of these structures for each potential channel connection to that partition.431*/432433/*434* The following is sn2 only.435*436* Each channel structure manages two message queues (circular buffers).437* They are allocated at the time a channel connection is made. One of438* these message queues (local_msgqueue) holds the locally created messages439* that are destined for the remote partition. The other of these message440* queues (remote_msgqueue) is a locally cached copy of the remote partition's441* own local_msgqueue.442*443* The following is a description of the Get/Put pointers used to manage these444* two message queues. Consider the local_msgqueue to be on one partition445* and the remote_msgqueue to be its cached copy on another partition. A446* description of what each of the lettered areas contains is included.447*448*449* local_msgqueue remote_msgqueue450*451* |/////////| |/////////|452* w_remote_GP.get --> +---------+ |/////////|453* | F | |/////////|454* remote_GP.get --> +---------+ +---------+ <-- local_GP->get455* | | | |456* | | | E |457* | | | |458* | | +---------+ <-- w_local_GP.get459* | B | |/////////|460* | | |////D////|461* | | |/////////|462* | | +---------+ <-- w_remote_GP.put463* | | |////C////|464* local_GP->put --> +---------+ +---------+ <-- remote_GP.put465* | | |/////////|466* | A | |/////////|467* | | |/////////|468* w_local_GP.put --> +---------+ |/////////|469* |/////////| |/////////|470*471*472* ( remote_GP.[get|put] are cached copies of the remote473* partition's local_GP->[get|put], and thus their values can474* lag behind their counterparts on the remote partition. )475*476*477* A - Messages that have been allocated, but have not yet been sent to the478* remote partition.479*480* B - Messages that have been sent, but have not yet been acknowledged by the481* remote partition as having been received.482*483* C - Area that needs to be prepared for the copying of sent messages, by484* the clearing of the message flags of any previously received messages.485*486* D - Area into which sent messages are to be copied from the remote487* partition's local_msgqueue and then delivered to their intended488* recipients. [ To allow for a multi-message copy, another pointer489* (next_msg_to_pull) has been added to keep track of the next message490* number needing to be copied (pulled). It chases after w_remote_GP.put.491* Any messages lying between w_local_GP.get and next_msg_to_pull have492* been copied and are ready to be delivered. ]493*494* E - Messages that have been copied and delivered, but have not yet been495* acknowledged by the recipient as having been received.496*497* F - Messages that have been acknowledged, but XPC has not yet notified the498* sender that the message was received by its intended recipient.499* This is also an area that needs to be prepared for the allocating of500* new messages, by the clearing of the message flags of the acknowledged501* messages.502*/503504struct xpc_channel_sn2 {505struct xpc_openclose_args *local_openclose_args; /* args passed on */506/* opening or closing of channel */507508void *local_msgqueue_base; /* base address of kmalloc'd space */509struct xpc_msg_sn2 *local_msgqueue; /* local message queue */510void *remote_msgqueue_base; /* base address of kmalloc'd space */511struct xpc_msg_sn2 *remote_msgqueue; /* cached copy of remote */512/* partition's local message queue */513unsigned long remote_msgqueue_pa; /* phys addr of remote partition's */514/* local message queue */515516struct xpc_notify_sn2 *notify_queue;/* notify queue for messages sent */517518/* various flavors of local and remote Get/Put values */519520struct xpc_gp_sn2 *local_GP; /* local Get/Put values */521struct xpc_gp_sn2 remote_GP; /* remote Get/Put values */522struct xpc_gp_sn2 w_local_GP; /* working local Get/Put values */523struct xpc_gp_sn2 w_remote_GP; /* working remote Get/Put values */524s64 next_msg_to_pull; /* Put value of next msg to pull */525526struct mutex msg_to_pull_mutex; /* next msg to pull serialization */527};528529struct xpc_channel_uv {530void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */531/* gru mq descriptor */532533struct xpc_send_msg_slot_uv *send_msg_slots;534void *recv_msg_slots; /* each slot will hold a xpc_notify_mq_msg_uv */535/* structure plus the user's payload */536537struct xpc_fifo_head_uv msg_slot_free_list;538struct xpc_fifo_head_uv recv_msg_list; /* deliverable payloads */539};540541struct xpc_channel {542short partid; /* ID of remote partition connected */543spinlock_t lock; /* lock for updating this structure */544unsigned int flags; /* general flags */545546enum xp_retval reason; /* reason why channel is disconnect'g */547int reason_line; /* line# disconnect initiated from */548549u16 number; /* channel # */550551u16 entry_size; /* sizeof each msg entry */552u16 local_nentries; /* #of msg entries in local msg queue */553u16 remote_nentries; /* #of msg entries in remote msg queue */554555atomic_t references; /* #of external references to queues */556557atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */558wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */559560u8 delayed_chctl_flags; /* chctl flags received, but delayed */561/* action until channel disconnected */562563atomic_t n_to_notify; /* #of msg senders to notify */564565xpc_channel_func func; /* user's channel function */566void *key; /* pointer to user's key */567568struct completion wdisconnect_wait; /* wait for channel disconnect */569570/* kthread management related fields */571572atomic_t kthreads_assigned; /* #of kthreads assigned to channel */573u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */574atomic_t kthreads_idle; /* #of kthreads idle waiting for work */575u32 kthreads_idle_limit; /* limit on #of kthreads idle */576atomic_t kthreads_active; /* #of kthreads actively working */577578wait_queue_head_t idle_wq; /* idle kthread wait queue */579580union {581struct xpc_channel_sn2 sn2;582struct xpc_channel_uv uv;583} sn;584585} ____cacheline_aligned;586587/* struct xpc_channel flags */588589#define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */590591#define XPC_C_ROPENCOMPLETE 0x00000002 /* remote open channel complete */592#define XPC_C_OPENCOMPLETE 0x00000004 /* local open channel complete */593#define XPC_C_ROPENREPLY 0x00000008 /* remote open channel reply */594#define XPC_C_OPENREPLY 0x00000010 /* local open channel reply */595#define XPC_C_ROPENREQUEST 0x00000020 /* remote open channel request */596#define XPC_C_OPENREQUEST 0x00000040 /* local open channel request */597598#define XPC_C_SETUP 0x00000080 /* channel's msgqueues are alloc'd */599#define XPC_C_CONNECTEDCALLOUT 0x00000100 /* connected callout initiated */600#define XPC_C_CONNECTEDCALLOUT_MADE \6010x00000200 /* connected callout completed */602#define XPC_C_CONNECTED 0x00000400 /* local channel is connected */603#define XPC_C_CONNECTING 0x00000800 /* channel is being connected */604605#define XPC_C_RCLOSEREPLY 0x00001000 /* remote close channel reply */606#define XPC_C_CLOSEREPLY 0x00002000 /* local close channel reply */607#define XPC_C_RCLOSEREQUEST 0x00004000 /* remote close channel request */608#define XPC_C_CLOSEREQUEST 0x00008000 /* local close channel request */609610#define XPC_C_DISCONNECTED 0x00010000 /* channel is disconnected */611#define XPC_C_DISCONNECTING 0x00020000 /* channel is being disconnected */612#define XPC_C_DISCONNECTINGCALLOUT \6130x00040000 /* disconnecting callout initiated */614#define XPC_C_DISCONNECTINGCALLOUT_MADE \6150x00080000 /* disconnecting callout completed */616#define XPC_C_WDISCONNECT 0x00100000 /* waiting for channel disconnect */617618/*619* The channel control flags (chctl) union consists of a 64-bit variable which620* is divided up into eight bytes, ordered from right to left. Byte zero621* pertains to channel 0, byte one to channel 1, and so on. Each channel's byte622* can have one or more of the chctl flags set in it.623*/624625union xpc_channel_ctl_flags {626u64 all_flags;627u8 flags[XPC_MAX_NCHANNELS];628};629630/* chctl flags */631#define XPC_CHCTL_CLOSEREQUEST 0x01632#define XPC_CHCTL_CLOSEREPLY 0x02633#define XPC_CHCTL_OPENREQUEST 0x04634#define XPC_CHCTL_OPENREPLY 0x08635#define XPC_CHCTL_OPENCOMPLETE 0x10636#define XPC_CHCTL_MSGREQUEST 0x20637638#define XPC_OPENCLOSE_CHCTL_FLAGS \639(XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \640XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \641XPC_CHCTL_OPENCOMPLETE)642#define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST643644static inline int645xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)646{647int ch_number;648649for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {650if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)651return 1;652}653return 0;654}655656static inline int657xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)658{659int ch_number;660661for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {662if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)663return 1;664}665return 0;666}667668/*669* Manage channels on a partition basis. There is one of these structures670* for each partition (a partition will never utilize the structure that671* represents itself).672*/673674struct xpc_partition_sn2 {675unsigned long remote_amos_page_pa; /* paddr of partition's amos page */676int activate_IRQ_nasid; /* active partition's act/deact nasid */677int activate_IRQ_phys_cpuid; /* active part's act/deact phys cpuid */678679unsigned long remote_vars_pa; /* phys addr of partition's vars */680unsigned long remote_vars_part_pa; /* paddr of partition's vars part */681u8 remote_vars_version; /* version# of partition's vars */682683void *local_GPs_base; /* base address of kmalloc'd space */684struct xpc_gp_sn2 *local_GPs; /* local Get/Put values */685void *remote_GPs_base; /* base address of kmalloc'd space */686struct xpc_gp_sn2 *remote_GPs; /* copy of remote partition's local */687/* Get/Put values */688unsigned long remote_GPs_pa; /* phys addr of remote partition's local */689/* Get/Put values */690691void *local_openclose_args_base; /* base address of kmalloc'd space */692struct xpc_openclose_args *local_openclose_args; /* local's args */693unsigned long remote_openclose_args_pa; /* phys addr of remote's args */694695int notify_IRQ_nasid; /* nasid of where to send notify IRQs */696int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */697char notify_IRQ_owner[8]; /* notify IRQ's owner's name */698699struct amo *remote_chctl_amo_va; /* addr of remote chctl flags' amo */700struct amo *local_chctl_amo_va; /* address of chctl flags' amo */701702struct timer_list dropped_notify_IRQ_timer; /* dropped IRQ timer */703};704705struct xpc_partition_uv {706unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */707struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */708/* partition's heartbeat */709unsigned long activate_gru_mq_desc_gpa; /* phys addr of parititon's */710/* activate mq's gru mq */711/* descriptor */712void *cached_activate_gru_mq_desc; /* cached copy of partition's */713/* activate mq's gru mq descriptor */714struct mutex cached_activate_gru_mq_desc_mutex;715spinlock_t flags_lock; /* protect updating of flags */716unsigned int flags; /* general flags */717u8 remote_act_state; /* remote partition's act_state */718u8 act_state_req; /* act_state request from remote partition */719enum xp_retval reason; /* reason for deactivate act_state request */720};721722/* struct xpc_partition_uv flags */723724#define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV 0x00000001725#define XPC_P_ENGAGED_UV 0x00000002726727/* struct xpc_partition_uv act_state change requests */728729#define XPC_P_ASR_ACTIVATE_UV 0x01730#define XPC_P_ASR_REACTIVATE_UV 0x02731#define XPC_P_ASR_DEACTIVATE_UV 0x03732733struct xpc_partition {734735/* XPC HB infrastructure */736737u8 remote_rp_version; /* version# of partition's rsvd pg */738unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */739unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */740u64 last_heartbeat; /* HB at last read */741u32 activate_IRQ_rcvd; /* IRQs since activation */742spinlock_t act_lock; /* protect updating of act_state */743u8 act_state; /* from XPC HB viewpoint */744enum xp_retval reason; /* reason partition is deactivating */745int reason_line; /* line# deactivation initiated from */746747unsigned long disengage_timeout; /* timeout in jiffies */748struct timer_list disengage_timer;749750/* XPC infrastructure referencing and teardown control */751752u8 setup_state; /* infrastructure setup state */753wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */754atomic_t references; /* #of references to infrastructure */755756u8 nchannels; /* #of defined channels supported */757atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */758atomic_t nchannels_engaged; /* #of channels engaged with remote part */759struct xpc_channel *channels; /* array of channel structures */760761/* fields used for managing channel avialability and activity */762763union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */764spinlock_t chctl_lock; /* chctl flags lock */765766void *remote_openclose_args_base; /* base address of kmalloc'd space */767struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */768/* args */769770/* channel manager related fields */771772atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */773wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */774775union {776struct xpc_partition_sn2 sn2;777struct xpc_partition_uv uv;778} sn;779780} ____cacheline_aligned;781782struct xpc_arch_operations {783int (*setup_partitions) (void);784void (*teardown_partitions) (void);785void (*process_activate_IRQ_rcvd) (void);786enum xp_retval (*get_partition_rsvd_page_pa)787(void *, u64 *, unsigned long *, size_t *);788int (*setup_rsvd_page) (struct xpc_rsvd_page *);789790void (*allow_hb) (short);791void (*disallow_hb) (short);792void (*disallow_all_hbs) (void);793void (*increment_heartbeat) (void);794void (*offline_heartbeat) (void);795void (*online_heartbeat) (void);796void (*heartbeat_init) (void);797void (*heartbeat_exit) (void);798enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);799800void (*request_partition_activation) (struct xpc_rsvd_page *,801unsigned long, int);802void (*request_partition_reactivation) (struct xpc_partition *);803void (*request_partition_deactivation) (struct xpc_partition *);804void (*cancel_partition_deactivation_request) (struct xpc_partition *);805enum xp_retval (*setup_ch_structures) (struct xpc_partition *);806void (*teardown_ch_structures) (struct xpc_partition *);807808enum xp_retval (*make_first_contact) (struct xpc_partition *);809810u64 (*get_chctl_all_flags) (struct xpc_partition *);811void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);812void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);813void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);814void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);815void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);816void (*process_msg_chctl_flags) (struct xpc_partition *, int);817818enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,819unsigned long);820821enum xp_retval (*setup_msg_structures) (struct xpc_channel *);822void (*teardown_msg_structures) (struct xpc_channel *);823824void (*indicate_partition_engaged) (struct xpc_partition *);825void (*indicate_partition_disengaged) (struct xpc_partition *);826void (*assume_partition_disengaged) (short);827int (*partition_engaged) (short);828int (*any_partition_engaged) (void);829830int (*n_of_deliverable_payloads) (struct xpc_channel *);831enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,832u16, u8, xpc_notify_func, void *);833void *(*get_deliverable_payload) (struct xpc_channel *);834void (*received_payload) (struct xpc_channel *, void *);835void (*notify_senders_of_disconnect) (struct xpc_channel *);836};837838/* struct xpc_partition act_state values (for XPC HB) */839840#define XPC_P_AS_INACTIVE 0x00 /* partition is not active */841#define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */842#define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */843#define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */844#define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */845846#define XPC_DEACTIVATE_PARTITION(_p, _reason) \847xpc_deactivate_partition(__LINE__, (_p), (_reason))848849/* struct xpc_partition setup_state values */850851#define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */852#define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */853#define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */854#define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */855856/*857* struct xpc_partition_sn2's dropped notify IRQ timer is set to wait the858* following interval #of seconds before checking for dropped notify IRQs.859* These can occur whenever an IRQ's associated amo write doesn't complete860* until after the IRQ was received.861*/862#define XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL (0.25 * HZ)863864/* number of seconds to wait for other partitions to disengage */865#define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90866867/* interval in seconds to print 'waiting deactivation' messages */868#define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10869870#define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0]))871872/* found in xp_main.c */873extern struct xpc_registration xpc_registrations[];874875/* found in xpc_main.c */876extern struct device *xpc_part;877extern struct device *xpc_chan;878extern struct xpc_arch_operations xpc_arch_ops;879extern int xpc_disengage_timelimit;880extern int xpc_disengage_timedout;881extern int xpc_activate_IRQ_rcvd;882extern spinlock_t xpc_activate_IRQ_rcvd_lock;883extern wait_queue_head_t xpc_activate_IRQ_wq;884extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);885extern void xpc_activate_partition(struct xpc_partition *);886extern void xpc_activate_kthreads(struct xpc_channel *, int);887extern void xpc_create_kthreads(struct xpc_channel *, int, int);888extern void xpc_disconnect_wait(int);889890/* found in xpc_sn2.c */891extern int xpc_init_sn2(void);892extern void xpc_exit_sn2(void);893894/* found in xpc_uv.c */895extern int xpc_init_uv(void);896extern void xpc_exit_uv(void);897898/* found in xpc_partition.c */899extern int xpc_exiting;900extern int xpc_nasid_mask_nlongs;901extern struct xpc_rsvd_page *xpc_rsvd_page;902extern unsigned long *xpc_mach_nasids;903extern struct xpc_partition *xpc_partitions;904extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);905extern int xpc_setup_rsvd_page(void);906extern void xpc_teardown_rsvd_page(void);907extern int xpc_identify_activate_IRQ_sender(void);908extern int xpc_partition_disengaged(struct xpc_partition *);909extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);910extern void xpc_mark_partition_inactive(struct xpc_partition *);911extern void xpc_discovery(void);912extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,913struct xpc_rsvd_page *,914unsigned long *);915extern void xpc_deactivate_partition(const int, struct xpc_partition *,916enum xp_retval);917extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);918919/* found in xpc_channel.c */920extern void xpc_initiate_connect(int);921extern void xpc_initiate_disconnect(int);922extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);923extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);924extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,925xpc_notify_func, void *);926extern void xpc_initiate_received(short, int, void *);927extern void xpc_process_sent_chctl_flags(struct xpc_partition *);928extern void xpc_connected_callout(struct xpc_channel *);929extern void xpc_deliver_payload(struct xpc_channel *);930extern void xpc_disconnect_channel(const int, struct xpc_channel *,931enum xp_retval, unsigned long *);932extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);933extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);934935static inline void936xpc_wakeup_channel_mgr(struct xpc_partition *part)937{938if (atomic_inc_return(&part->channel_mgr_requests) == 1)939wake_up(&part->channel_mgr_wq);940}941942/*943* These next two inlines are used to keep us from tearing down a channel's944* msg queues while a thread may be referencing them.945*/946static inline void947xpc_msgqueue_ref(struct xpc_channel *ch)948{949atomic_inc(&ch->references);950}951952static inline void953xpc_msgqueue_deref(struct xpc_channel *ch)954{955s32 refs = atomic_dec_return(&ch->references);956957DBUG_ON(refs < 0);958if (refs == 0)959xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);960}961962#define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \963xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)964965/*966* These two inlines are used to keep us from tearing down a partition's967* setup infrastructure while a thread may be referencing it.968*/969static inline void970xpc_part_deref(struct xpc_partition *part)971{972s32 refs = atomic_dec_return(&part->references);973974DBUG_ON(refs < 0);975if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)976wake_up(&part->teardown_wq);977}978979static inline int980xpc_part_ref(struct xpc_partition *part)981{982int setup;983984atomic_inc(&part->references);985setup = (part->setup_state == XPC_P_SS_SETUP);986if (!setup)987xpc_part_deref(part);988989return setup;990}991992/*993* The following macro is to be used for the setting of the reason and994* reason_line fields in both the struct xpc_channel and struct xpc_partition995* structures.996*/997#define XPC_SET_REASON(_p, _reason, _line) \998{ \999(_p)->reason = _reason; \1000(_p)->reason_line = _line; \1001}10021003#endif /* _DRIVERS_MISC_SGIXP_XPC_H */100410051006