xpc.h 25 KB

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