xpc.h 36 KB

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