xpc.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. * 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. unsigned long ts_jiffies; /* timestamp when rsvd pg was setup by XPC */
  86. union {
  87. struct {
  88. unsigned long vars_pa; /* phys addr */
  89. } sn2;
  90. struct {
  91. unsigned long heartbeat_gpa; /* phys addr */
  92. unsigned long activate_gru_mq_desc_gpa; /* phys addr */
  93. } uv;
  94. } sn;
  95. u64 pad2[9]; /* align to last u64 in 2nd 64-byte cacheline */
  96. u64 SAL_nasids_size; /* SAL: size of each nasid mask in bytes */
  97. };
  98. #define XPC_RP_VERSION _XPC_VERSION(3, 0) /* version 3.0 of the reserved page */
  99. /*
  100. * Define the structures by which XPC variables can be exported to other
  101. * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
  102. */
  103. /*
  104. * The following structure describes the partition generic variables
  105. * needed by other partitions in order to properly initialize.
  106. *
  107. * struct xpc_vars version number also applies to struct xpc_vars_part.
  108. * Changes to either structure and/or related functionality should be
  109. * reflected by incrementing either the major or minor version numbers
  110. * of struct xpc_vars.
  111. */
  112. struct xpc_vars_sn2 {
  113. u8 version;
  114. u64 heartbeat;
  115. DECLARE_BITMAP(heartbeating_to_mask, XP_MAX_NPARTITIONS_SN2);
  116. u64 heartbeat_offline; /* if 0, heartbeat should be changing */
  117. int activate_IRQ_nasid;
  118. int activate_IRQ_phys_cpuid;
  119. unsigned long vars_part_pa;
  120. unsigned long amos_page_pa;/* paddr of page of amos from MSPEC driver */
  121. struct amo *amos_page; /* vaddr of page of amos from MSPEC driver */
  122. };
  123. #define XPC_V_VERSION _XPC_VERSION(3, 1) /* version 3.1 of the cross vars */
  124. /*
  125. * The following structure describes the per partition specific variables.
  126. *
  127. * An array of these structures, one per partition, will be defined. As a
  128. * partition becomes active XPC will copy the array entry corresponding to
  129. * itself from that partition. It is desirable that the size of this structure
  130. * evenly divides into a 128-byte cacheline, such that none of the entries in
  131. * this array crosses a 128-byte cacheline boundary. As it is now, each entry
  132. * occupies 64-bytes.
  133. */
  134. struct xpc_vars_part_sn2 {
  135. u64 magic;
  136. unsigned long openclose_args_pa; /* phys addr of open and close args */
  137. unsigned long GPs_pa; /* physical address of Get/Put values */
  138. unsigned long chctl_amo_pa; /* physical address of chctl flags' amo */
  139. int notify_IRQ_nasid; /* nasid of where to send notify IRQs */
  140. int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */
  141. u8 nchannels; /* #of defined channels supported */
  142. u8 reserved[23]; /* pad to a full 64 bytes */
  143. };
  144. /*
  145. * The vars_part MAGIC numbers play a part in the first contact protocol.
  146. *
  147. * MAGIC1 indicates that the per partition specific variables for a remote
  148. * partition have been initialized by this partition.
  149. *
  150. * MAGIC2 indicates that this partition has pulled the remote partititions
  151. * per partition variables that pertain to this partition.
  152. */
  153. #define XPC_VP_MAGIC1_SN2 0x0053524156435058L /* 'XPCVARS\0'L (little endian) */
  154. #define XPC_VP_MAGIC2_SN2 0x0073726176435058L /* 'XPCvars\0'L (little endian) */
  155. /* the reserved page sizes and offsets */
  156. #define XPC_RP_HEADER_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page))
  157. #define XPC_RP_VARS_SIZE L1_CACHE_ALIGN(sizeof(struct xpc_vars_sn2))
  158. #define XPC_RP_PART_NASIDS(_rp) ((unsigned long *)((u8 *)(_rp) + \
  159. XPC_RP_HEADER_SIZE))
  160. #define XPC_RP_MACH_NASIDS(_rp) (XPC_RP_PART_NASIDS(_rp) + \
  161. xpc_nasid_mask_nlongs)
  162. #define XPC_RP_VARS(_rp) ((struct xpc_vars_sn2 *) \
  163. (XPC_RP_MACH_NASIDS(_rp) + \
  164. xpc_nasid_mask_nlongs))
  165. /*
  166. * The following structure describes the partition's heartbeat info which
  167. * will be periodically read by other partitions to determine whether this
  168. * XPC is still 'alive'.
  169. */
  170. struct xpc_heartbeat_uv {
  171. unsigned long value;
  172. unsigned long offline; /* if 0, heartbeat should be changing */
  173. };
  174. /*
  175. * Info pertinent to a GRU message queue using a watch list for irq generation.
  176. */
  177. struct xpc_gru_mq_uv {
  178. void *address; /* address of GRU message queue */
  179. unsigned int order; /* size of GRU message queue as a power of 2 */
  180. int irq; /* irq raised when message is received in mq */
  181. int mmr_blade; /* blade where watchlist was allocated from */
  182. unsigned long mmr_offset; /* offset of irq mmr located on mmr_blade */
  183. unsigned long mmr_value; /* value of irq mmr located on mmr_blade */
  184. int watchlist_num; /* number of watchlist allocatd by BIOS */
  185. void *gru_mq_desc; /* opaque structure used by the GRU driver */
  186. };
  187. /*
  188. * The activate_mq is used to send/receive GRU messages that affect XPC's
  189. * partition active state and channel state. This is uv only.
  190. */
  191. struct xpc_activate_mq_msghdr_uv {
  192. unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
  193. short partid; /* sender's partid */
  194. u8 act_state; /* sender's act_state at time msg sent */
  195. u8 type; /* message's type */
  196. unsigned long rp_ts_jiffies; /* timestamp of sender's rp setup by XPC */
  197. };
  198. /* activate_mq defined message types */
  199. #define XPC_ACTIVATE_MQ_MSG_SYNC_ACT_STATE_UV 0
  200. #define XPC_ACTIVATE_MQ_MSG_ACTIVATE_REQ_UV 1
  201. #define XPC_ACTIVATE_MQ_MSG_DEACTIVATE_REQ_UV 2
  202. #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREQUEST_UV 3
  203. #define XPC_ACTIVATE_MQ_MSG_CHCTL_CLOSEREPLY_UV 4
  204. #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREQUEST_UV 5
  205. #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENREPLY_UV 6
  206. #define XPC_ACTIVATE_MQ_MSG_CHCTL_OPENCOMPLETE_UV 7
  207. #define XPC_ACTIVATE_MQ_MSG_MARK_ENGAGED_UV 8
  208. #define XPC_ACTIVATE_MQ_MSG_MARK_DISENGAGED_UV 9
  209. struct xpc_activate_mq_msg_uv {
  210. struct xpc_activate_mq_msghdr_uv hdr;
  211. };
  212. struct xpc_activate_mq_msg_activate_req_uv {
  213. struct xpc_activate_mq_msghdr_uv hdr;
  214. unsigned long rp_gpa;
  215. unsigned long heartbeat_gpa;
  216. unsigned long activate_gru_mq_desc_gpa;
  217. };
  218. struct xpc_activate_mq_msg_deactivate_req_uv {
  219. struct xpc_activate_mq_msghdr_uv hdr;
  220. enum xp_retval reason;
  221. };
  222. struct xpc_activate_mq_msg_chctl_closerequest_uv {
  223. struct xpc_activate_mq_msghdr_uv hdr;
  224. short ch_number;
  225. enum xp_retval reason;
  226. };
  227. struct xpc_activate_mq_msg_chctl_closereply_uv {
  228. struct xpc_activate_mq_msghdr_uv hdr;
  229. short ch_number;
  230. };
  231. struct xpc_activate_mq_msg_chctl_openrequest_uv {
  232. struct xpc_activate_mq_msghdr_uv hdr;
  233. short ch_number;
  234. short entry_size; /* size of notify_mq's GRU messages */
  235. short local_nentries; /* ??? Is this needed? What is? */
  236. };
  237. struct xpc_activate_mq_msg_chctl_openreply_uv {
  238. struct xpc_activate_mq_msghdr_uv hdr;
  239. short ch_number;
  240. short remote_nentries; /* ??? Is this needed? What is? */
  241. short local_nentries; /* ??? Is this needed? What is? */
  242. unsigned long notify_gru_mq_desc_gpa;
  243. };
  244. struct xpc_activate_mq_msg_chctl_opencomplete_uv {
  245. struct xpc_activate_mq_msghdr_uv hdr;
  246. short ch_number;
  247. };
  248. /*
  249. * Functions registered by add_timer() or called by kernel_thread() only
  250. * allow for a single 64-bit argument. The following macros can be used to
  251. * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
  252. * the passed argument.
  253. */
  254. #define XPC_PACK_ARGS(_arg1, _arg2) \
  255. ((((u64)_arg1) & 0xffffffff) | \
  256. ((((u64)_arg2) & 0xffffffff) << 32))
  257. #define XPC_UNPACK_ARG1(_args) (((u64)_args) & 0xffffffff)
  258. #define XPC_UNPACK_ARG2(_args) ((((u64)_args) >> 32) & 0xffffffff)
  259. /*
  260. * Define a Get/Put value pair (pointers) used with a message queue.
  261. */
  262. struct xpc_gp_sn2 {
  263. s64 get; /* Get value */
  264. s64 put; /* Put value */
  265. };
  266. #define XPC_GP_SIZE \
  267. L1_CACHE_ALIGN(sizeof(struct xpc_gp_sn2) * XPC_MAX_NCHANNELS)
  268. /*
  269. * Define a structure that contains arguments associated with opening and
  270. * closing a channel.
  271. */
  272. struct xpc_openclose_args {
  273. u16 reason; /* reason why channel is closing */
  274. u16 entry_size; /* sizeof each message entry */
  275. u16 remote_nentries; /* #of message entries in remote msg queue */
  276. u16 local_nentries; /* #of message entries in local msg queue */
  277. unsigned long local_msgqueue_pa; /* phys addr of local message queue */
  278. };
  279. #define XPC_OPENCLOSE_ARGS_SIZE \
  280. L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * \
  281. XPC_MAX_NCHANNELS)
  282. /*
  283. * Structures to define a fifo singly-linked list.
  284. */
  285. struct xpc_fifo_entry_uv {
  286. struct xpc_fifo_entry_uv *next;
  287. };
  288. struct xpc_fifo_head_uv {
  289. struct xpc_fifo_entry_uv *first;
  290. struct xpc_fifo_entry_uv *last;
  291. spinlock_t lock;
  292. int n_entries;
  293. };
  294. /*
  295. * Define a sn2 styled message.
  296. *
  297. * A user-defined message resides in the payload area. The max size of the
  298. * payload is defined by the user via xpc_connect().
  299. *
  300. * The size of a message entry (within a message queue) must be a 128-byte
  301. * cacheline sized multiple in order to facilitate the BTE transfer of messages
  302. * from one message queue to another.
  303. */
  304. struct xpc_msg_sn2 {
  305. u8 flags; /* FOR XPC INTERNAL USE ONLY */
  306. u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */
  307. s64 number; /* FOR XPC INTERNAL USE ONLY */
  308. u64 payload; /* user defined portion of message */
  309. };
  310. /* struct xpc_msg_sn2 flags */
  311. #define XPC_M_SN2_DONE 0x01 /* msg has been received/consumed */
  312. #define XPC_M_SN2_READY 0x02 /* msg is ready to be sent */
  313. #define XPC_M_SN2_INTERRUPT 0x04 /* send interrupt when msg consumed */
  314. /*
  315. * The format of a uv XPC notify_mq GRU message is as follows:
  316. *
  317. * A user-defined message resides in the payload area. The max size of the
  318. * payload is defined by the user via xpc_connect().
  319. *
  320. * The size of a message (payload and header) sent via the GRU must be either 1
  321. * or 2 GRU_CACHE_LINE_BYTES in length.
  322. */
  323. struct xpc_notify_mq_msghdr_uv {
  324. union {
  325. unsigned int gru_msg_hdr; /* FOR GRU INTERNAL USE ONLY */
  326. struct xpc_fifo_entry_uv next; /* FOR XPC INTERNAL USE ONLY */
  327. } u;
  328. short partid; /* FOR XPC INTERNAL USE ONLY */
  329. u8 ch_number; /* FOR XPC INTERNAL USE ONLY */
  330. u8 size; /* FOR XPC INTERNAL USE ONLY */
  331. unsigned int msg_slot_number; /* FOR XPC INTERNAL USE ONLY */
  332. };
  333. struct xpc_notify_mq_msg_uv {
  334. struct xpc_notify_mq_msghdr_uv hdr;
  335. unsigned long payload;
  336. };
  337. /*
  338. * Define sn2's notify entry.
  339. *
  340. * This is used to notify a message's sender that their message was received
  341. * and consumed by the intended recipient.
  342. */
  343. struct xpc_notify_sn2 {
  344. u8 type; /* type of notification */
  345. /* the following two fields are only used if type == XPC_N_CALL */
  346. xpc_notify_func func; /* user's notify function */
  347. void *key; /* pointer to user's key */
  348. };
  349. /* struct xpc_notify_sn2 type of notification */
  350. #define XPC_N_CALL 0x01 /* notify function provided by user */
  351. /*
  352. * Define uv's version of the notify entry. It additionally is used to allocate
  353. * a msg slot on the remote partition into which is copied a sent message.
  354. */
  355. struct xpc_send_msg_slot_uv {
  356. struct xpc_fifo_entry_uv next;
  357. unsigned int msg_slot_number;
  358. xpc_notify_func func; /* user's notify function */
  359. void *key; /* pointer to user's key */
  360. };
  361. /*
  362. * Define the structure that manages all the stuff required by a channel. In
  363. * particular, they are used to manage the messages sent across the channel.
  364. *
  365. * This structure is private to a partition, and is NOT shared across the
  366. * partition boundary.
  367. *
  368. * There is an array of these structures for each remote partition. It is
  369. * allocated at the time a partition becomes active. The array contains one
  370. * of these structures for each potential channel connection to that partition.
  371. */
  372. /*
  373. * The following is sn2 only.
  374. *
  375. * Each channel structure manages two message queues (circular buffers).
  376. * They are allocated at the time a channel connection is made. One of
  377. * these message queues (local_msgqueue) holds the locally created messages
  378. * that are destined for the remote partition. The other of these message
  379. * queues (remote_msgqueue) is a locally cached copy of the remote partition's
  380. * own local_msgqueue.
  381. *
  382. * The following is a description of the Get/Put pointers used to manage these
  383. * two message queues. Consider the local_msgqueue to be on one partition
  384. * and the remote_msgqueue to be its cached copy on another partition. A
  385. * description of what each of the lettered areas contains is included.
  386. *
  387. *
  388. * local_msgqueue remote_msgqueue
  389. *
  390. * |/////////| |/////////|
  391. * w_remote_GP.get --> +---------+ |/////////|
  392. * | F | |/////////|
  393. * remote_GP.get --> +---------+ +---------+ <-- local_GP->get
  394. * | | | |
  395. * | | | E |
  396. * | | | |
  397. * | | +---------+ <-- w_local_GP.get
  398. * | B | |/////////|
  399. * | | |////D////|
  400. * | | |/////////|
  401. * | | +---------+ <-- w_remote_GP.put
  402. * | | |////C////|
  403. * local_GP->put --> +---------+ +---------+ <-- remote_GP.put
  404. * | | |/////////|
  405. * | A | |/////////|
  406. * | | |/////////|
  407. * w_local_GP.put --> +---------+ |/////////|
  408. * |/////////| |/////////|
  409. *
  410. *
  411. * ( remote_GP.[get|put] are cached copies of the remote
  412. * partition's local_GP->[get|put], and thus their values can
  413. * lag behind their counterparts on the remote partition. )
  414. *
  415. *
  416. * A - Messages that have been allocated, but have not yet been sent to the
  417. * remote partition.
  418. *
  419. * B - Messages that have been sent, but have not yet been acknowledged by the
  420. * remote partition as having been received.
  421. *
  422. * C - Area that needs to be prepared for the copying of sent messages, by
  423. * the clearing of the message flags of any previously received messages.
  424. *
  425. * D - Area into which sent messages are to be copied from the remote
  426. * partition's local_msgqueue and then delivered to their intended
  427. * recipients. [ To allow for a multi-message copy, another pointer
  428. * (next_msg_to_pull) has been added to keep track of the next message
  429. * number needing to be copied (pulled). It chases after w_remote_GP.put.
  430. * Any messages lying between w_local_GP.get and next_msg_to_pull have
  431. * been copied and are ready to be delivered. ]
  432. *
  433. * E - Messages that have been copied and delivered, but have not yet been
  434. * acknowledged by the recipient as having been received.
  435. *
  436. * F - Messages that have been acknowledged, but XPC has not yet notified the
  437. * sender that the message was received by its intended recipient.
  438. * This is also an area that needs to be prepared for the allocating of
  439. * new messages, by the clearing of the message flags of the acknowledged
  440. * messages.
  441. */
  442. struct xpc_channel_sn2 {
  443. struct xpc_openclose_args *local_openclose_args; /* args passed on */
  444. /* opening or closing of channel */
  445. void *local_msgqueue_base; /* base address of kmalloc'd space */
  446. struct xpc_msg_sn2 *local_msgqueue; /* local message queue */
  447. void *remote_msgqueue_base; /* base address of kmalloc'd space */
  448. struct xpc_msg_sn2 *remote_msgqueue; /* cached copy of remote */
  449. /* partition's local message queue */
  450. unsigned long remote_msgqueue_pa; /* phys addr of remote partition's */
  451. /* local message queue */
  452. struct xpc_notify_sn2 *notify_queue;/* notify queue for messages sent */
  453. /* various flavors of local and remote Get/Put values */
  454. struct xpc_gp_sn2 *local_GP; /* local Get/Put values */
  455. struct xpc_gp_sn2 remote_GP; /* remote Get/Put values */
  456. struct xpc_gp_sn2 w_local_GP; /* working local Get/Put values */
  457. struct xpc_gp_sn2 w_remote_GP; /* working remote Get/Put values */
  458. s64 next_msg_to_pull; /* Put value of next msg to pull */
  459. struct mutex msg_to_pull_mutex; /* next msg to pull serialization */
  460. };
  461. struct xpc_channel_uv {
  462. void *cached_notify_gru_mq_desc; /* remote partition's notify mq's */
  463. /* gru mq descriptor */
  464. struct xpc_send_msg_slot_uv *send_msg_slots;
  465. void *recv_msg_slots; /* each slot will hold a xpc_notify_mq_msg_uv */
  466. /* structure plus the user's payload */
  467. struct xpc_fifo_head_uv msg_slot_free_list;
  468. struct xpc_fifo_head_uv recv_msg_list; /* deliverable payloads */
  469. };
  470. struct xpc_channel {
  471. short partid; /* ID of remote partition connected */
  472. spinlock_t lock; /* lock for updating this structure */
  473. unsigned int flags; /* general flags */
  474. enum xp_retval reason; /* reason why channel is disconnect'g */
  475. int reason_line; /* line# disconnect initiated from */
  476. u16 number; /* channel # */
  477. u16 entry_size; /* sizeof each msg entry */
  478. u16 local_nentries; /* #of msg entries in local msg queue */
  479. u16 remote_nentries; /* #of msg entries in remote msg queue */
  480. atomic_t references; /* #of external references to queues */
  481. atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
  482. wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
  483. u8 delayed_chctl_flags; /* chctl flags received, but delayed */
  484. /* action until channel disconnected */
  485. atomic_t n_to_notify; /* #of msg senders to notify */
  486. xpc_channel_func func; /* user's channel function */
  487. void *key; /* pointer to user's key */
  488. struct completion wdisconnect_wait; /* wait for channel disconnect */
  489. /* kthread management related fields */
  490. atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
  491. u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
  492. atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
  493. u32 kthreads_idle_limit; /* limit on #of kthreads idle */
  494. atomic_t kthreads_active; /* #of kthreads actively working */
  495. wait_queue_head_t idle_wq; /* idle kthread wait queue */
  496. union {
  497. struct xpc_channel_sn2 sn2;
  498. struct xpc_channel_uv uv;
  499. } sn;
  500. } ____cacheline_aligned;
  501. /* struct xpc_channel flags */
  502. #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
  503. #define XPC_C_ROPENCOMPLETE 0x00000002 /* remote open channel complete */
  504. #define XPC_C_OPENCOMPLETE 0x00000004 /* local open channel complete */
  505. #define XPC_C_ROPENREPLY 0x00000008 /* remote open channel reply */
  506. #define XPC_C_OPENREPLY 0x00000010 /* local open channel reply */
  507. #define XPC_C_ROPENREQUEST 0x00000020 /* remote open channel request */
  508. #define XPC_C_OPENREQUEST 0x00000040 /* local open channel request */
  509. #define XPC_C_SETUP 0x00000080 /* channel's msgqueues are alloc'd */
  510. #define XPC_C_CONNECTEDCALLOUT 0x00000100 /* connected callout initiated */
  511. #define XPC_C_CONNECTEDCALLOUT_MADE \
  512. 0x00000200 /* connected callout completed */
  513. #define XPC_C_CONNECTED 0x00000400 /* local channel is connected */
  514. #define XPC_C_CONNECTING 0x00000800 /* channel is being connected */
  515. #define XPC_C_RCLOSEREPLY 0x00001000 /* remote close channel reply */
  516. #define XPC_C_CLOSEREPLY 0x00002000 /* local close channel reply */
  517. #define XPC_C_RCLOSEREQUEST 0x00004000 /* remote close channel request */
  518. #define XPC_C_CLOSEREQUEST 0x00008000 /* local close channel request */
  519. #define XPC_C_DISCONNECTED 0x00010000 /* channel is disconnected */
  520. #define XPC_C_DISCONNECTING 0x00020000 /* channel is being disconnected */
  521. #define XPC_C_DISCONNECTINGCALLOUT \
  522. 0x00040000 /* disconnecting callout initiated */
  523. #define XPC_C_DISCONNECTINGCALLOUT_MADE \
  524. 0x00080000 /* disconnecting callout completed */
  525. #define XPC_C_WDISCONNECT 0x00100000 /* waiting for channel disconnect */
  526. /*
  527. * The channel control flags (chctl) union consists of a 64-bit variable which
  528. * is divided up into eight bytes, ordered from right to left. Byte zero
  529. * pertains to channel 0, byte one to channel 1, and so on. Each channel's byte
  530. * can have one or more of the chctl flags set in it.
  531. */
  532. union xpc_channel_ctl_flags {
  533. u64 all_flags;
  534. u8 flags[XPC_MAX_NCHANNELS];
  535. };
  536. /* chctl flags */
  537. #define XPC_CHCTL_CLOSEREQUEST 0x01
  538. #define XPC_CHCTL_CLOSEREPLY 0x02
  539. #define XPC_CHCTL_OPENREQUEST 0x04
  540. #define XPC_CHCTL_OPENREPLY 0x08
  541. #define XPC_CHCTL_OPENCOMPLETE 0x10
  542. #define XPC_CHCTL_MSGREQUEST 0x20
  543. #define XPC_OPENCLOSE_CHCTL_FLAGS \
  544. (XPC_CHCTL_CLOSEREQUEST | XPC_CHCTL_CLOSEREPLY | \
  545. XPC_CHCTL_OPENREQUEST | XPC_CHCTL_OPENREPLY | \
  546. XPC_CHCTL_OPENCOMPLETE)
  547. #define XPC_MSG_CHCTL_FLAGS XPC_CHCTL_MSGREQUEST
  548. static inline int
  549. xpc_any_openclose_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
  550. {
  551. int ch_number;
  552. for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
  553. if (chctl->flags[ch_number] & XPC_OPENCLOSE_CHCTL_FLAGS)
  554. return 1;
  555. }
  556. return 0;
  557. }
  558. static inline int
  559. xpc_any_msg_chctl_flags_set(union xpc_channel_ctl_flags *chctl)
  560. {
  561. int ch_number;
  562. for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) {
  563. if (chctl->flags[ch_number] & XPC_MSG_CHCTL_FLAGS)
  564. return 1;
  565. }
  566. return 0;
  567. }
  568. /*
  569. * Manage channels on a partition basis. There is one of these structures
  570. * for each partition (a partition will never utilize the structure that
  571. * represents itself).
  572. */
  573. struct xpc_partition_sn2 {
  574. unsigned long remote_amos_page_pa; /* paddr of partition's amos page */
  575. int activate_IRQ_nasid; /* active partition's act/deact nasid */
  576. int activate_IRQ_phys_cpuid; /* active part's act/deact phys cpuid */
  577. unsigned long remote_vars_pa; /* phys addr of partition's vars */
  578. unsigned long remote_vars_part_pa; /* paddr of partition's vars part */
  579. u8 remote_vars_version; /* version# of partition's vars */
  580. void *local_GPs_base; /* base address of kmalloc'd space */
  581. struct xpc_gp_sn2 *local_GPs; /* local Get/Put values */
  582. void *remote_GPs_base; /* base address of kmalloc'd space */
  583. struct xpc_gp_sn2 *remote_GPs; /* copy of remote partition's local */
  584. /* Get/Put values */
  585. unsigned long remote_GPs_pa; /* phys addr of remote partition's local */
  586. /* Get/Put values */
  587. void *local_openclose_args_base; /* base address of kmalloc'd space */
  588. struct xpc_openclose_args *local_openclose_args; /* local's args */
  589. unsigned long remote_openclose_args_pa; /* phys addr of remote's args */
  590. int notify_IRQ_nasid; /* nasid of where to send notify IRQs */
  591. int notify_IRQ_phys_cpuid; /* CPUID of where to send notify IRQs */
  592. char notify_IRQ_owner[8]; /* notify IRQ's owner's name */
  593. struct amo *remote_chctl_amo_va; /* addr of remote chctl flags' amo */
  594. struct amo *local_chctl_amo_va; /* address of chctl flags' amo */
  595. struct timer_list dropped_notify_IRQ_timer; /* dropped IRQ timer */
  596. };
  597. struct xpc_partition_uv {
  598. unsigned long heartbeat_gpa; /* phys addr of partition's heartbeat */
  599. struct xpc_heartbeat_uv cached_heartbeat; /* cached copy of */
  600. /* partition's heartbeat */
  601. unsigned long activate_gru_mq_desc_gpa; /* phys addr of parititon's */
  602. /* activate mq's gru mq */
  603. /* descriptor */
  604. void *cached_activate_gru_mq_desc; /* cached copy of partition's */
  605. /* activate mq's gru mq descriptor */
  606. struct mutex cached_activate_gru_mq_desc_mutex;
  607. spinlock_t flags_lock; /* protect updating of flags */
  608. unsigned int flags; /* general flags */
  609. u8 remote_act_state; /* remote partition's act_state */
  610. u8 act_state_req; /* act_state request from remote partition */
  611. enum xp_retval reason; /* reason for deactivate act_state request */
  612. };
  613. /* struct xpc_partition_uv flags */
  614. #define XPC_P_CACHED_ACTIVATE_GRU_MQ_DESC_UV 0x00000001
  615. #define XPC_P_ENGAGED_UV 0x00000002
  616. /* struct xpc_partition_uv act_state change requests */
  617. #define XPC_P_ASR_ACTIVATE_UV 0x01
  618. #define XPC_P_ASR_REACTIVATE_UV 0x02
  619. #define XPC_P_ASR_DEACTIVATE_UV 0x03
  620. struct xpc_partition {
  621. /* XPC HB infrastructure */
  622. u8 remote_rp_version; /* version# of partition's rsvd pg */
  623. unsigned long remote_rp_ts_jiffies; /* timestamp when rsvd pg setup */
  624. unsigned long remote_rp_pa; /* phys addr of partition's rsvd pg */
  625. u64 last_heartbeat; /* HB at last read */
  626. u32 activate_IRQ_rcvd; /* IRQs since activation */
  627. spinlock_t act_lock; /* protect updating of act_state */
  628. u8 act_state; /* from XPC HB viewpoint */
  629. enum xp_retval reason; /* reason partition is deactivating */
  630. int reason_line; /* line# deactivation initiated from */
  631. unsigned long disengage_timeout; /* timeout in jiffies */
  632. struct timer_list disengage_timer;
  633. /* XPC infrastructure referencing and teardown control */
  634. u8 setup_state; /* infrastructure setup state */
  635. wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
  636. atomic_t references; /* #of references to infrastructure */
  637. u8 nchannels; /* #of defined channels supported */
  638. atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
  639. atomic_t nchannels_engaged; /* #of channels engaged with remote part */
  640. struct xpc_channel *channels; /* array of channel structures */
  641. /* fields used for managing channel avialability and activity */
  642. union xpc_channel_ctl_flags chctl; /* chctl flags yet to be processed */
  643. spinlock_t chctl_lock; /* chctl flags lock */
  644. void *remote_openclose_args_base; /* base address of kmalloc'd space */
  645. struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
  646. /* args */
  647. /* channel manager related fields */
  648. atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
  649. wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
  650. union {
  651. struct xpc_partition_sn2 sn2;
  652. struct xpc_partition_uv uv;
  653. } sn;
  654. } ____cacheline_aligned;
  655. struct xpc_arch_operations {
  656. int (*setup_partitions) (void);
  657. void (*teardown_partitions) (void);
  658. void (*process_activate_IRQ_rcvd) (void);
  659. enum xp_retval (*get_partition_rsvd_page_pa)
  660. (void *, u64 *, unsigned long *, size_t *);
  661. int (*setup_rsvd_page) (struct xpc_rsvd_page *);
  662. void (*allow_hb) (short);
  663. void (*disallow_hb) (short);
  664. void (*disallow_all_hbs) (void);
  665. void (*increment_heartbeat) (void);
  666. void (*offline_heartbeat) (void);
  667. void (*online_heartbeat) (void);
  668. void (*heartbeat_init) (void);
  669. void (*heartbeat_exit) (void);
  670. enum xp_retval (*get_remote_heartbeat) (struct xpc_partition *);
  671. void (*request_partition_activation) (struct xpc_rsvd_page *,
  672. unsigned long, int);
  673. void (*request_partition_reactivation) (struct xpc_partition *);
  674. void (*request_partition_deactivation) (struct xpc_partition *);
  675. void (*cancel_partition_deactivation_request) (struct xpc_partition *);
  676. enum xp_retval (*setup_ch_structures) (struct xpc_partition *);
  677. void (*teardown_ch_structures) (struct xpc_partition *);
  678. enum xp_retval (*make_first_contact) (struct xpc_partition *);
  679. u64 (*get_chctl_all_flags) (struct xpc_partition *);
  680. void (*send_chctl_closerequest) (struct xpc_channel *, unsigned long *);
  681. void (*send_chctl_closereply) (struct xpc_channel *, unsigned long *);
  682. void (*send_chctl_openrequest) (struct xpc_channel *, unsigned long *);
  683. void (*send_chctl_openreply) (struct xpc_channel *, unsigned long *);
  684. void (*send_chctl_opencomplete) (struct xpc_channel *, unsigned long *);
  685. void (*process_msg_chctl_flags) (struct xpc_partition *, int);
  686. enum xp_retval (*save_remote_msgqueue_pa) (struct xpc_channel *,
  687. unsigned long);
  688. enum xp_retval (*setup_msg_structures) (struct xpc_channel *);
  689. void (*teardown_msg_structures) (struct xpc_channel *);
  690. void (*indicate_partition_engaged) (struct xpc_partition *);
  691. void (*indicate_partition_disengaged) (struct xpc_partition *);
  692. void (*assume_partition_disengaged) (short);
  693. int (*partition_engaged) (short);
  694. int (*any_partition_engaged) (void);
  695. int (*n_of_deliverable_payloads) (struct xpc_channel *);
  696. enum xp_retval (*send_payload) (struct xpc_channel *, u32, void *,
  697. u16, u8, xpc_notify_func, void *);
  698. void *(*get_deliverable_payload) (struct xpc_channel *);
  699. void (*received_payload) (struct xpc_channel *, void *);
  700. void (*notify_senders_of_disconnect) (struct xpc_channel *);
  701. };
  702. /* struct xpc_partition act_state values (for XPC HB) */
  703. #define XPC_P_AS_INACTIVE 0x00 /* partition is not active */
  704. #define XPC_P_AS_ACTIVATION_REQ 0x01 /* created thread to activate */
  705. #define XPC_P_AS_ACTIVATING 0x02 /* activation thread started */
  706. #define XPC_P_AS_ACTIVE 0x03 /* xpc_partition_up() was called */
  707. #define XPC_P_AS_DEACTIVATING 0x04 /* partition deactivation initiated */
  708. #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
  709. xpc_deactivate_partition(__LINE__, (_p), (_reason))
  710. /* struct xpc_partition setup_state values */
  711. #define XPC_P_SS_UNSET 0x00 /* infrastructure was never setup */
  712. #define XPC_P_SS_SETUP 0x01 /* infrastructure is setup */
  713. #define XPC_P_SS_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
  714. #define XPC_P_SS_TORNDOWN 0x03 /* infrastructure is torndown */
  715. /*
  716. * struct xpc_partition_sn2's dropped notify IRQ timer is set to wait the
  717. * following interval #of seconds before checking for dropped notify IRQs.
  718. * These can occur whenever an IRQ's associated amo write doesn't complete
  719. * until after the IRQ was received.
  720. */
  721. #define XPC_DROPPED_NOTIFY_IRQ_WAIT_INTERVAL (0.25 * HZ)
  722. /* number of seconds to wait for other partitions to disengage */
  723. #define XPC_DISENGAGE_DEFAULT_TIMELIMIT 90
  724. /* interval in seconds to print 'waiting deactivation' messages */
  725. #define XPC_DEACTIVATE_PRINTMSG_INTERVAL 10
  726. #define XPC_PARTID(_p) ((short)((_p) - &xpc_partitions[0]))
  727. /* found in xp_main.c */
  728. extern struct xpc_registration xpc_registrations[];
  729. /* found in xpc_main.c */
  730. extern struct device *xpc_part;
  731. extern struct device *xpc_chan;
  732. extern struct xpc_arch_operations xpc_arch_ops;
  733. extern int xpc_disengage_timelimit;
  734. extern int xpc_disengage_timedout;
  735. extern int xpc_activate_IRQ_rcvd;
  736. extern spinlock_t xpc_activate_IRQ_rcvd_lock;
  737. extern wait_queue_head_t xpc_activate_IRQ_wq;
  738. extern void *xpc_kzalloc_cacheline_aligned(size_t, gfp_t, void **);
  739. extern void xpc_activate_partition(struct xpc_partition *);
  740. extern void xpc_activate_kthreads(struct xpc_channel *, int);
  741. extern void xpc_create_kthreads(struct xpc_channel *, int, int);
  742. extern void xpc_disconnect_wait(int);
  743. /* found in xpc_sn2.c */
  744. extern int xpc_init_sn2(void);
  745. extern void xpc_exit_sn2(void);
  746. /* found in xpc_uv.c */
  747. extern int xpc_init_uv(void);
  748. extern void xpc_exit_uv(void);
  749. /* found in xpc_partition.c */
  750. extern int xpc_exiting;
  751. extern int xpc_nasid_mask_nlongs;
  752. extern struct xpc_rsvd_page *xpc_rsvd_page;
  753. extern unsigned long *xpc_mach_nasids;
  754. extern struct xpc_partition *xpc_partitions;
  755. extern void *xpc_kmalloc_cacheline_aligned(size_t, gfp_t, void **);
  756. extern int xpc_setup_rsvd_page(void);
  757. extern void xpc_teardown_rsvd_page(void);
  758. extern int xpc_identify_activate_IRQ_sender(void);
  759. extern int xpc_partition_disengaged(struct xpc_partition *);
  760. extern enum xp_retval xpc_mark_partition_active(struct xpc_partition *);
  761. extern void xpc_mark_partition_inactive(struct xpc_partition *);
  762. extern void xpc_discovery(void);
  763. extern enum xp_retval xpc_get_remote_rp(int, unsigned long *,
  764. struct xpc_rsvd_page *,
  765. unsigned long *);
  766. extern void xpc_deactivate_partition(const int, struct xpc_partition *,
  767. enum xp_retval);
  768. extern enum xp_retval xpc_initiate_partid_to_nasids(short, void *);
  769. /* found in xpc_channel.c */
  770. extern void xpc_initiate_connect(int);
  771. extern void xpc_initiate_disconnect(int);
  772. extern enum xp_retval xpc_allocate_msg_wait(struct xpc_channel *);
  773. extern enum xp_retval xpc_initiate_send(short, int, u32, void *, u16);
  774. extern enum xp_retval xpc_initiate_send_notify(short, int, u32, void *, u16,
  775. xpc_notify_func, void *);
  776. extern void xpc_initiate_received(short, int, void *);
  777. extern void xpc_process_sent_chctl_flags(struct xpc_partition *);
  778. extern void xpc_connected_callout(struct xpc_channel *);
  779. extern void xpc_deliver_payload(struct xpc_channel *);
  780. extern void xpc_disconnect_channel(const int, struct xpc_channel *,
  781. enum xp_retval, unsigned long *);
  782. extern void xpc_disconnect_callout(struct xpc_channel *, enum xp_retval);
  783. extern void xpc_partition_going_down(struct xpc_partition *, enum xp_retval);
  784. static inline void
  785. xpc_wakeup_channel_mgr(struct xpc_partition *part)
  786. {
  787. if (atomic_inc_return(&part->channel_mgr_requests) == 1)
  788. wake_up(&part->channel_mgr_wq);
  789. }
  790. /*
  791. * These next two inlines are used to keep us from tearing down a channel's
  792. * msg queues while a thread may be referencing them.
  793. */
  794. static inline void
  795. xpc_msgqueue_ref(struct xpc_channel *ch)
  796. {
  797. atomic_inc(&ch->references);
  798. }
  799. static inline void
  800. xpc_msgqueue_deref(struct xpc_channel *ch)
  801. {
  802. s32 refs = atomic_dec_return(&ch->references);
  803. DBUG_ON(refs < 0);
  804. if (refs == 0)
  805. xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
  806. }
  807. #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
  808. xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
  809. /*
  810. * These two inlines are used to keep us from tearing down a partition's
  811. * setup infrastructure while a thread may be referencing it.
  812. */
  813. static inline void
  814. xpc_part_deref(struct xpc_partition *part)
  815. {
  816. s32 refs = atomic_dec_return(&part->references);
  817. DBUG_ON(refs < 0);
  818. if (refs == 0 && part->setup_state == XPC_P_SS_WTEARDOWN)
  819. wake_up(&part->teardown_wq);
  820. }
  821. static inline int
  822. xpc_part_ref(struct xpc_partition *part)
  823. {
  824. int setup;
  825. atomic_inc(&part->references);
  826. setup = (part->setup_state == XPC_P_SS_SETUP);
  827. if (!setup)
  828. xpc_part_deref(part);
  829. return setup;
  830. }
  831. /*
  832. * The following macro is to be used for the setting of the reason and
  833. * reason_line fields in both the struct xpc_channel and struct xpc_partition
  834. * structures.
  835. */
  836. #define XPC_SET_REASON(_p, _reason, _line) \
  837. { \
  838. (_p)->reason = _reason; \
  839. (_p)->reason_line = _line; \
  840. }
  841. #endif /* _DRIVERS_MISC_SGIXP_XPC_H */