xpc.h 32 KB

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