xp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 <linux/mutex.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_NUMALINK_NODES / 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. xpcOtherGoingDown, /* 44: other side going down, reason unknown */
  177. xpcSystemGoingDown, /* 45: system is going down, reason unknown */
  178. xpcSystemHalt, /* 46: system is being halted */
  179. xpcSystemReboot, /* 47: system is being rebooted */
  180. xpcSystemPoweroff, /* 48: system is being powered off */
  181. xpcDisconnecting, /* 49: channel disconnecting (closing) */
  182. xpcOpenCloseError, /* 50: channel open/close protocol error */
  183. xpcDisconnected, /* 51: channel disconnected (closed) */
  184. xpcUnknownReason /* 52: unknown reason -- must be last in list */
  185. };
  186. /*
  187. * Define the callout function types used by XPC to update the user on
  188. * connection activity and state changes (via the user function registered by
  189. * xpc_connect()) and to notify them of messages received and delivered (via
  190. * the user function registered by xpc_send_notify()).
  191. *
  192. * The two function types are xpc_channel_func and xpc_notify_func and
  193. * both share the following arguments, with the exception of "data", which
  194. * only xpc_channel_func has.
  195. *
  196. * Arguments:
  197. *
  198. * reason - reason code. (See following table.)
  199. * partid - partition ID associated with condition.
  200. * ch_number - channel # associated with condition.
  201. * data - pointer to optional data. (See following table.)
  202. * key - pointer to optional user-defined value provided as the "key"
  203. * argument to xpc_connect() or xpc_send_notify().
  204. *
  205. * In the following table the "Optional Data" column applies to callouts made
  206. * to functions registered by xpc_connect(). A "NA" in that column indicates
  207. * that this reason code can be passed to functions registered by
  208. * xpc_send_notify() (i.e. they don't have data arguments).
  209. *
  210. * Also, the first three reason codes in the following table indicate
  211. * success, whereas the others indicate failure. When a failure reason code
  212. * is received, one can assume that the channel is not connected.
  213. *
  214. *
  215. * Reason Code | Cause | Optional Data
  216. * =====================+================================+=====================
  217. * xpcConnected | connection has been established| max #of entries
  218. * | to the specified partition on | allowed in message
  219. * | the specified channel | queue
  220. * ---------------------+--------------------------------+---------------------
  221. * xpcMsgReceived | an XPC message arrived from | address of payload
  222. * | the specified partition on the |
  223. * | specified channel | [the user must call
  224. * | | xpc_received() when
  225. * | | finished with the
  226. * | | payload]
  227. * ---------------------+--------------------------------+---------------------
  228. * xpcMsgDelivered | notification that the message | NA
  229. * | was delivered to the intended |
  230. * | recipient and that they have |
  231. * | acknowledged its receipt by |
  232. * | calling xpc_received() |
  233. * =====================+================================+=====================
  234. * xpcUnequalMsgSizes | can't connect to the specified | NULL
  235. * | partition on the specified |
  236. * | channel because of mismatched |
  237. * | message sizes |
  238. * ---------------------+--------------------------------+---------------------
  239. * xpcNoMemory | insufficient memory avaiable | NULL
  240. * | to allocate message queue |
  241. * ---------------------+--------------------------------+---------------------
  242. * xpcLackOfResources | lack of resources to create | NULL
  243. * | the necessary kthreads to |
  244. * | support the channel |
  245. * ---------------------+--------------------------------+---------------------
  246. * xpcUnregistering | this side's user has | NULL or NA
  247. * | unregistered by calling |
  248. * | xpc_disconnect() |
  249. * ---------------------+--------------------------------+---------------------
  250. * xpcOtherUnregistering| the other side's user has | NULL or NA
  251. * | unregistered by calling |
  252. * | xpc_disconnect() |
  253. * ---------------------+--------------------------------+---------------------
  254. * xpcNoHeartbeat | the other side's XPC is no | NULL or NA
  255. * | longer heartbeating |
  256. * | |
  257. * ---------------------+--------------------------------+---------------------
  258. * xpcUnloading | this side's XPC module is | NULL or NA
  259. * | being unloaded |
  260. * | |
  261. * ---------------------+--------------------------------+---------------------
  262. * xpcOtherUnloading | the other side's XPC module is | NULL or NA
  263. * | is being unloaded |
  264. * | |
  265. * ---------------------+--------------------------------+---------------------
  266. * xpcPioReadError | xp_nofault_PIOR() returned an | NULL or NA
  267. * | error while sending an IPI |
  268. * | |
  269. * ---------------------+--------------------------------+---------------------
  270. * xpcInvalidAddress | the address either received or | NULL or NA
  271. * | sent by the specified partition|
  272. * | is invalid |
  273. * ---------------------+--------------------------------+---------------------
  274. * xpcBteNotAvailable | attempt to pull data from the | NULL or NA
  275. * xpcBtePoisonError | specified partition over the |
  276. * xpcBteWriteError | specified channel via a |
  277. * xpcBteAccessError | bte_copy() failed |
  278. * xpcBteTimeOutError | |
  279. * xpcBteXtalkError | |
  280. * xpcBteDirectoryError | |
  281. * xpcBteGenericError | |
  282. * xpcBteUnmappedError | |
  283. * ---------------------+--------------------------------+---------------------
  284. * xpcUnknownReason | the specified channel to the | NULL or NA
  285. * | specified partition was |
  286. * | unavailable for unknown reasons|
  287. * =====================+================================+=====================
  288. */
  289. typedef void (*xpc_channel_func)(enum xpc_retval reason, partid_t partid,
  290. int ch_number, void *data, void *key);
  291. typedef void (*xpc_notify_func)(enum xpc_retval reason, partid_t partid,
  292. int ch_number, void *key);
  293. /*
  294. * The following is a registration entry. There is a global array of these,
  295. * one per channel. It is used to record the connection registration made
  296. * by the users of XPC. As long as a registration entry exists, for any
  297. * partition that comes up, XPC will attempt to establish a connection on
  298. * that channel. Notification that a connection has been made will occur via
  299. * the xpc_channel_func function.
  300. *
  301. * The 'func' field points to the function to call when aynchronous
  302. * notification is required for such events as: a connection established/lost,
  303. * or an incoming message received, or an error condition encountered. A
  304. * non-NULL 'func' field indicates that there is an active registration for
  305. * the channel.
  306. */
  307. struct xpc_registration {
  308. struct mutex mutex;
  309. xpc_channel_func func; /* function to call */
  310. void *key; /* pointer to user's key */
  311. u16 nentries; /* #of msg entries in local msg queue */
  312. u16 msg_size; /* message queue's message size */
  313. u32 assigned_limit; /* limit on #of assigned kthreads */
  314. u32 idle_limit; /* limit on #of idle kthreads */
  315. } ____cacheline_aligned;
  316. #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
  317. /* the following are valid xpc_allocate() flags */
  318. #define XPC_WAIT 0 /* wait flag */
  319. #define XPC_NOWAIT 1 /* no wait flag */
  320. struct xpc_interface {
  321. void (*connect)(int);
  322. void (*disconnect)(int);
  323. enum xpc_retval (*allocate)(partid_t, int, u32, void **);
  324. enum xpc_retval (*send)(partid_t, int, void *);
  325. enum xpc_retval (*send_notify)(partid_t, int, void *,
  326. xpc_notify_func, void *);
  327. void (*received)(partid_t, int, void *);
  328. enum xpc_retval (*partid_to_nasids)(partid_t, void *);
  329. };
  330. extern struct xpc_interface xpc_interface;
  331. extern void xpc_set_interface(void (*)(int),
  332. void (*)(int),
  333. enum xpc_retval (*)(partid_t, int, u32, void **),
  334. enum xpc_retval (*)(partid_t, int, void *),
  335. enum xpc_retval (*)(partid_t, int, void *, xpc_notify_func,
  336. void *),
  337. void (*)(partid_t, int, void *),
  338. enum xpc_retval (*)(partid_t, void *));
  339. extern void xpc_clear_interface(void);
  340. extern enum xpc_retval xpc_connect(int, xpc_channel_func, void *, u16,
  341. u16, u32, u32);
  342. extern void xpc_disconnect(int);
  343. static inline enum xpc_retval
  344. xpc_allocate(partid_t partid, int ch_number, u32 flags, void **payload)
  345. {
  346. return xpc_interface.allocate(partid, ch_number, flags, payload);
  347. }
  348. static inline enum xpc_retval
  349. xpc_send(partid_t partid, int ch_number, void *payload)
  350. {
  351. return xpc_interface.send(partid, ch_number, payload);
  352. }
  353. static inline enum xpc_retval
  354. xpc_send_notify(partid_t partid, int ch_number, void *payload,
  355. xpc_notify_func func, void *key)
  356. {
  357. return xpc_interface.send_notify(partid, ch_number, payload, func, key);
  358. }
  359. static inline void
  360. xpc_received(partid_t partid, int ch_number, void *payload)
  361. {
  362. return xpc_interface.received(partid, ch_number, payload);
  363. }
  364. static inline enum xpc_retval
  365. xpc_partid_to_nasids(partid_t partid, void *nasids)
  366. {
  367. return xpc_interface.partid_to_nasids(partid, nasids);
  368. }
  369. extern u64 xp_nofault_PIOR_target;
  370. extern int xp_nofault_PIOR(void *);
  371. extern int xp_error_PIOR(void);
  372. #endif /* _ASM_IA64_SN_XP_H */