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