xpc.h 31 KB

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