xpc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  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-2008 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. * vars (ia64-sn2 only)
  67. * vars part (ia64-sn2 only)
  68. *
  69. * Immediately following the mach_nasids mask are the XPC variables
  70. * required by other partitions. First are those that are generic to all
  71. * partitions (vars), followed on the next available cacheline by those
  72. * which are partition specific (vars part). These are setup by XPC.
  73. * (Local partition's vars pointers are xpc_vars and xpc_vars_part.)
  74. *
  75. * Note: Until 'ts_jiffies' is set non-zero, the partition XPC code has not been
  76. * initialized.
  77. */
  78. struct xpc_rsvd_page {
  79. u64 SAL_signature; /* SAL: unique signature */
  80. u64 SAL_version; /* SAL: version */
  81. short SAL_partid; /* SAL: partition ID */
  82. short max_npartitions; /* value of XPC_MAX_PARTITIONS */
  83. u8 version;
  84. u8 pad1[3]; /* align to next u64 in 1st 64-byte cacheline */
  85. union {
  86. u64 vars_pa; /* physical address of struct xpc_vars */
  87. u64 activate_mq_gpa; /* global phys address of activate_mq */
  88. } sn;
  89. unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
  90. u64 pad2[10]; /* align to last u64 in 2nd 64-byte cacheline */
  91. u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */
  92. };
  93. #define XPC_RP_VERSION _XPC_VERSION(2, 0) /* version 2.0 of the reserved page */
  94. /*
  95. * Define the structures by which XPC variables can be exported to other
  96. * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
  97. */
  98. /*
  99. * The following structure describes the partition generic variables
  100. * needed by other partitions in order to properly initialize.
  101. *
  102. * struct xpc_vars version number also applies to struct xpc_vars_part.
  103. * Changes to either structure and/or related functionality should be
  104. * reflected by incrementing either the major or minor version numbers
  105. * of struct xpc_vars.
  106. */
  107. struct xpc_vars_sn2 {
  108. u8 version;
  109. u64 heartbeat;
  110. DECLARE_BITMAP(heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);
  111. u64 heartbeat_offline; /* if 0, heartbeat should be changing */
  112. int activate_IRQ_nasid;
  113. int activate_IRQ_phys_cpuid;
  114. u64 vars_part_pa;
  115. u64 amos_page_pa; /* paddr of page of amos from MSPEC driver */
  116. struct amo *amos_page; /* vaddr of page of amos from MSPEC driver */
  117. };
  118. #define XPC_V_VERSION _XPC_VERSION(3, 1) /* version 3.1 of the cross vars */
  119. /*
  120. * The following structure describes the per partition specific variables.
  121. *
  122. * An array of these structures, one per partition, will be defined. As a
  123. * partition becomes active XPC will copy the array entry corresponding to
  124. * itself from that partition. It is desirable that the size of this structure
  125. * evenly divides into a 128-byte cacheline, such that none of the entries in
  126. * this array crosses a 128-byte cacheline boundary. As it is now, each entry
  127. * occupies 64-bytes.
  128. */
  129. struct xpc_vars_part_sn2 {
  130. u64 magic;
  131. u64 openclose_args_pa; /* physical address of open and close args */
  132. u64 GPs_pa; /* physical address of Get/Put values */
  133. u64 chctl_amo_pa; /* physical address of chctl flags' amo */
  134. int notify_IRQ_nasid; /* nasid of where to send notify IRQs */
  135. int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */
  136. u8 nchannels; /* #of defined channels supported */
  137. u8 reserved[23]; /* pad to a full 64 bytes */
  138. };
  139. /*
  140. * The vars_part MAGIC numbers play a part in the first contact protocol.
  141. *
  142. * MAGIC1 indicates that the per partition specific variables for a remote
  143. * partition have been initialized by this partition.
  144. *
  145. * MAGIC2 indicates that this partition has pulled the remote partititions
  146. * per partition variables that pertain to this partition.
  147. */
  148. #define XPC_VP_MAGIC1 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */
  149. #define XPC_VP_MAGIC2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */
  150. /* the reserved page sizes and offsets */
  151. #define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
  152. #define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars_sn2))
  153. #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
  154. XPC_RP_HEADER_SIZE))
  155. #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
  156. xpc_nasid_mask_nlongs)
  157. #define XPC_RP_VARS(_rp) ((struct xpc_vars_sn2 *) \
  158. (XPC_RP_MACH_NASIDS(_rp) + \
  159. xpc_nasid_mask_nlongs))
  160. /*
  161. * Functions registered by add_timer() or called by kernel_thread() only
  162. * allow for a single 64-bit argument. The following macros can be used to
  163. * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
  164. * the passed argument.
  165. */
  166. #define XPC_PACK_ARGS(_arg1, _arg2) \
  167. ((((u64)_arg1) & 0xffffffff) | \
  168. ((((u64)_arg2) & 0xffffffff) << 32))
  169. #define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff)
  170. #define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff)
  171. /*
  172. * Define a Get/Put value pair (pointers) used with a message queue.
  173. */
  174. struct xpc_gp_sn2 {
  175. s64 get; /* Get value */
  176. s64 put; /* Put value */
  177. };
  178. #define XPC_GP_SIZE \
  179. L1_CACHE_ALIGN(sizeof(struct xpc_gp_sn2) * XPC_MAX_NCHANNELS)
  180. /*
  181. * Define a structure that contains arguments associated with opening and
  182. * closing a channel.
  183. */
  184. struct xpc_openclose_args {
  185. u16 reason; /* reason why channel is closing */
  186. u16 msg_size; /* sizeof each message entry */
  187. u16 remote_nentries; /* #of message entries in remote msg queue */
  188. u16 local_nentries; /* #of message entries in local msg queue */
  189. u64 local_msgqueue_pa; /* physical address of local message queue */
  190. };
  191. #define XPC_OPENCLOSE_ARGS_SIZE \
  192. L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
  193. XPC_MAX_NCHANNELS)
  194. /* struct xpc_msg flags */
  195. #define XPC_M_DONE 0x01 /* msg has been received/consumed */
  196. #define XPC_M_READY 0x02 /* msg is ready to be sent */
  197. #define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */
  198. #define XPC_MSG_ADDRESS(_payload) \
  199. ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET))
  200. /*
  201. * Defines notify entry.
  202. *
  203. * This is used to notify a message's sender that their message was received
  204. * and consumed by the intended recipient.
  205. */
  206. struct xpc_notify {
  207. u8 type; /* type of notification */
  208. /* the following two fields are only used if type == XPC_N_CALL */
  209. xpc_notify_func func; /* user's notify function */
  210. void *key; /* pointer to user's key */
  211. };
  212. /* struct xpc_notify type of notification */
  213. #define XPC_N_CALL 0x01 /* notify function provided by user */
  214. /*
  215. * Define the structure that manages all the stuff required by a channel. In
  216. * particular, they are used to manage the messages sent across the channel.
  217. *
  218. * This structure is private to a partition, and is NOT shared across the
  219. * partition boundary.
  220. *
  221. * There is an array of these structures for each remote partition. It is
  222. * allocated at the time a partition becomes active. The array contains one
  223. * of these structures for each potential channel connection to that partition.
  224. */
  225. /*
  226. * The following is sn2 only.
  227. *
  228. * Each channel structure manages two message queues (circular buffers).
  229. * They are allocated at the time a channel connection is made. One of
  230. * these message queues (local_msgqueue) holds the locally created messages
  231. * that are destined for the remote partition. The other of these message
  232. * queues (remote_msgqueue) is a locally cached copy of the remote partition's
  233. * own local_msgqueue.
  234. *
  235. * The following is a description of the Get/Put pointers used to manage these
  236. * two message queues. Consider the local_msgqueue to be on one partition
  237. * and the remote_msgqueue to be its cached copy on another partition. A
  238. * description of what each of the lettered areas contains is included.
  239. *
  240. *
  241. * local_msgqueue remote_msgqueue
  242. *
  243. * |/////////| |/////////|
  244. * w_remote_GP.get --> +---------+ |/////////|
  245. * | F | |/////////|
  246. * remote_GP.get --> +---------+ +---------+ <-- local_GP->get
  247. * | | | |
  248. * | | | E |
  249. * | | | |
  250. * | | +---------+ <-- w_local_GP.get
  251. * | B | |/////////|
  252. * | | |////D////|
  253. * | | |/////////|
  254. * | | +---------+ <-- w_remote_GP.put
  255. * | | |////C////|
  256. * local_GP->put --> +---------+ +---------+ <-- remote_GP.put
  257. * | | |/////////|
  258. * | A | |/////////|
  259. * | | |/////////|
  260. * w_local_GP.put --> +---------+ |/////////|
  261. * |/////////| |/////////|
  262. *
  263. *
  264. * ( remote_GP.[get|put] are cached copies of the remote
  265. * partition's local_GP->[get|put], and thus their values can
  266. * lag behind their counterparts on the remote partition. )
  267. *
  268. *
  269. * A - Messages that have been allocated, but have not yet been sent to the
  270. * remote partition.
  271. *
  272. * B - Messages that have been sent, but have not yet been acknowledged by the
  273. * remote partition as having been received.
  274. *
  275. * C - Area that needs to be prepared for the copying of sent messages, by
  276. * the clearing of the message flags of any previously received messages.
  277. *
  278. * D - Area into which sent messages are to be copied from the remote
  279. * partition's local_msgqueue and then delivered to their intended
  280. * recipients. [ To allow for a multi-message copy, another pointer
  281. * (next_msg_to_pull) has been added to keep track of the next message
  282. * number needing to be copied (pulled). It chases after w_remote_GP.put.
  283. * Any messages lying between w_local_GP.get and next_msg_to_pull have
  284. * been copied and are ready to be delivered. ]
  285. *
  286. * E - Messages that have been copied and delivered, but have not yet been
  287. * acknowledged by the recipient as having been received.
  288. *
  289. * F - Messages that have been acknowledged, but XPC has not yet notified the
  290. * sender that the message was received by its intended recipient.
  291. * This is also an area that needs to be prepared for the allocating of
  292. * new messages, by the clearing of the message flags of the acknowledged
  293. * messages.
  294. */
  295. struct xpc_channel_sn2 {
  296. /* various flavors of local and remote Get/Put values */
  297. struct xpc_gp_sn2 *local_GP; /* local Get/Put values */
  298. struct xpc_gp_sn2 remote_GP; /* remote Get/Put values */
  299. struct xpc_gp_sn2 w_local_GP; /* working local Get/Put values */
  300. struct xpc_gp_sn2 w_remote_GP; /* working remote Get/Put values */
  301. s64 next_msg_to_pull; /* Put value of next msg to pull */
  302. struct mutex msg_to_pull_mutex; /* next msg to pull serialization */
  303. };
  304. struct xpc_channel_uv {
  305. /* !!! code is coming */
  306. };
  307. struct xpc_channel {
  308. short partid; /* ID of remote partition connected */
  309. spinlock_t lock; /* lock for updating this structure */
  310. u32 flags; /* general flags */
  311. enum xp_retval reason; /* reason why channel is disconnect'g */
  312. int reason_line; /* line# disconnect initiated from */
  313. u16 number; /* channel # */
  314. u16 msg_size; /* sizeof each msg entry */
  315. u16 local_nentries; /* #of msg entries in local msg queue */
  316. u16 remote_nentries; /* #of msg entries in remote msg queue */
  317. void *local_msgqueue_base; /* base address of kmalloc'd space */
  318. struct xpc_msg *local_msgqueue; /* local message queue */
  319. void *remote_msgqueue_base; /* base address of kmalloc'd space */
  320. struct xpc_msg *remote_msgqueue; /* cached copy of remote partition's */
  321. /* local message queue */
  322. u64 remote_msgqueue_pa; /* phys addr of remote partition's */
  323. /* local message queue */
  324. atomic_t references; /* #of external references to queues */
  325. atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
  326. wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
  327. u8 delayed_chctl_flags; /* chctl flags received, but delayed */
  328. /* action until channel disconnected */
  329. /* queue of msg senders who want to be notified when msg received */
  330. atomic_t n_to_notify; /* #of msg senders to notify */
  331. struct xpc_notify *notify_queue; /* notify queue for messages sent */
  332. xpc_channel_func func; /* user's channel function */
  333. void *key; /* pointer to user's key */
  334. struct completion wdisconnect_wait; /* wait for channel disconnect */
  335. struct xpc_openclose_args *local_openclose_args; /* args passed on */
  336. /* opening or closing of channel */
  337. /* kthread management related fields */
  338. atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
  339. u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
  340. atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
  341. u32 kthreads_idle_limit; /* limit on #of kthreads idle */
  342. atomic_t kthreads_active; /* #of kthreads actively working */
  343. wait_queue_head_t idle_wq; /* idle kthread wait queue */
  344. union {
  345. struct xpc_channel_sn2 sn2;
  346. struct xpc_channel_uv uv;
  347. } sn;
  348. } ____cacheline_aligned;
  349. /* struct xpc_channel flags */
  350. #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
  351. #define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */
  352. #define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */
  353. #define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */
  354. #define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */
  355. #define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */
  356. #define XPC_C_CONNECTEDCALLOUT 0x00000040 /* connected callout initiated */
  357. #define XPC_C_CONNECTEDCALLOUT_MADE \
  358. 0x00000080 /* connected callout completed */
  359. #define XPC_C_CONNECTED 0x00000100 /* local channel is connected */
  360. #define XPC_C_CONNECTING 0x00000200 /* channel is being connected */
  361. #define XPC_C_RCLOSEREPLY 0x00000400 /* remote close channel reply */
  362. #define XPC_C_CLOSEREPLY 0x00000800 /* local close channel reply */
  363. #define XPC_C_RCLOSEREQUEST 0x00001000 /* remote close channel request */
  364. #define XPC_C_CLOSEREQUEST 0x00002000 /* local close channel request */
  365. #define XPC_C_DISCONNECTED 0x00004000 /* channel is disconnected */
  366. #define XPC_C_DISCONNECTING 0x00008000 /* channel is being disconnected */
  367. #define XPC_C_DISCONNECTINGCALLOUT \
  368. 0x00010000 /* disconnecting callout initiated */
  369. #define XPC_C_DISCONNECTINGCALLOUT_MADE \
  370. 0x00020000 /* disconnecting callout completed */
  371. #define XPC_C_WDISCONNECT 0x00040000 /* waiting for channel disconnect */
  372. /*
  373. * The channel control flags (chctl) union consists of a 64-bit variable which
  374. * is divided up into eight bytes, ordered from right to left. Byte zero
  375. * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
  376. * can have one or more of the chctl flags set in it.
  377. */
  378. union xpc_channel_ctl_flags {
  379. u64 all_flags;
  380. u8 flags[XPC_MAX_NCHANNELS];
  381. };
  382. /* chctl flags */
  383. #define XPC_CHCTL_CLOSEREQUEST 0x01
  384. #define XPC_CHCTL_CLOSEREPLY 0x02
  385. #define XPC_CHCTL_OPENREQUEST 0x04
  386. #define XPC_CHCTL_OPENREPLY 0x08
  387. #define XPC_CHCTL_MSGREQUEST 0x10
  388. #define XPC_OPENCLOSE_CHCTL_FLAGS \
  389. (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
  390. XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY)
  391. #define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST
  392. static inline int
  393. xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
  394. {
  395. int ch_number;
  396. for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
  397. if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
  398. return 1;
  399. }
  400. return 0;
  401. }
  402. static inline int
  403. xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
  404. {
  405. int ch_number;
  406. for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
  407. if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
  408. return 1;
  409. }
  410. return 0;
  411. }
  412. /*
  413. * Manage channels on a partition basis. There is one of these structures
  414. * for each partition (a partition will never utilize the structure that
  415. * represents itself).
  416. */
  417. struct xpc_partition_sn2 {
  418. u64 remote_amos_page_pa; /* phys addr of partition's amos page */
  419. int activate_IRQ_nasid; /* active partition's act/deact nasid */
  420. int activate_IRQ_phys_cpuid; /* active part's act/deact phys cpuid */
  421. u64 remote_vars_pa; /* phys addr of partition's vars */
  422. u64 remote_vars_part_pa; /* phys addr of partition's vars part */
  423. u8 remote_vars_version; /* version# of partition's vars */
  424. void *local_GPs_base; /* base address of kmalloc'd space */
  425. struct xpc_gp_sn2 *local_GPs; /* local Get/Put values */
  426. void *remote_GPs_base; /* base address of kmalloc'd space */
  427. struct xpc_gp_sn2 *remote_GPs; /* copy of remote partition's local */
  428. /* Get/Put values */
  429. u64 remote_GPs_pa; /* phys address of remote partition's local */
  430. /* Get/Put values */
  431. u64 remote_openclose_args_pa; /* phys addr of remote's args */
  432. int notify_IRQ_nasid; /* nasid of where to send notify IRQs */
  433. int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */
  434. char notify_IRQ_owner[8]; /* notify IRQ's owner's name */
  435. struct amo *remote_chctl_amo_va; /* addr of remote chctl flags' amo */
  436. struct amo *local_chctl_amo_va; /* address of chctl flags' amo */
  437. struct timer_list dropped_notify_IRQ_timer; /* dropped IRQ timer */
  438. };
  439. struct xpc_partition_uv {
  440. /* !!! code is coming */
  441. };
  442. struct xpc_partition {
  443. /* XPC HB infrastructure */
  444. u8 remote_rp_version; /* version# of partition's rsvd pg */
  445. unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
  446. u64 remote_rp_pa; /* phys addr of partition's rsvd pg */
  447. u64 last_heartbeat; /* HB at last read */
  448. u32 activate_IRQ_rcvd; /* IRQs since activation */
  449. spinlock_t act_lock; /* protect updating of act_state */
  450. u8 act_state; /* from XPC HB viewpoint */
  451. enum xp_retval reason; /* reason partition is deactivating */
  452. int reason_line; /* line# deactivation initiated from */
  453. unsigned long disengage_timeout; /* timeout in jiffies */
  454. struct timer_list disengage_timer;
  455. /* XPC infrastructure referencing and teardown control */
  456. u8 setup_state; /* infrastructure setup state */
  457. wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
  458. atomic_t references; /* #of references to infrastructure */
  459. u8 nchannels; /* #of defined channels supported */
  460. atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
  461. atomic_t nchannels_engaged; /* #of channels engaged with remote part */
  462. struct xpc_channel *channels; /* array of channel structures */
  463. /* fields used for managing channel avialability and activity */
  464. union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
  465. spinlock_t chctl_lock; /* chctl flags lock */
  466. void *local_openclose_args_base; /* base address of kmalloc'd space */
  467. struct xpc_openclose_args *local_openclose_args; /* local's args */
  468. void *remote_openclose_args_base; /* base address of kmalloc'd space */
  469. struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
  470. /* args */
  471. /* channel manager related fields */
  472. atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
  473. wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
  474. union {
  475. struct xpc_partition_sn2 sn2;
  476. struct xpc_partition_uv uv;
  477. } sn;
  478. } ____cacheline_aligned;
  479. /* struct xpc_partition act_state values (for XPC HB) */
  480. #define XPC_P_INACTIVE 0x00 /* partition is not active */
  481. #define XPC_P_ACTIVATION_REQ 0x01 /* created thread to activate */
  482. #define XPC_P_ACTIVATING 0x02 /* activation thread started */
  483. #define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */
  484. #define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */
  485. #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
  486. xpc_deactivate_partition(__LINE__, (_p), (_reason))
  487. /* struct xpc_partition setup_state values */
  488. #define XPC_P_UNSET 0x00 /* infrastructure was never setup */
  489. #define XPC_P_SETUP 0x01 /* infrastructure is setup */
  490. #define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
  491. #define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */
  492. /*
  493. * struct xpc_partition_sn2's dropped notify IRQ timer is set to wait the
  494. * following interval #of seconds before checking for dropped notify IRQs.
  495. * These can occur whenever an IRQ's associated amo write doesn't complete
  496. * until after the IRQ was received.
  497. */
  498. #define XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL (0.25 * HZ)
  499. /* number of seconds to wait for other partitions to disengage */
  500. #define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90
  501. /* interval in seconds to print 'waiting deactivation' messages */
  502. #define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10
  503. #define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0]))
  504. /* found in xp_main.c */
  505. extern struct xpc_registration xpc_registrations[];
  506. /* found in xpc_main.c */
  507. extern struct device *xpc_part;
  508. extern struct device *xpc_chan;
  509. extern int xpc_disengage_timelimit;
  510. extern int xpc_disengage_timedout;
  511. extern atomic_t xpc_activate_IRQ_rcvd;
  512. extern wait_queue_head_t xpc_activate_IRQ_wq;
  513. extern void *xpc_heartbeating_to_mask;
  514. extern void xpc_activate_partition(struct xpc_partition *);
  515. extern void xpc_activate_kthreads(struct xpc_channel *, int);
  516. extern void xpc_create_kthreads(struct xpc_channel *, int, int);
  517. extern void xpc_disconnect_wait(int);
  518. extern enum xp_retval (*xpc_get_partition_rsvd_page_pa) (u64, u64 *, u64 *,
  519. size_t *);
  520. extern enum xp_retval (*xpc_rsvd_page_init) (struct xpc_rsvd_page *);
  521. extern void (*xpc_heartbeat_init) (void);
  522. extern void (*xpc_heartbeat_exit) (void);
  523. extern void (*xpc_increment_heartbeat) (void);
  524. extern void (*xpc_offline_heartbeat) (void);
  525. extern void (*xpc_online_heartbeat) (void);
  526. extern void (*xpc_check_remote_hb) (void);
  527. extern enum xp_retval (*xpc_make_first_contact) (struct xpc_partition *);
  528. extern u64 (*xpc_get_chctl_all_flags) (struct xpc_partition *);
  529. extern enum xp_retval (*xpc_allocate_msgqueues) (struct xpc_channel *);
  530. extern void (*xpc_free_msgqueues) (struct xpc_channel *);
  531. extern void (*xpc_notify_senders_of_disconnect) (struct xpc_channel *);
  532. extern void (*xpc_process_msg_chctl_flags) (struct xpc_partition *, int);
  533. extern int (*xpc_n_of_deliverable_msgs) (struct xpc_channel *);
  534. extern struct xpc_msg *(*xpc_get_deliverable_msg) (struct xpc_channel *);
  535. extern void (*xpc_request_partition_activation) (struct xpc_rsvd_page *, u64,
  536. int);
  537. extern void (*xpc_request_partition_reactivation) (struct xpc_partition *);
  538. extern void (*xpc_request_partition_deactivation) (struct xpc_partition *);
  539. extern void (*xpc_cancel_partition_deactivation_request) (
  540. struct xpc_partition *);
  541. extern void (*xpc_process_activate_IRQ_rcvd) (int);
  542. extern enum xp_retval (*xpc_setup_infrastructure) (struct xpc_partition *);
  543. extern void (*xpc_teardown_infrastructure) (struct xpc_partition *);
  544. extern void (*xpc_indicate_partition_engaged) (struct xpc_partition *);
  545. extern int (*xpc_partition_engaged) (short);
  546. extern int (*xpc_any_partition_engaged) (void);
  547. extern void (*xpc_indicate_partition_disengaged) (struct xpc_partition *);
  548. extern void (*xpc_assume_partition_disengaged) (short);
  549. extern void (*xpc_send_chctl_closerequest) (struct xpc_channel *,
  550. unsigned long *);
  551. extern void (*xpc_send_chctl_closereply) (struct xpc_channel *,
  552. unsigned long *);
  553. extern void (*xpc_send_chctl_openrequest) (struct xpc_channel *,
  554. unsigned long *);
  555. extern void (*xpc_send_chctl_openreply) (struct xpc_channel *, unsigned long *);
  556. extern enum xp_retval (*xpc_send_msg) (struct xpc_channel *, u32, void *, u16,
  557. u8, xpc_notify_func, void *);
  558. extern void (*xpc_received_msg) (struct xpc_channel *, struct xpc_msg *);
  559. /* found in xpc_sn2.c */
  560. extern int xpc_init_sn2(void);
  561. extern void xpc_exit_sn2(void);
  562. /* found in xpc_uv.c */
  563. extern void xpc_init_uv(void);
  564. extern void xpc_exit_uv(void);
  565. /* found in xpc_partition.c */
  566. extern int xpc_exiting;
  567. extern int xpc_nasid_mask_nlongs;
  568. extern struct xpc_rsvd_page *xpc_rsvd_page;
  569. extern unsigned long *xpc_mach_nasids;
  570. extern struct xpc_partition *xpc_partitions;
  571. extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
  572. extern struct xpc_rsvd_page *xpc_setup_rsvd_page(void);
  573. extern int xpc_identify_activate_IRQ_sender(void);
  574. extern int xpc_partition_disengaged(struct xpc_partition *);
  575. extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
  576. extern void xpc_mark_partition_inactive(struct xpc_partition *);
  577. extern void xpc_discovery(void);
  578. extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
  579. struct xpc_rsvd_page *, u64 *);
  580. extern void xpc_deactivate_partition(const int, struct xpc_partition *,
  581. enum xp_retval);
  582. extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
  583. /* found in xpc_channel.c */
  584. extern void xpc_initiate_connect(int);
  585. extern void xpc_initiate_disconnect(int);
  586. extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
  587. extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
  588. extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
  589. xpc_notify_func, void *);
  590. extern void xpc_initiate_received(short, int, void *);
  591. extern void xpc_process_sent_chctl_flags(struct xpc_partition *);
  592. extern void xpc_connected_callout(struct xpc_channel *);
  593. extern void xpc_deliver_msg(struct xpc_channel *);
  594. extern void xpc_disconnect_channel(const int, struct xpc_channel *,
  595. enum xp_retval, unsigned long *);
  596. extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
  597. extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
  598. static inline int
  599. xpc_hb_allowed(short partid, void *heartbeating_to_mask)
  600. {
  601. return test_bit(partid, heartbeating_to_mask);
  602. }
  603. static inline int
  604. xpc_any_hbs_allowed(void)
  605. {
  606. DBUG_ON(xpc_heartbeating_to_mask == NULL);
  607. return !bitmap_empty(xpc_heartbeating_to_mask, xp_max_npartitions);
  608. }
  609. static inline void
  610. xpc_allow_hb(short partid)
  611. {
  612. DBUG_ON(xpc_heartbeating_to_mask == NULL);
  613. set_bit(partid, xpc_heartbeating_to_mask);
  614. }
  615. static inline void
  616. xpc_disallow_hb(short partid)
  617. {
  618. DBUG_ON(xpc_heartbeating_to_mask == NULL);
  619. clear_bit(partid, xpc_heartbeating_to_mask);
  620. }
  621. static inline void
  622. xpc_disallow_all_hbs(void)
  623. {
  624. DBUG_ON(xpc_heartbeating_to_mask == NULL);
  625. bitmap_zero(xpc_heartbeating_to_mask, xp_max_npartitions);
  626. }
  627. static inline void
  628. xpc_wakeup_channel_mgr(struct xpc_partition *part)
  629. {
  630. if (atomic_inc_return(&part->channel_mgr_requests) == 1)
  631. wake_up(&part->channel_mgr_wq);
  632. }
  633. /*
  634. * These next two inlines are used to keep us from tearing down a channel's
  635. * msg queues while a thread may be referencing them.
  636. */
  637. static inline void
  638. xpc_msgqueue_ref(struct xpc_channel *ch)
  639. {
  640. atomic_inc(&ch->references);
  641. }
  642. static inline void
  643. xpc_msgqueue_deref(struct xpc_channel *ch)
  644. {
  645. s32 refs = atomic_dec_return(&ch->references);
  646. DBUG_ON(refs < 0);
  647. if (refs == 0)
  648. xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
  649. }
  650. #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
  651. xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
  652. /*
  653. * These two inlines are used to keep us from tearing down a partition's
  654. * setup infrastructure while a thread may be referencing it.
  655. */
  656. static inline void
  657. xpc_part_deref(struct xpc_partition *part)
  658. {
  659. s32 refs = atomic_dec_return(&part->references);
  660. DBUG_ON(refs < 0);
  661. if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN)
  662. wake_up(&part->teardown_wq);
  663. }
  664. static inline int
  665. xpc_part_ref(struct xpc_partition *part)
  666. {
  667. int setup;
  668. atomic_inc(&part->references);
  669. setup = (part->setup_state == XPC_P_SETUP);
  670. if (!setup)
  671. xpc_part_deref(part);
  672. return setup;
  673. }
  674. /*
  675. * The following macro is to be used for the setting of the reason and
  676. * reason_line fields in both the struct xpc_channel and struct xpc_partition
  677. * structures.
  678. */
  679. #define XPC_SET_REASON(_p, _reason, _line) \
  680. { \
  681. (_p)->reason = _reason; \
  682. (_p)->reason_line = _line; \
  683. }
  684. #endif /* _DRIVERS_MISC_SGIXP_XPC_H */