xpc.h 31 KB

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