xp.h 17 KB

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