xpc.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  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-2005 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. /*
  9. * Cross Partition Communication (XPC) structures and macros.
  10. */
  11. #ifndef _IA64_SN_KERNEL_XPC_H
  12. #define _IA64_SN_KERNEL_XPC_H
  13. #include <linux/config.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/sysctl.h>
  16. #include <linux/device.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/processor.h>
  19. #include <asm/sn/bte.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 <asm/sn/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. * Reserved Page provided by SAL.
  58. *
  59. * SAL provides one page per partition of reserved memory. When SAL
  60. * initialization is complete, SAL_signature, SAL_version, partid,
  61. * part_nasids, and mach_nasids are set.
  62. *
  63. * Note: Until vars_pa is set, the partition XPC code has not been initialized.
  64. */
  65. struct xpc_rsvd_page {
  66. u64 SAL_signature; /* SAL unique signature */
  67. u64 SAL_version; /* SAL specified version */
  68. u8 partid; /* partition ID from SAL */
  69. u8 version;
  70. u8 pad[6]; /* pad to u64 align */
  71. volatile u64 vars_pa;
  72. struct timespec stamp; /* time when reserved page was initialized */
  73. u64 part_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
  74. u64 mach_nasids[XP_NASID_MASK_WORDS] ____cacheline_aligned;
  75. };
  76. #define XPC_RSVD_PAGE_ALIGNED_SIZE \
  77. (L1_CACHE_ALIGN(sizeof(struct xpc_rsvd_page)))
  78. #define XPC_RP_VERSION _XPC_VERSION(1,1) /* version 1.1 of the reserved page */
  79. #define XPC_SUPPORTS_RP_STAMP(_version) \
  80. (_version >= _XPC_VERSION(1,1))
  81. /*
  82. * compare stamps - the return value is:
  83. *
  84. * < 0, if stamp1 < stamp2
  85. * = 0, if stamp1 == stamp2
  86. * > 0, if stamp1 > stamp2
  87. */
  88. static inline int
  89. xpc_compare_stamps(struct timespec *stamp1, struct timespec *stamp2)
  90. {
  91. int ret;
  92. if ((ret = stamp1->tv_sec - stamp2->tv_sec) == 0) {
  93. ret = stamp1->tv_nsec - stamp2->tv_nsec;
  94. }
  95. return ret;
  96. }
  97. /*
  98. * Define the structures by which XPC variables can be exported to other
  99. * partitions. (There are two: struct xpc_vars and struct xpc_vars_part)
  100. */
  101. /*
  102. * The following structure describes the partition generic variables
  103. * needed by other partitions in order to properly initialize.
  104. *
  105. * struct xpc_vars version number also applies to struct xpc_vars_part.
  106. * Changes to either structure and/or related functionality should be
  107. * reflected by incrementing either the major or minor version numbers
  108. * of struct xpc_vars.
  109. */
  110. struct xpc_vars {
  111. u8 version;
  112. u64 heartbeat;
  113. u64 heartbeating_to_mask;
  114. u64 kdb_status; /* 0 = machine running */
  115. int act_nasid;
  116. int act_phys_cpuid;
  117. u64 vars_part_pa;
  118. u64 amos_page_pa; /* paddr of page of AMOs from MSPEC driver */
  119. AMO_t *amos_page; /* vaddr of page of AMOs from MSPEC driver */
  120. };
  121. #define XPC_VARS_ALIGNED_SIZE (L1_CACHE_ALIGN(sizeof(struct xpc_vars)))
  122. #define XPC_V_VERSION _XPC_VERSION(3,1) /* version 3.1 of the cross vars */
  123. #define XPC_SUPPORTS_DISENGAGE_REQUEST(_version) \
  124. (_version >= _XPC_VERSION(3,1))
  125. static inline int
  126. xpc_hb_allowed(partid_t partid, struct xpc_vars *vars)
  127. {
  128. return ((vars->heartbeating_to_mask & (1UL << partid)) != 0);
  129. }
  130. static inline void
  131. xpc_allow_hb(partid_t partid, struct xpc_vars *vars)
  132. {
  133. u64 old_mask, new_mask;
  134. do {
  135. old_mask = vars->heartbeating_to_mask;
  136. new_mask = (old_mask | (1UL << partid));
  137. } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
  138. old_mask);
  139. }
  140. static inline void
  141. xpc_disallow_hb(partid_t partid, struct xpc_vars *vars)
  142. {
  143. u64 old_mask, new_mask;
  144. do {
  145. old_mask = vars->heartbeating_to_mask;
  146. new_mask = (old_mask & ~(1UL << partid));
  147. } while (cmpxchg(&vars->heartbeating_to_mask, old_mask, new_mask) !=
  148. old_mask);
  149. }
  150. /*
  151. * The AMOs page consists of a number of AMO variables which are divided into
  152. * four groups, The first two groups are used to identify an IRQ's sender.
  153. * These two groups consist of 64 and 16 AMO variables respectively. The last
  154. * two groups, consisting of just one AMO variable each, are used to identify
  155. * the remote partitions that are currently engaged (from the viewpoint of
  156. * the XPC running on the remote partition).
  157. */
  158. #define XPC_NOTIFY_IRQ_AMOS 0
  159. #define XPC_ACTIVATE_IRQ_AMOS (XPC_NOTIFY_IRQ_AMOS + XP_MAX_PARTITIONS)
  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
  168. * structure evenly divide into a cacheline, such that none of the entries
  169. * in this array crosses a cacheline boundary. As it is now, each entry
  170. * occupies half a cacheline.
  171. */
  172. struct xpc_vars_part {
  173. volatile 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. /*
  194. * Functions registered by add_timer() or called by kernel_thread() only
  195. * allow for a single 64-bit argument. The following macros can be used to
  196. * pack and unpack two (32-bit, 16-bit or 8-bit) arguments into or out from
  197. * the passed argument.
  198. */
  199. #define XPC_PACK_ARGS(_arg1, _arg2) \
  200. ((((u64) _arg1) & 0xffffffff) | \
  201. ((((u64) _arg2) & 0xffffffff) << 32))
  202. #define XPC_UNPACK_ARG1(_args) (((u64) _args) & 0xffffffff)
  203. #define XPC_UNPACK_ARG2(_args) ((((u64) _args) >> 32) & 0xffffffff)
  204. /*
  205. * Define a Get/Put value pair (pointers) used with a message queue.
  206. */
  207. struct xpc_gp {
  208. volatile s64 get; /* Get value */
  209. volatile s64 put; /* Put value */
  210. };
  211. #define XPC_GP_SIZE \
  212. L1_CACHE_ALIGN(sizeof(struct xpc_gp) * XPC_NCHANNELS)
  213. /*
  214. * Define a structure that contains arguments associated with opening and
  215. * closing a channel.
  216. */
  217. struct xpc_openclose_args {
  218. u16 reason; /* reason why channel is closing */
  219. u16 msg_size; /* sizeof each message entry */
  220. u16 remote_nentries; /* #of message entries in remote msg queue */
  221. u16 local_nentries; /* #of message entries in local msg queue */
  222. u64 local_msgqueue_pa; /* physical address of local message queue */
  223. };
  224. #define XPC_OPENCLOSE_ARGS_SIZE \
  225. L1_CACHE_ALIGN(sizeof(struct xpc_openclose_args) * XPC_NCHANNELS)
  226. /* struct xpc_msg flags */
  227. #define XPC_M_DONE 0x01 /* msg has been received/consumed */
  228. #define XPC_M_READY 0x02 /* msg is ready to be sent */
  229. #define XPC_M_INTERRUPT 0x04 /* send interrupt when msg consumed */
  230. #define XPC_MSG_ADDRESS(_payload) \
  231. ((struct xpc_msg *)((u8 *)(_payload) - XPC_MSG_PAYLOAD_OFFSET))
  232. /*
  233. * Defines notify entry.
  234. *
  235. * This is used to notify a message's sender that their message was received
  236. * and consumed by the intended recipient.
  237. */
  238. struct xpc_notify {
  239. struct semaphore sema; /* notify semaphore */
  240. volatile u8 type; /* type of notification */
  241. /* the following two fields are only used if type == XPC_N_CALL */
  242. xpc_notify_func func; /* user's notify function */
  243. void *key; /* pointer to user's key */
  244. };
  245. /* struct xpc_notify type of notification */
  246. #define XPC_N_CALL 0x01 /* notify function provided by user */
  247. /*
  248. * Define the structure that manages all the stuff required by a channel. In
  249. * particular, they are used to manage the messages sent across the channel.
  250. *
  251. * This structure is private to a partition, and is NOT shared across the
  252. * partition boundary.
  253. *
  254. * There is an array of these structures for each remote partition. It is
  255. * allocated at the time a partition becomes active. The array contains one
  256. * of these structures for each potential channel connection to that partition.
  257. *
  258. * Each of these structures manages two message queues (circular buffers).
  259. * They are allocated at the time a channel connection is made. One of
  260. * these message queues (local_msgqueue) holds the locally created messages
  261. * that are destined for the remote partition. The other of these message
  262. * queues (remote_msgqueue) is a locally cached copy of the remote partition's
  263. * own local_msgqueue.
  264. *
  265. * The following is a description of the Get/Put pointers used to manage these
  266. * two message queues. Consider the local_msgqueue to be on one partition
  267. * and the remote_msgqueue to be its cached copy on another partition. A
  268. * description of what each of the lettered areas contains is included.
  269. *
  270. *
  271. * local_msgqueue remote_msgqueue
  272. *
  273. * |/////////| |/////////|
  274. * w_remote_GP.get --> +---------+ |/////////|
  275. * | F | |/////////|
  276. * remote_GP.get --> +---------+ +---------+ <-- local_GP->get
  277. * | | | |
  278. * | | | E |
  279. * | | | |
  280. * | | +---------+ <-- w_local_GP.get
  281. * | B | |/////////|
  282. * | | |////D////|
  283. * | | |/////////|
  284. * | | +---------+ <-- w_remote_GP.put
  285. * | | |////C////|
  286. * local_GP->put --> +---------+ +---------+ <-- remote_GP.put
  287. * | | |/////////|
  288. * | A | |/////////|
  289. * | | |/////////|
  290. * w_local_GP.put --> +---------+ |/////////|
  291. * |/////////| |/////////|
  292. *
  293. *
  294. * ( remote_GP.[get|put] are cached copies of the remote
  295. * partition's local_GP->[get|put], and thus their values can
  296. * lag behind their counterparts on the remote partition. )
  297. *
  298. *
  299. * A - Messages that have been allocated, but have not yet been sent to the
  300. * remote partition.
  301. *
  302. * B - Messages that have been sent, but have not yet been acknowledged by the
  303. * remote partition as having been received.
  304. *
  305. * C - Area that needs to be prepared for the copying of sent messages, by
  306. * the clearing of the message flags of any previously received messages.
  307. *
  308. * D - Area into which sent messages are to be copied from the remote
  309. * partition's local_msgqueue and then delivered to their intended
  310. * recipients. [ To allow for a multi-message copy, another pointer
  311. * (next_msg_to_pull) has been added to keep track of the next message
  312. * number needing to be copied (pulled). It chases after w_remote_GP.put.
  313. * Any messages lying between w_local_GP.get and next_msg_to_pull have
  314. * been copied and are ready to be delivered. ]
  315. *
  316. * E - Messages that have been copied and delivered, but have not yet been
  317. * acknowledged by the recipient as having been received.
  318. *
  319. * F - Messages that have been acknowledged, but XPC has not yet notified the
  320. * sender that the message was received by its intended recipient.
  321. * This is also an area that needs to be prepared for the allocating of
  322. * new messages, by the clearing of the message flags of the acknowledged
  323. * messages.
  324. */
  325. struct xpc_channel {
  326. partid_t partid; /* ID of remote partition connected */
  327. spinlock_t lock; /* lock for updating this structure */
  328. u32 flags; /* general flags */
  329. enum xpc_retval reason; /* reason why channel is disconnect'g */
  330. int reason_line; /* line# disconnect initiated from */
  331. u16 number; /* channel # */
  332. u16 msg_size; /* sizeof each msg entry */
  333. u16 local_nentries; /* #of msg entries in local msg queue */
  334. u16 remote_nentries; /* #of msg entries in remote msg queue*/
  335. void *local_msgqueue_base; /* base address of kmalloc'd space */
  336. struct xpc_msg *local_msgqueue; /* local message queue */
  337. void *remote_msgqueue_base; /* base address of kmalloc'd space */
  338. struct xpc_msg *remote_msgqueue;/* cached copy of remote partition's */
  339. /* local message queue */
  340. u64 remote_msgqueue_pa; /* phys addr of remote partition's */
  341. /* local message queue */
  342. atomic_t references; /* #of external references to queues */
  343. atomic_t n_on_msg_allocate_wq; /* #on msg allocation wait queue */
  344. wait_queue_head_t msg_allocate_wq; /* msg allocation wait queue */
  345. u8 delayed_IPI_flags; /* IPI flags received, but delayed */
  346. /* action until channel disconnected */
  347. /* queue of msg senders who want to be notified when msg received */
  348. atomic_t n_to_notify; /* #of msg senders to notify */
  349. struct xpc_notify *notify_queue;/* notify queue for messages sent */
  350. xpc_channel_func func; /* user's channel function */
  351. void *key; /* pointer to user's key */
  352. struct semaphore msg_to_pull_sema; /* next msg to pull serialization */
  353. struct semaphore wdisconnect_sema; /* wait for channel disconnect */
  354. struct xpc_openclose_args *local_openclose_args; /* args passed on */
  355. /* opening or closing of channel */
  356. /* various flavors of local and remote Get/Put values */
  357. struct xpc_gp *local_GP; /* local Get/Put values */
  358. struct xpc_gp remote_GP; /* remote Get/Put values */
  359. struct xpc_gp w_local_GP; /* working local Get/Put values */
  360. struct xpc_gp w_remote_GP; /* working remote Get/Put values */
  361. s64 next_msg_to_pull; /* Put value of next msg to pull */
  362. /* kthread management related fields */
  363. // >>> rethink having kthreads_assigned_limit and kthreads_idle_limit; perhaps
  364. // >>> allow the assigned limit be unbounded and let the idle limit be dynamic
  365. // >>> dependent on activity over the last interval of time
  366. atomic_t kthreads_assigned; /* #of kthreads assigned to channel */
  367. u32 kthreads_assigned_limit; /* limit on #of kthreads assigned */
  368. atomic_t kthreads_idle; /* #of kthreads idle waiting for work */
  369. u32 kthreads_idle_limit; /* limit on #of kthreads idle */
  370. atomic_t kthreads_active; /* #of kthreads actively working */
  371. // >>> following field is temporary
  372. u32 kthreads_created; /* total #of kthreads created */
  373. wait_queue_head_t idle_wq; /* idle kthread wait queue */
  374. } ____cacheline_aligned;
  375. /* struct xpc_channel flags */
  376. #define XPC_C_WASCONNECTED 0x00000001 /* channel was connected */
  377. #define XPC_C_ROPENREPLY 0x00000002 /* remote open channel reply */
  378. #define XPC_C_OPENREPLY 0x00000004 /* local open channel reply */
  379. #define XPC_C_ROPENREQUEST 0x00000008 /* remote open channel request */
  380. #define XPC_C_OPENREQUEST 0x00000010 /* local open channel request */
  381. #define XPC_C_SETUP 0x00000020 /* channel's msgqueues are alloc'd */
  382. #define XPC_C_CONNECTCALLOUT 0x00000040 /* channel connected callout made */
  383. #define XPC_C_CONNECTED 0x00000080 /* local channel is connected */
  384. #define XPC_C_CONNECTING 0x00000100 /* channel is being connected */
  385. #define XPC_C_RCLOSEREPLY 0x00000200 /* remote close channel reply */
  386. #define XPC_C_CLOSEREPLY 0x00000400 /* local close channel reply */
  387. #define XPC_C_RCLOSEREQUEST 0x00000800 /* remote close channel request */
  388. #define XPC_C_CLOSEREQUEST 0x00001000 /* local close channel request */
  389. #define XPC_C_DISCONNECTED 0x00002000 /* channel is disconnected */
  390. #define XPC_C_DISCONNECTING 0x00004000 /* channel is being disconnected */
  391. #define XPC_C_DISCONNECTCALLOUT 0x00008000 /* chan disconnected callout made */
  392. #define XPC_C_WDISCONNECT 0x00010000 /* waiting for channel disconnect */
  393. /*
  394. * Manages channels on a partition basis. There is one of these structures
  395. * for each partition (a partition will never utilize the structure that
  396. * represents itself).
  397. */
  398. struct xpc_partition {
  399. /* XPC HB infrastructure */
  400. u8 remote_rp_version; /* version# of partition's rsvd pg */
  401. struct timespec remote_rp_stamp;/* time when rsvd pg was initialized */
  402. u64 remote_rp_pa; /* phys addr of partition's rsvd pg */
  403. u64 remote_vars_pa; /* phys addr of partition's vars */
  404. u64 remote_vars_part_pa; /* phys addr of partition's vars part */
  405. u64 last_heartbeat; /* HB at last read */
  406. u64 remote_amos_page_pa; /* phys addr of partition's amos page */
  407. int remote_act_nasid; /* active part's act/deact nasid */
  408. int remote_act_phys_cpuid; /* active part's act/deact phys cpuid */
  409. u32 act_IRQ_rcvd; /* IRQs since activation */
  410. spinlock_t act_lock; /* protect updating of act_state */
  411. u8 act_state; /* from XPC HB viewpoint */
  412. u8 remote_vars_version; /* version# of partition's vars */
  413. enum xpc_retval reason; /* reason partition is deactivating */
  414. int reason_line; /* line# deactivation initiated from */
  415. int reactivate_nasid; /* nasid in partition to reactivate */
  416. unsigned long disengage_request_timeout; /* timeout in jiffies */
  417. struct timer_list disengage_request_timer;
  418. /* XPC infrastructure referencing and teardown control */
  419. volatile u8 setup_state; /* infrastructure setup state */
  420. wait_queue_head_t teardown_wq; /* kthread waiting to teardown infra */
  421. atomic_t references; /* #of references to infrastructure */
  422. /*
  423. * NONE OF THE PRECEDING FIELDS OF THIS STRUCTURE WILL BE CLEARED WHEN
  424. * XPC SETS UP THE NECESSARY INFRASTRUCTURE TO SUPPORT CROSS PARTITION
  425. * COMMUNICATION. ALL OF THE FOLLOWING FIELDS WILL BE CLEARED. (THE
  426. * 'nchannels' FIELD MUST BE THE FIRST OF THE FIELDS TO BE CLEARED.)
  427. */
  428. u8 nchannels; /* #of defined channels supported */
  429. atomic_t nchannels_active; /* #of channels that are not DISCONNECTED */
  430. atomic_t nchannels_engaged;/* #of channels engaged with remote part */
  431. struct xpc_channel *channels;/* array of channel structures */
  432. void *local_GPs_base; /* base address of kmalloc'd space */
  433. struct xpc_gp *local_GPs; /* local Get/Put values */
  434. void *remote_GPs_base; /* base address of kmalloc'd space */
  435. struct xpc_gp *remote_GPs;/* copy of remote partition's local Get/Put */
  436. /* values */
  437. u64 remote_GPs_pa; /* phys address of remote partition's local */
  438. /* Get/Put values */
  439. /* fields used to pass args when opening or closing a channel */
  440. void *local_openclose_args_base; /* base address of kmalloc'd space */
  441. struct xpc_openclose_args *local_openclose_args; /* local's args */
  442. void *remote_openclose_args_base; /* base address of kmalloc'd space */
  443. struct xpc_openclose_args *remote_openclose_args; /* copy of remote's */
  444. /* args */
  445. u64 remote_openclose_args_pa; /* phys addr of remote's args */
  446. /* IPI sending, receiving and handling related fields */
  447. int remote_IPI_nasid; /* nasid of where to send IPIs */
  448. int remote_IPI_phys_cpuid; /* phys CPU ID of where to send IPIs */
  449. AMO_t *remote_IPI_amo_va; /* address of remote IPI AMO_t structure */
  450. AMO_t *local_IPI_amo_va; /* address of IPI AMO_t structure */
  451. u64 local_IPI_amo; /* IPI amo flags yet to be handled */
  452. char IPI_owner[8]; /* IPI owner's name */
  453. struct timer_list dropped_IPI_timer; /* dropped IPI timer */
  454. spinlock_t IPI_lock; /* IPI handler lock */
  455. /* channel manager related fields */
  456. atomic_t channel_mgr_requests; /* #of requests to activate chan mgr */
  457. wait_queue_head_t channel_mgr_wq; /* channel mgr's wait queue */
  458. } ____cacheline_aligned;
  459. /* struct xpc_partition act_state values (for XPC HB) */
  460. #define XPC_P_INACTIVE 0x00 /* partition is not active */
  461. #define XPC_P_ACTIVATION_REQ 0x01 /* created thread to activate */
  462. #define XPC_P_ACTIVATING 0x02 /* activation thread started */
  463. #define XPC_P_ACTIVE 0x03 /* xpc_partition_up() was called */
  464. #define XPC_P_DEACTIVATING 0x04 /* partition deactivation initiated */
  465. #define XPC_DEACTIVATE_PARTITION(_p, _reason) \
  466. xpc_deactivate_partition(__LINE__, (_p), (_reason))
  467. /* struct xpc_partition setup_state values */
  468. #define XPC_P_UNSET 0x00 /* infrastructure was never setup */
  469. #define XPC_P_SETUP 0x01 /* infrastructure is setup */
  470. #define XPC_P_WTEARDOWN 0x02 /* waiting to teardown infrastructure */
  471. #define XPC_P_TORNDOWN 0x03 /* infrastructure is torndown */
  472. /*
  473. * struct xpc_partition IPI_timer #of seconds to wait before checking for
  474. * dropped IPIs. These occur whenever an IPI amo write doesn't complete until
  475. * after the IPI was received.
  476. */
  477. #define XPC_P_DROPPED_IPI_WAIT (0.25 * HZ)
  478. /* number of seconds to wait for other partitions to disengage */
  479. #define XPC_DISENGAGE_REQUEST_DEFAULT_TIMELIMIT 90
  480. /* interval in seconds to print 'waiting disengagement' messages */
  481. #define XPC_DISENGAGE_PRINTMSG_INTERVAL 10
  482. #define XPC_PARTID(_p) ((partid_t) ((_p) - &xpc_partitions[0]))
  483. /* found in xp_main.c */
  484. extern struct xpc_registration xpc_registrations[];
  485. /* found in xpc_main.c */
  486. extern struct device *xpc_part;
  487. extern struct device *xpc_chan;
  488. extern int xpc_disengage_request_timelimit;
  489. extern irqreturn_t xpc_notify_IRQ_handler(int, void *, struct pt_regs *);
  490. extern void xpc_dropped_IPI_check(struct xpc_partition *);
  491. extern void xpc_activate_partition(struct xpc_partition *);
  492. extern void xpc_activate_kthreads(struct xpc_channel *, int);
  493. extern void xpc_create_kthreads(struct xpc_channel *, int);
  494. extern void xpc_disconnect_wait(int);
  495. /* found in xpc_partition.c */
  496. extern int xpc_exiting;
  497. extern struct xpc_vars *xpc_vars;
  498. extern struct xpc_rsvd_page *xpc_rsvd_page;
  499. extern struct xpc_vars_part *xpc_vars_part;
  500. extern struct xpc_partition xpc_partitions[XP_MAX_PARTITIONS + 1];
  501. extern char xpc_remote_copy_buffer[];
  502. extern struct xpc_rsvd_page *xpc_rsvd_page_init(void);
  503. extern void xpc_allow_IPI_ops(void);
  504. extern void xpc_restrict_IPI_ops(void);
  505. extern int xpc_identify_act_IRQ_sender(void);
  506. extern int xpc_partition_disengaged(struct xpc_partition *);
  507. extern enum xpc_retval xpc_mark_partition_active(struct xpc_partition *);
  508. extern void xpc_mark_partition_inactive(struct xpc_partition *);
  509. extern void xpc_discovery(void);
  510. extern void xpc_check_remote_hb(void);
  511. extern void xpc_deactivate_partition(const int, struct xpc_partition *,
  512. enum xpc_retval);
  513. extern enum xpc_retval xpc_initiate_partid_to_nasids(partid_t, void *);
  514. /* found in xpc_channel.c */
  515. extern void xpc_initiate_connect(int);
  516. extern void xpc_initiate_disconnect(int);
  517. extern enum xpc_retval xpc_initiate_allocate(partid_t, int, u32, void **);
  518. extern enum xpc_retval xpc_initiate_send(partid_t, int, void *);
  519. extern enum xpc_retval xpc_initiate_send_notify(partid_t, int, void *,
  520. xpc_notify_func, void *);
  521. extern void xpc_initiate_received(partid_t, int, void *);
  522. extern enum xpc_retval xpc_setup_infrastructure(struct xpc_partition *);
  523. extern enum xpc_retval xpc_pull_remote_vars_part(struct xpc_partition *);
  524. extern void xpc_process_channel_activity(struct xpc_partition *);
  525. extern void xpc_connected_callout(struct xpc_channel *);
  526. extern void xpc_deliver_msg(struct xpc_channel *);
  527. extern void xpc_disconnect_channel(const int, struct xpc_channel *,
  528. enum xpc_retval, unsigned long *);
  529. extern void xpc_disconnecting_callout(struct xpc_channel *);
  530. extern void xpc_partition_going_down(struct xpc_partition *, enum xpc_retval);
  531. extern void xpc_teardown_infrastructure(struct xpc_partition *);
  532. static inline void
  533. xpc_wakeup_channel_mgr(struct xpc_partition *part)
  534. {
  535. if (atomic_inc_return(&part->channel_mgr_requests) == 1) {
  536. wake_up(&part->channel_mgr_wq);
  537. }
  538. }
  539. /*
  540. * These next two inlines are used to keep us from tearing down a channel's
  541. * msg queues while a thread may be referencing them.
  542. */
  543. static inline void
  544. xpc_msgqueue_ref(struct xpc_channel *ch)
  545. {
  546. atomic_inc(&ch->references);
  547. }
  548. static inline void
  549. xpc_msgqueue_deref(struct xpc_channel *ch)
  550. {
  551. s32 refs = atomic_dec_return(&ch->references);
  552. DBUG_ON(refs < 0);
  553. if (refs == 0) {
  554. xpc_wakeup_channel_mgr(&xpc_partitions[ch->partid]);
  555. }
  556. }
  557. #define XPC_DISCONNECT_CHANNEL(_ch, _reason, _irqflgs) \
  558. xpc_disconnect_channel(__LINE__, _ch, _reason, _irqflgs)
  559. /*
  560. * These two inlines are used to keep us from tearing down a partition's
  561. * setup infrastructure while a thread may be referencing it.
  562. */
  563. static inline void
  564. xpc_part_deref(struct xpc_partition *part)
  565. {
  566. s32 refs = atomic_dec_return(&part->references);
  567. DBUG_ON(refs < 0);
  568. if (refs == 0 && part->setup_state == XPC_P_WTEARDOWN) {
  569. wake_up(&part->teardown_wq);
  570. }
  571. }
  572. static inline int
  573. xpc_part_ref(struct xpc_partition *part)
  574. {
  575. int setup;
  576. atomic_inc(&part->references);
  577. setup = (part->setup_state == XPC_P_SETUP);
  578. if (!setup) {
  579. xpc_part_deref(part);
  580. }
  581. return setup;
  582. }
  583. /*
  584. * The following macro is to be used for the setting of the reason and
  585. * reason_line fields in both the struct xpc_channel and struct xpc_partition
  586. * structures.
  587. */
  588. #define XPC_SET_REASON(_p, _reason, _line) \
  589. { \
  590. (_p)->reason = _reason; \
  591. (_p)->reason_line = _line; \
  592. }
  593. /*
  594. * This next set of inlines are used to keep track of when a partition is
  595. * potentially engaged in accessing memory belonging to another partition.
  596. */
  597. static inline void
  598. xpc_mark_partition_engaged(struct xpc_partition *part)
  599. {
  600. unsigned long irq_flags;
  601. AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
  602. (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
  603. local_irq_save(irq_flags);
  604. /* set bit corresponding to our partid in remote partition's AMO */
  605. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
  606. (1UL << sn_partition_id));
  607. /*
  608. * We must always use the nofault function regardless of whether we
  609. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  610. * didn't, we'd never know that the other partition is down and would
  611. * keep sending IPIs and AMOs to it until the heartbeat times out.
  612. */
  613. (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
  614. variable), xp_nofault_PIOR_target));
  615. local_irq_restore(irq_flags);
  616. }
  617. static inline void
  618. xpc_mark_partition_disengaged(struct xpc_partition *part)
  619. {
  620. unsigned long irq_flags;
  621. AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
  622. (XPC_ENGAGED_PARTITIONS_AMO * sizeof(AMO_t)));
  623. local_irq_save(irq_flags);
  624. /* clear bit corresponding to our partid in remote partition's AMO */
  625. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
  626. ~(1UL << sn_partition_id));
  627. /*
  628. * We must always use the nofault function regardless of whether we
  629. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  630. * didn't, we'd never know that the other partition is down and would
  631. * keep sending IPIs and AMOs to it until the heartbeat times out.
  632. */
  633. (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
  634. variable), xp_nofault_PIOR_target));
  635. local_irq_restore(irq_flags);
  636. }
  637. static inline void
  638. xpc_request_partition_disengage(struct xpc_partition *part)
  639. {
  640. unsigned long irq_flags;
  641. AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
  642. (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
  643. local_irq_save(irq_flags);
  644. /* set bit corresponding to our partid in remote partition's AMO */
  645. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR,
  646. (1UL << sn_partition_id));
  647. /*
  648. * We must always use the nofault function regardless of whether we
  649. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  650. * didn't, we'd never know that the other partition is down and would
  651. * keep sending IPIs and AMOs to it until the heartbeat times out.
  652. */
  653. (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
  654. variable), xp_nofault_PIOR_target));
  655. local_irq_restore(irq_flags);
  656. }
  657. static inline void
  658. xpc_cancel_partition_disengage_request(struct xpc_partition *part)
  659. {
  660. unsigned long irq_flags;
  661. AMO_t *amo = (AMO_t *) __va(part->remote_amos_page_pa +
  662. (XPC_DISENGAGE_REQUEST_AMO * sizeof(AMO_t)));
  663. local_irq_save(irq_flags);
  664. /* clear bit corresponding to our partid in remote partition's AMO */
  665. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
  666. ~(1UL << sn_partition_id));
  667. /*
  668. * We must always use the nofault function regardless of whether we
  669. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  670. * didn't, we'd never know that the other partition is down and would
  671. * keep sending IPIs and AMOs to it until the heartbeat times out.
  672. */
  673. (void) xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->
  674. variable), xp_nofault_PIOR_target));
  675. local_irq_restore(irq_flags);
  676. }
  677. static inline u64
  678. xpc_partition_engaged(u64 partid_mask)
  679. {
  680. AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
  681. /* return our partition's AMO variable ANDed with partid_mask */
  682. return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
  683. partid_mask);
  684. }
  685. static inline u64
  686. xpc_partition_disengage_requested(u64 partid_mask)
  687. {
  688. AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
  689. /* return our partition's AMO variable ANDed with partid_mask */
  690. return (FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_LOAD) &
  691. partid_mask);
  692. }
  693. static inline void
  694. xpc_clear_partition_engaged(u64 partid_mask)
  695. {
  696. AMO_t *amo = xpc_vars->amos_page + XPC_ENGAGED_PARTITIONS_AMO;
  697. /* clear bit(s) based on partid_mask in our partition's AMO */
  698. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
  699. ~partid_mask);
  700. }
  701. static inline void
  702. xpc_clear_partition_disengage_request(u64 partid_mask)
  703. {
  704. AMO_t *amo = xpc_vars->amos_page + XPC_DISENGAGE_REQUEST_AMO;
  705. /* clear bit(s) based on partid_mask in our partition's AMO */
  706. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_AND,
  707. ~partid_mask);
  708. }
  709. /*
  710. * The following set of macros and inlines are used for the sending and
  711. * receiving of IPIs (also known as IRQs). There are two flavors of IPIs,
  712. * one that is associated with partition activity (SGI_XPC_ACTIVATE) and
  713. * the other that is associated with channel activity (SGI_XPC_NOTIFY).
  714. */
  715. static inline u64
  716. xpc_IPI_receive(AMO_t *amo)
  717. {
  718. return FETCHOP_LOAD_OP(TO_AMO((u64) &amo->variable), FETCHOP_CLEAR);
  719. }
  720. static inline enum xpc_retval
  721. xpc_IPI_send(AMO_t *amo, u64 flag, int nasid, int phys_cpuid, int vector)
  722. {
  723. int ret = 0;
  724. unsigned long irq_flags;
  725. local_irq_save(irq_flags);
  726. FETCHOP_STORE_OP(TO_AMO((u64) &amo->variable), FETCHOP_OR, flag);
  727. sn_send_IPI_phys(nasid, phys_cpuid, vector, 0);
  728. /*
  729. * We must always use the nofault function regardless of whether we
  730. * are on a Shub 1.1 system or a Shub 1.2 slice 0xc processor. If we
  731. * didn't, we'd never know that the other partition is down and would
  732. * keep sending IPIs and AMOs to it until the heartbeat times out.
  733. */
  734. ret = xp_nofault_PIOR((u64 *) GLOBAL_MMR_ADDR(NASID_GET(&amo->variable),
  735. xp_nofault_PIOR_target));
  736. local_irq_restore(irq_flags);
  737. return ((ret == 0) ? xpcSuccess : xpcPioReadError);
  738. }
  739. /*
  740. * IPIs associated with SGI_XPC_ACTIVATE IRQ.
  741. */
  742. /*
  743. * Flag the appropriate AMO variable and send an IPI to the specified node.
  744. */
  745. static inline void
  746. xpc_activate_IRQ_send(u64 amos_page_pa, int from_nasid, int to_nasid,
  747. int to_phys_cpuid)
  748. {
  749. int w_index = XPC_NASID_W_INDEX(from_nasid);
  750. int b_index = XPC_NASID_B_INDEX(from_nasid);
  751. AMO_t *amos = (AMO_t *) __va(amos_page_pa +
  752. (XPC_ACTIVATE_IRQ_AMOS * sizeof(AMO_t)));
  753. (void) xpc_IPI_send(&amos[w_index], (1UL << b_index), to_nasid,
  754. to_phys_cpuid, SGI_XPC_ACTIVATE);
  755. }
  756. static inline void
  757. xpc_IPI_send_activate(struct xpc_vars *vars)
  758. {
  759. xpc_activate_IRQ_send(vars->amos_page_pa, cnodeid_to_nasid(0),
  760. vars->act_nasid, vars->act_phys_cpuid);
  761. }
  762. static inline void
  763. xpc_IPI_send_activated(struct xpc_partition *part)
  764. {
  765. xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
  766. part->remote_act_nasid, part->remote_act_phys_cpuid);
  767. }
  768. static inline void
  769. xpc_IPI_send_reactivate(struct xpc_partition *part)
  770. {
  771. xpc_activate_IRQ_send(xpc_vars->amos_page_pa, part->reactivate_nasid,
  772. xpc_vars->act_nasid, xpc_vars->act_phys_cpuid);
  773. }
  774. static inline void
  775. xpc_IPI_send_disengage(struct xpc_partition *part)
  776. {
  777. xpc_activate_IRQ_send(part->remote_amos_page_pa, cnodeid_to_nasid(0),
  778. part->remote_act_nasid, part->remote_act_phys_cpuid);
  779. }
  780. /*
  781. * IPIs associated with SGI_XPC_NOTIFY IRQ.
  782. */
  783. /*
  784. * Send an IPI to the remote partition that is associated with the
  785. * specified channel.
  786. */
  787. #define XPC_NOTIFY_IRQ_SEND(_ch, _ipi_f, _irq_f) \
  788. xpc_notify_IRQ_send(_ch, _ipi_f, #_ipi_f, _irq_f)
  789. static inline void
  790. xpc_notify_IRQ_send(struct xpc_channel *ch, u8 ipi_flag, char *ipi_flag_string,
  791. unsigned long *irq_flags)
  792. {
  793. struct xpc_partition *part = &xpc_partitions[ch->partid];
  794. enum xpc_retval ret;
  795. if (likely(part->act_state != XPC_P_DEACTIVATING)) {
  796. ret = xpc_IPI_send(part->remote_IPI_amo_va,
  797. (u64) ipi_flag << (ch->number * 8),
  798. part->remote_IPI_nasid,
  799. part->remote_IPI_phys_cpuid,
  800. SGI_XPC_NOTIFY);
  801. dev_dbg(xpc_chan, "%s sent to partid=%d, channel=%d, ret=%d\n",
  802. ipi_flag_string, ch->partid, ch->number, ret);
  803. if (unlikely(ret != xpcSuccess)) {
  804. if (irq_flags != NULL) {
  805. spin_unlock_irqrestore(&ch->lock, *irq_flags);
  806. }
  807. XPC_DEACTIVATE_PARTITION(part, ret);
  808. if (irq_flags != NULL) {
  809. spin_lock_irqsave(&ch->lock, *irq_flags);
  810. }
  811. }
  812. }
  813. }
  814. /*
  815. * Make it look like the remote partition, which is associated with the
  816. * specified channel, sent us an IPI. This faked IPI will be handled
  817. * by xpc_dropped_IPI_check().
  818. */
  819. #define XPC_NOTIFY_IRQ_SEND_LOCAL(_ch, _ipi_f) \
  820. xpc_notify_IRQ_send_local(_ch, _ipi_f, #_ipi_f)
  821. static inline void
  822. xpc_notify_IRQ_send_local(struct xpc_channel *ch, u8 ipi_flag,
  823. char *ipi_flag_string)
  824. {
  825. struct xpc_partition *part = &xpc_partitions[ch->partid];
  826. FETCHOP_STORE_OP(TO_AMO((u64) &part->local_IPI_amo_va->variable),
  827. FETCHOP_OR, ((u64) ipi_flag << (ch->number * 8)));
  828. dev_dbg(xpc_chan, "%s sent local from partid=%d, channel=%d\n",
  829. ipi_flag_string, ch->partid, ch->number);
  830. }
  831. /*
  832. * The sending and receiving of IPIs includes the setting of an AMO variable
  833. * to indicate the reason the IPI was sent. The 64-bit variable is divided
  834. * up into eight bytes, ordered from right to left. Byte zero pertains to
  835. * channel 0, byte one to channel 1, and so on. Each byte is described by
  836. * the following IPI flags.
  837. */
  838. #define XPC_IPI_CLOSEREQUEST 0x01
  839. #define XPC_IPI_CLOSEREPLY 0x02
  840. #define XPC_IPI_OPENREQUEST 0x04
  841. #define XPC_IPI_OPENREPLY 0x08
  842. #define XPC_IPI_MSGREQUEST 0x10
  843. /* given an AMO variable and a channel#, get its associated IPI flags */
  844. #define XPC_GET_IPI_FLAGS(_amo, _c) ((u8) (((_amo) >> ((_c) * 8)) & 0xff))
  845. #define XPC_SET_IPI_FLAGS(_amo, _c, _f) (_amo) |= ((u64) (_f) << ((_c) * 8))
  846. #define XPC_ANY_OPENCLOSE_IPI_FLAGS_SET(_amo) ((_amo) & 0x0f0f0f0f0f0f0f0f)
  847. #define XPC_ANY_MSG_IPI_FLAGS_SET(_amo) ((_amo) & 0x1010101010101010)
  848. static inline void
  849. xpc_IPI_send_closerequest(struct xpc_channel *ch, unsigned long *irq_flags)
  850. {
  851. struct xpc_openclose_args *args = ch->local_openclose_args;
  852. args->reason = ch->reason;
  853. XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREQUEST, irq_flags);
  854. }
  855. static inline void
  856. xpc_IPI_send_closereply(struct xpc_channel *ch, unsigned long *irq_flags)
  857. {
  858. XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_CLOSEREPLY, irq_flags);
  859. }
  860. static inline void
  861. xpc_IPI_send_openrequest(struct xpc_channel *ch, unsigned long *irq_flags)
  862. {
  863. struct xpc_openclose_args *args = ch->local_openclose_args;
  864. args->msg_size = ch->msg_size;
  865. args->local_nentries = ch->local_nentries;
  866. XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREQUEST, irq_flags);
  867. }
  868. static inline void
  869. xpc_IPI_send_openreply(struct xpc_channel *ch, unsigned long *irq_flags)
  870. {
  871. struct xpc_openclose_args *args = ch->local_openclose_args;
  872. args->remote_nentries = ch->remote_nentries;
  873. args->local_nentries = ch->local_nentries;
  874. args->local_msgqueue_pa = __pa(ch->local_msgqueue);
  875. XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_OPENREPLY, irq_flags);
  876. }
  877. static inline void
  878. xpc_IPI_send_msgrequest(struct xpc_channel *ch)
  879. {
  880. XPC_NOTIFY_IRQ_SEND(ch, XPC_IPI_MSGREQUEST, NULL);
  881. }
  882. static inline void
  883. xpc_IPI_send_local_msgrequest(struct xpc_channel *ch)
  884. {
  885. XPC_NOTIFY_IRQ_SEND_LOCAL(ch, XPC_IPI_MSGREQUEST);
  886. }
  887. /*
  888. * Memory for XPC's AMO variables is allocated by the MSPEC driver. These
  889. * pages are located in the lowest granule. The lowest granule uses 4k pages
  890. * for cached references and an alternate TLB handler to never provide a
  891. * cacheable mapping for the entire region. This will prevent speculative
  892. * reading of cached copies of our lines from being issued which will cause
  893. * a PI FSB Protocol error to be generated by the SHUB. For XPC, we need 64
  894. * (XP_MAX_PARTITIONS) AMO variables for message notification and an
  895. * additional 16 (XP_NASID_MASK_WORDS) AMO variables for partition activation
  896. * and 2 AMO variables for partition deactivation.
  897. */
  898. static inline AMO_t *
  899. xpc_IPI_init(int index)
  900. {
  901. AMO_t *amo = xpc_vars->amos_page + index;
  902. (void) xpc_IPI_receive(amo); /* clear AMO variable */
  903. return amo;
  904. }
  905. static inline enum xpc_retval
  906. xpc_map_bte_errors(bte_result_t error)
  907. {
  908. switch (error) {
  909. case BTE_SUCCESS: return xpcSuccess;
  910. case BTEFAIL_DIR: return xpcBteDirectoryError;
  911. case BTEFAIL_POISON: return xpcBtePoisonError;
  912. case BTEFAIL_WERR: return xpcBteWriteError;
  913. case BTEFAIL_ACCESS: return xpcBteAccessError;
  914. case BTEFAIL_PWERR: return xpcBtePWriteError;
  915. case BTEFAIL_PRERR: return xpcBtePReadError;
  916. case BTEFAIL_TOUT: return xpcBteTimeOutError;
  917. case BTEFAIL_XTERR: return xpcBteXtalkError;
  918. case BTEFAIL_NOTAVAIL: return xpcBteNotAvailable;
  919. default: return xpcBteUnmappedError;
  920. }
  921. }
  922. static inline void *
  923. xpc_kmalloc_cacheline_aligned(size_t size, int flags, void **base)
  924. {
  925. /* see if kmalloc will give us cachline aligned memory by default */
  926. *base = kmalloc(size, flags);
  927. if (*base == NULL) {
  928. return NULL;
  929. }
  930. if ((u64) *base == L1_CACHE_ALIGN((u64) *base)) {
  931. return *base;
  932. }
  933. kfree(*base);
  934. /* nope, we'll have to do it ourselves */
  935. *base = kmalloc(size + L1_CACHE_BYTES, flags);
  936. if (*base == NULL) {
  937. return NULL;
  938. }
  939. return (void *) L1_CACHE_ALIGN((u64) *base);
  940. }
  941. /*
  942. * Check to see if there is any channel activity to/from the specified
  943. * partition.
  944. */
  945. static inline void
  946. xpc_check_for_channel_activity(struct xpc_partition *part)
  947. {
  948. u64 IPI_amo;
  949. unsigned long irq_flags;
  950. IPI_amo = xpc_IPI_receive(part->local_IPI_amo_va);
  951. if (IPI_amo == 0) {
  952. return;
  953. }
  954. spin_lock_irqsave(&part->IPI_lock, irq_flags);
  955. part->local_IPI_amo |= IPI_amo;
  956. spin_unlock_irqrestore(&part->IPI_lock, irq_flags);
  957. dev_dbg(xpc_chan, "received IPI from partid=%d, IPI_amo=0x%lx\n",
  958. XPC_PARTID(part), IPI_amo);
  959. xpc_wakeup_channel_mgr(part);
  960. }
  961. #endif /* _IA64_SN_KERNEL_XPC_H */