xp.h 19 KB

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