xpc.h 37 KB

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