xp.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. * External Cross Partition (XP) structures and defines.
  10. */
  11. #ifndef _ASM_IA64_SN_XP_H
  12. #define _ASM_IA64_SN_XP_H
  13. #include <linux/version.h>
  14. #include <linux/cache.h>
  15. #include <linux/hardirq.h>
  16. #include <asm/sn/types.h>
  17. #include <asm/sn/bte.h>
  18. #ifdef USE_DBUG_ON
  19. #define DBUG_ON(condition) BUG_ON(condition)
  20. #else
  21. #define DBUG_ON(condition)
  22. #endif
  23. /*
  24. * Define the maximum number of logically defined partitions the system
  25. * can support. It is constrained by the maximum number of hardware
  26. * partitionable regions. The term 'region' in this context refers to the
  27. * minimum number of nodes that can comprise an access protection grouping.
  28. * The access protection is in regards to memory, IPI and IOI.
  29. *
  30. * The maximum number of hardware partitionable regions is equal to the
  31. * maximum number of nodes in the entire system divided by the minimum number
  32. * of nodes that comprise an access protection grouping.
  33. */
  34. #define XP_MAX_PARTITIONS 64
  35. /*
  36. * Define the number of u64s required to represent all the C-brick nasids
  37. * as a bitmap. The cross-partition kernel modules deal only with
  38. * C-brick nasids, thus the need for bitmaps which don't account for
  39. * odd-numbered (non C-brick) nasids.
  40. */
  41. #define XP_MAX_PHYSNODE_ID (MAX_PHYSNODE_ID / 2)
  42. #define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8)
  43. #define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64)
  44. /*
  45. * Wrapper for bte_copy() that should it return a failure status will retry
  46. * the bte_copy() once in the hope that the failure was due to a temporary
  47. * aberration (i.e., the link going down temporarily).
  48. *
  49. * See bte_copy for definition of the input parameters.
  50. *
  51. * Note: xp_bte_copy() should never be called while holding a spinlock.
  52. */
  53. static inline bte_result_t
  54. xp_bte_copy(u64 src, u64 dest, u64 len, u64 mode, void *notification)
  55. {
  56. bte_result_t ret;
  57. ret = bte_copy(src, dest, len, mode, notification);
  58. if (ret != BTE_SUCCESS) {
  59. if (!in_interrupt()) {
  60. cond_resched();
  61. }
  62. ret = bte_copy(src, dest, len, mode, notification);
  63. }
  64. return ret;
  65. }
  66. /*
  67. * XPC establishes channel connections between the local partition and any
  68. * other partition that is currently up. Over these channels, kernel-level
  69. * `users' can communicate with their counterparts on the other partitions.
  70. *
  71. * The maxinum number of channels is limited to eight. For performance reasons,
  72. * the internal cross partition structures require sixteen bytes per channel,
  73. * and eight allows all of this interface-shared info to fit in one cache line.
  74. *
  75. * XPC_NCHANNELS reflects the total number of channels currently defined.
  76. * If the need for additional channels arises, one can simply increase
  77. * XPC_NCHANNELS accordingly. If the day should come where that number
  78. * exceeds the MAXIMUM number of channels allowed (eight), then one will need
  79. * to make changes to the XPC code to allow for this.
  80. */
  81. #define XPC_MEM_CHANNEL 0 /* memory channel number */
  82. #define XPC_NET_CHANNEL 1 /* network channel number */
  83. #define XPC_NCHANNELS 2 /* #of defined channels */
  84. #define XPC_MAX_NCHANNELS 8 /* max #of channels allowed */
  85. #if XPC_NCHANNELS > XPC_MAX_NCHANNELS
  86. #error XPC_NCHANNELS exceeds MAXIMUM allowed.
  87. #endif
  88. /*
  89. * The format of an XPC message is as follows:
  90. *
  91. * +-------+--------------------------------+
  92. * | flags |////////////////////////////////|
  93. * +-------+--------------------------------+
  94. * | message # |
  95. * +----------------------------------------+
  96. * | payload (user-defined message) |
  97. * | |
  98. * :
  99. * | |
  100. * +----------------------------------------+
  101. *
  102. * The size of the payload is defined by the user via xpc_connect(). A user-
  103. * defined message resides in the payload area.
  104. *
  105. * The user should have no dealings with the message header, but only the
  106. * message's payload. When a message entry is allocated (via xpc_allocate())
  107. * a pointer to the payload area is returned and not the actual beginning of
  108. * the XPC message. The user then constructs a message in the payload area
  109. * and passes that pointer as an argument on xpc_send() or xpc_send_notify().
  110. *
  111. * The size of a message entry (within a message queue) must be a cacheline
  112. * sized multiple in order to facilitate the BTE transfer of messages from one
  113. * message queue to another. A macro, XPC_MSG_SIZE(), is provided for the user
  114. * that wants to fit as many msg entries as possible in a given memory size
  115. * (e.g. a memory page).
  116. */
  117. struct xpc_msg {
  118. u8 flags; /* FOR XPC INTERNAL USE ONLY */
  119. u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */
  120. s64 number; /* FOR XPC INTERNAL USE ONLY */
  121. u64 payload; /* user defined portion of message */
  122. };
  123. #define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload)
  124. #define XPC_MSG_SIZE(_payload_size) \
  125. L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size))
  126. /*
  127. * Define the return values and values passed to user's callout functions.
  128. * (It is important to add new value codes at the end just preceding
  129. * xpcUnknownReason, which must have the highest numerical value.)
  130. */
  131. enum xpc_retval {
  132. xpcSuccess = 0,
  133. xpcNotConnected, /* 1: channel is not connected */
  134. xpcConnected, /* 2: channel connected (opened) */
  135. xpcRETIRED1, /* 3: (formerly xpcDisconnected) */
  136. xpcMsgReceived, /* 4: message received */
  137. xpcMsgDelivered, /* 5: message delivered and acknowledged */
  138. xpcRETIRED2, /* 6: (formerly xpcTransferFailed) */
  139. xpcNoWait, /* 7: operation would require wait */
  140. xpcRetry, /* 8: retry operation */
  141. xpcTimeout, /* 9: timeout in xpc_allocate_msg_wait() */
  142. xpcInterrupted, /* 10: interrupted wait */
  143. xpcUnequalMsgSizes, /* 11: message size disparity between sides */
  144. xpcInvalidAddress, /* 12: invalid address */
  145. xpcNoMemory, /* 13: no memory available for XPC structures */
  146. xpcLackOfResources, /* 14: insufficient resources for operation */
  147. xpcUnregistered, /* 15: channel is not registered */
  148. xpcAlreadyRegistered, /* 16: channel is already registered */
  149. xpcPartitionDown, /* 17: remote partition is down */
  150. xpcNotLoaded, /* 18: XPC module is not loaded */
  151. xpcUnloading, /* 19: this side is unloading XPC module */
  152. xpcBadMagic, /* 20: XPC MAGIC string not found */
  153. xpcReactivating, /* 21: remote partition was reactivated */
  154. xpcUnregistering, /* 22: this side is unregistering channel */
  155. xpcOtherUnregistering, /* 23: other side is unregistering channel */
  156. xpcCloneKThread, /* 24: cloning kernel thread */
  157. xpcCloneKThreadFailed, /* 25: cloning kernel thread failed */
  158. xpcNoHeartbeat, /* 26: remote partition has no heartbeat */
  159. xpcPioReadError, /* 27: PIO read error */
  160. xpcPhysAddrRegFailed, /* 28: registration of phys addr range failed */
  161. xpcBteDirectoryError, /* 29: maps to BTEFAIL_DIR */
  162. xpcBtePoisonError, /* 30: maps to BTEFAIL_POISON */
  163. xpcBteWriteError, /* 31: maps to BTEFAIL_WERR */
  164. xpcBteAccessError, /* 32: maps to BTEFAIL_ACCESS */
  165. xpcBtePWriteError, /* 33: maps to BTEFAIL_PWERR */
  166. xpcBtePReadError, /* 34: maps to BTEFAIL_PRERR */
  167. xpcBteTimeOutError, /* 35: maps to BTEFAIL_TOUT */
  168. xpcBteXtalkError, /* 36: maps to BTEFAIL_XTERR */
  169. xpcBteNotAvailable, /* 37: maps to BTEFAIL_NOTAVAIL */
  170. xpcBteUnmappedError, /* 38: unmapped BTEFAIL_ error */
  171. xpcBadVersion, /* 39: bad version number */
  172. xpcVarsNotSet, /* 40: the XPC variables are not set up */
  173. xpcNoRsvdPageAddr, /* 41: unable to get rsvd page's phys addr */
  174. xpcInvalidPartid, /* 42: invalid partition ID */
  175. xpcLocalPartid, /* 43: local partition ID */
  176. xpcUnknownReason /* 44: unknown reason -- must be last in list */
  177. };
  178. /*
  179. * Define the callout function types used by XPC to update the user on
  180. * connection activity and state changes (via the user function registered by
  181. * xpc_connect()) and to notify them of messages received and delivered (via
  182. * the user function registered by xpc_send_notify()).
  183. *
  184. * The two function types are xpc_channel_func and xpc_notify_func and
  185. * both share the following arguments, with the exception of "data", which
  186. * only xpc_channel_func has.
  187. *
  188. * Arguments:
  189. *
  190. * reason - reason code. (See following table.)
  191. * partid - partition ID associated with condition.
  192. * ch_number - channel # associated with condition.
  193. * data - pointer to optional data. (See following table.)
  194. * key - pointer to optional user-defined value provided as the "key"
  195. * argument to xpc_connect() or xpc_send_notify().
  196. *
  197. * In the following table the "Optional Data" column applies to callouts made
  198. * to functions registered by xpc_connect(). A "NA" in that column indicates
  199. * that this reason code can be passed to functions registered by
  200. * xpc_send_notify() (i.e. they don't have data arguments).
  201. *
  202. * Also, the first three reason codes in the following table indicate
  203. * success, whereas the others indicate failure. When a failure reason code
  204. * is received, one can assume that the channel is not connected.
  205. *
  206. *
  207. * Reason Code | Cause | Optional Data
  208. * =====================+================================+=====================
  209. * xpcConnected | connection has been established| max #of entries
  210. * | to the specified partition on | allowed in message
  211. * | the specified channel | queue
  212. * ---------------------+--------------------------------+---------------------
  213. * xpcMsgReceived | an XPC message arrived from | address of payload
  214. * | the specified partition on the |
  215. * | specified channel | [the user must call
  216. * | | xpc_received() when
  217. * | | finished with the
  218. * | | payload]
  219. * ---------------------+--------------------------------+---------------------
  220. * xpcMsgDelivered | notification that the message | NA
  221. * | was delivered to the intended |
  222. * | recipient and that they have |
  223. * | acknowledged its receipt by |
  224. * | calling xpc_received() |
  225. * =====================+================================+=====================
  226. * xpcUnequalMsgSizes | can't connect to the specified | NULL
  227. * | partition on the specified |
  228. * | channel because of mismatched |
  229. * | message sizes |
  230. * ---------------------+--------------------------------+---------------------
  231. * xpcNoMemory | insufficient memory avaiable | NULL
  232. * | to allocate message queue |
  233. * ---------------------+--------------------------------+---------------------
  234. * xpcLackOfResources | lack of resources to create | NULL
  235. * | the necessary kthreads to |
  236. * | support the channel |
  237. * ---------------------+--------------------------------+---------------------
  238. * xpcUnregistering | this side's user has | NULL or NA
  239. * | unregistered by calling |
  240. * | xpc_disconnect() |
  241. * ---------------------+--------------------------------+---------------------
  242. * xpcOtherUnregistering| the other side's user has | NULL or NA
  243. * | unregistered by calling |
  244. * | xpc_disconnect() |
  245. * ---------------------+--------------------------------+---------------------
  246. * xpcNoHeartbeat | the other side's XPC is no | NULL or NA
  247. * | longer heartbeating |
  248. * | |
  249. * ---------------------+--------------------------------+---------------------
  250. * xpcUnloading | this side's XPC module is | NULL or NA
  251. * | being unloaded |
  252. * | |
  253. * ---------------------+--------------------------------+---------------------
  254. * xpcOtherUnloading | the other side's XPC module is | NULL or NA
  255. * | is being unloaded |
  256. * | |
  257. * ---------------------+--------------------------------+---------------------
  258. * xpcPioReadError | xp_nofault_PIOR() returned an | NULL or NA
  259. * | error while sending an IPI |
  260. * | |
  261. * ---------------------+--------------------------------+---------------------
  262. * xpcInvalidAddress | the address either received or | NULL or NA
  263. * | sent by the specified partition|
  264. * | is invalid |
  265. * ---------------------+--------------------------------+---------------------
  266. * xpcBteNotAvailable | attempt to pull data from the | NULL or NA
  267. * xpcBtePoisonError | specified partition over the |
  268. * xpcBteWriteError | specified channel via a |
  269. * xpcBteAccessError | bte_copy() failed |
  270. * xpcBteTimeOutError | |
  271. * xpcBteXtalkError | |
  272. * xpcBteDirectoryError | |
  273. * xpcBteGenericError | |
  274. * xpcBteUnmappedError | |
  275. * ---------------------+--------------------------------+---------------------
  276. * xpcUnknownReason | the specified channel to the | NULL or NA
  277. * | specified partition was |
  278. * | unavailable for unknown reasons|
  279. * =====================+================================+=====================
  280. */
  281. typedef void (*xpc_channel_func)(enum xpc_retval reason, partid_t partid,
  282. int ch_number, void *data, void *key);
  283. typedef void (*xpc_notify_func)(enum xpc_retval reason, partid_t partid,
  284. int ch_number, void *key);
  285. /*
  286. * The following is a registration entry. There is a global array of these,
  287. * one per channel. It is used to record the connection registration made
  288. * by the users of XPC. As long as a registration entry exists, for any
  289. * partition that comes up, XPC will attempt to establish a connection on
  290. * that channel. Notification that a connection has been made will occur via
  291. * the xpc_channel_func function.
  292. *
  293. * The 'func' field points to the function to call when aynchronous
  294. * notification is required for such events as: a connection established/lost,
  295. * or an incomming message received, or an error condition encountered. A
  296. * non-NULL 'func' field indicates that there is an active registration for
  297. * the channel.
  298. */
  299. struct xpc_registration {
  300. struct semaphore sema;
  301. xpc_channel_func func; /* function to call */
  302. void *key; /* pointer to user's key */
  303. u16 nentries; /* #of msg entries in local msg queue */
  304. u16 msg_size; /* message queue's message size */
  305. u32 assigned_limit; /* limit on #of assigned kthreads */
  306. u32 idle_limit; /* limit on #of idle kthreads */
  307. } ____cacheline_aligned;
  308. #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
  309. /* the following are valid xpc_allocate() flags */
  310. #define XPC_WAIT 0 /* wait flag */
  311. #define XPC_NOWAIT 1 /* no wait flag */
  312. struct xpc_interface {
  313. void (*connect)(int);
  314. void (*disconnect)(int);
  315. enum xpc_retval (*allocate)(partid_t, int, u32, void **);
  316. enum xpc_retval (*send)(partid_t, int, void *);
  317. enum xpc_retval (*send_notify)(partid_t, int, void *,
  318. xpc_notify_func, void *);
  319. void (*received)(partid_t, int, void *);
  320. enum xpc_retval (*partid_to_nasids)(partid_t, void *);
  321. };
  322. extern struct xpc_interface xpc_interface;
  323. extern void xpc_set_interface(void (*)(int),
  324. void (*)(int),
  325. enum xpc_retval (*)(partid_t, int, u32, void **),
  326. enum xpc_retval (*)(partid_t, int, void *),
  327. enum xpc_retval (*)(partid_t, int, void *, xpc_notify_func,
  328. void *),
  329. void (*)(partid_t, int, void *),
  330. enum xpc_retval (*)(partid_t, void *));
  331. extern void xpc_clear_interface(void);
  332. extern enum xpc_retval xpc_connect(int, xpc_channel_func, void *, u16,
  333. u16, u32, u32);
  334. extern void xpc_disconnect(int);
  335. static inline enum xpc_retval
  336. xpc_allocate(partid_t partid, int ch_number, u32 flags, void **payload)
  337. {
  338. return xpc_interface.allocate(partid, ch_number, flags, payload);
  339. }
  340. static inline enum xpc_retval
  341. xpc_send(partid_t partid, int ch_number, void *payload)
  342. {
  343. return xpc_interface.send(partid, ch_number, payload);
  344. }
  345. static inline enum xpc_retval
  346. xpc_send_notify(partid_t partid, int ch_number, void *payload,
  347. xpc_notify_func func, void *key)
  348. {
  349. return xpc_interface.send_notify(partid, ch_number, payload, func, key);
  350. }
  351. static inline void
  352. xpc_received(partid_t partid, int ch_number, void *payload)
  353. {
  354. return xpc_interface.received(partid, ch_number, payload);
  355. }
  356. static inline enum xpc_retval
  357. xpc_partid_to_nasids(partid_t partid, void *nasids)
  358. {
  359. return xpc_interface.partid_to_nasids(partid, nasids);
  360. }
  361. extern u64 xp_nofault_PIOR_target;
  362. extern int xp_nofault_PIOR(void *);
  363. extern int xp_error_PIOR(void);
  364. #endif /* _ASM_IA64_SN_XP_H */