xp.h 18 KB

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