xp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #ifndef is_shub1
  24. #define is_shub1() 0
  25. #endif
  26. #ifndef is_shub2
  27. #define is_shub2() 0
  28. #endif
  29. #ifndef is_shub
  30. #define is_shub() (is_shub1() || is_shub2())
  31. #endif
  32. #ifndef is_uv
  33. #define is_uv() 0
  34. #endif
  35. /*
  36. * Define the maximum number of logically defined partitions the system
  37. * can support. It is constrained by the maximum number of hardware
  38. * partitionable regions. The term 'region' in this context refers to the
  39. * minimum number of nodes that can comprise an access protection grouping.
  40. * The access protection is in regards to memory, IPI and IOI.
  41. *
  42. * The maximum number of hardware partitionable regions is equal to the
  43. * maximum number of nodes in the entire system divided by the minimum number
  44. * of nodes that comprise an access protection grouping.
  45. */
  46. #define XP_MAX_PARTITIONS 64
  47. /*
  48. * Define the number of u64s required to represent all the C-brick nasids
  49. * as a bitmap. The cross-partition kernel modules deal only with
  50. * C-brick nasids, thus the need for bitmaps which don't account for
  51. * odd-numbered (non C-brick) nasids.
  52. */
  53. #define XP_MAX_PHYSNODE_ID (MAX_NUMALINK_NODES / 2)
  54. #define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8)
  55. #define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64)
  56. /*
  57. * Wrapper for bte_copy() that should it return a failure status will retry
  58. * the bte_copy() once in the hope that the failure was due to a temporary
  59. * aberration (i.e., the link going down temporarily).
  60. *
  61. * src - physical address of the source of the transfer.
  62. * vdst - virtual address of the destination of the transfer.
  63. * len - number of bytes to transfer from source to destination.
  64. * mode - see bte_copy() for definition.
  65. * notification - see bte_copy() for definition.
  66. *
  67. * Note: xp_bte_copy() should never be called while holding a spinlock.
  68. */
  69. static inline bte_result_t
  70. xp_bte_copy(u64 src, u64 vdst, u64 len, u64 mode, void *notification)
  71. {
  72. bte_result_t ret;
  73. u64 pdst = ia64_tpa(vdst);
  74. /*
  75. * Ensure that the physically mapped memory is contiguous.
  76. *
  77. * We do this by ensuring that the memory is from region 7 only.
  78. * If the need should arise to use memory from one of the other
  79. * regions, then modify the BUG_ON() statement to ensure that the
  80. * memory from that region is always physically contiguous.
  81. */
  82. BUG_ON(REGION_NUMBER(vdst) != RGN_KERNEL);
  83. ret = bte_copy(src, pdst, len, mode, notification);
  84. if ((ret != BTE_SUCCESS) && BTE_ERROR_RETRY(ret)) {
  85. if (!in_interrupt())
  86. cond_resched();
  87. ret = bte_copy(src, pdst, len, mode, notification);
  88. }
  89. return ret;
  90. }
  91. /*
  92. * XPC establishes channel connections between the local partition and any
  93. * other partition that is currently up. Over these channels, kernel-level
  94. * `users' can communicate with their counterparts on the other partitions.
  95. *
  96. * The maxinum number of channels is limited to eight. For performance reasons,
  97. * the internal cross partition structures require sixteen bytes per channel,
  98. * and eight allows all of this interface-shared info to fit in one cache line.
  99. *
  100. * XPC_NCHANNELS reflects the total number of channels currently defined.
  101. * If the need for additional channels arises, one can simply increase
  102. * XPC_NCHANNELS accordingly. If the day should come where that number
  103. * exceeds the MAXIMUM number of channels allowed (eight), then one will need
  104. * to make changes to the XPC code to allow for this.
  105. */
  106. #define XPC_MEM_CHANNEL 0 /* memory channel number */
  107. #define XPC_NET_CHANNEL 1 /* network channel number */
  108. #define XPC_NCHANNELS 2 /* #of defined channels */
  109. #define XPC_MAX_NCHANNELS 8 /* max #of channels allowed */
  110. #if XPC_NCHANNELS > XPC_MAX_NCHANNELS
  111. #error XPC_NCHANNELS exceeds MAXIMUM allowed.
  112. #endif
  113. /*
  114. * The format of an XPC message is as follows:
  115. *
  116. * +-------+--------------------------------+
  117. * | flags |////////////////////////////////|
  118. * +-------+--------------------------------+
  119. * | message # |
  120. * +----------------------------------------+
  121. * | payload (user-defined message) |
  122. * | |
  123. * :
  124. * | |
  125. * +----------------------------------------+
  126. *
  127. * The size of the payload is defined by the user via xpc_connect(). A user-
  128. * defined message resides in the payload area.
  129. *
  130. * The user should have no dealings with the message header, but only the
  131. * message's payload. When a message entry is allocated (via xpc_allocate())
  132. * a pointer to the payload area is returned and not the actual beginning of
  133. * the XPC message. The user then constructs a message in the payload area
  134. * and passes that pointer as an argument on xpc_send() or xpc_send_notify().
  135. *
  136. * The size of a message entry (within a message queue) must be a cacheline
  137. * sized multiple in order to facilitate the BTE transfer of messages from one
  138. * message queue to another. A macro, XPC_MSG_SIZE(), is provided for the user
  139. * that wants to fit as many msg entries as possible in a given memory size
  140. * (e.g. a memory page).
  141. */
  142. struct xpc_msg {
  143. u8 flags; /* FOR XPC INTERNAL USE ONLY */
  144. u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */
  145. s64 number; /* FOR XPC INTERNAL USE ONLY */
  146. u64 payload; /* user defined portion of message */
  147. };
  148. #define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload)
  149. #define XPC_MSG_SIZE(_payload_size) \
  150. L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size))
  151. /*
  152. * Define the return values and values passed to user's callout functions.
  153. * (It is important to add new value codes at the end just preceding
  154. * xpUnknownReason, which must have the highest numerical value.)
  155. */
  156. enum xp_retval {
  157. xpSuccess = 0,
  158. xpNotConnected, /* 1: channel is not connected */
  159. xpConnected, /* 2: channel connected (opened) */
  160. xpRETIRED1, /* 3: (formerly xpDisconnected) */
  161. xpMsgReceived, /* 4: message received */
  162. xpMsgDelivered, /* 5: message delivered and acknowledged */
  163. xpRETIRED2, /* 6: (formerly xpTransferFailed) */
  164. xpNoWait, /* 7: operation would require wait */
  165. xpRetry, /* 8: retry operation */
  166. xpTimeout, /* 9: timeout in xpc_allocate_msg_wait() */
  167. xpInterrupted, /* 10: interrupted wait */
  168. xpUnequalMsgSizes, /* 11: message size disparity between sides */
  169. xpInvalidAddress, /* 12: invalid address */
  170. xpNoMemory, /* 13: no memory available for XPC structures */
  171. xpLackOfResources, /* 14: insufficient resources for operation */
  172. xpUnregistered, /* 15: channel is not registered */
  173. xpAlreadyRegistered, /* 16: channel is already registered */
  174. xpPartitionDown, /* 17: remote partition is down */
  175. xpNotLoaded, /* 18: XPC module is not loaded */
  176. xpUnloading, /* 19: this side is unloading XPC module */
  177. xpBadMagic, /* 20: XPC MAGIC string not found */
  178. xpReactivating, /* 21: remote partition was reactivated */
  179. xpUnregistering, /* 22: this side is unregistering channel */
  180. xpOtherUnregistering, /* 23: other side is unregistering channel */
  181. xpCloneKThread, /* 24: cloning kernel thread */
  182. xpCloneKThreadFailed, /* 25: cloning kernel thread failed */
  183. xpNoHeartbeat, /* 26: remote partition has no heartbeat */
  184. xpPioReadError, /* 27: PIO read error */
  185. xpPhysAddrRegFailed, /* 28: registration of phys addr range failed */
  186. xpRETIRED3, /* 29: (formerly xpBteDirectoryError) */
  187. xpRETIRED4, /* 30: (formerly xpBtePoisonError) */
  188. xpRETIRED5, /* 31: (formerly xpBteWriteError) */
  189. xpRETIRED6, /* 32: (formerly xpBteAccessError) */
  190. xpRETIRED7, /* 33: (formerly xpBtePWriteError) */
  191. xpRETIRED8, /* 34: (formerly xpBtePReadError) */
  192. xpRETIRED9, /* 35: (formerly xpBteTimeOutError) */
  193. xpRETIRED10, /* 36: (formerly xpBteXtalkError) */
  194. xpRETIRED11, /* 37: (formerly xpBteNotAvailable) */
  195. xpRETIRED12, /* 38: (formerly xpBteUnmappedError) */
  196. xpBadVersion, /* 39: bad version number */
  197. xpVarsNotSet, /* 40: the XPC variables are not set up */
  198. xpNoRsvdPageAddr, /* 41: unable to get rsvd page's phys addr */
  199. xpInvalidPartid, /* 42: invalid partition ID */
  200. xpLocalPartid, /* 43: local partition ID */
  201. xpOtherGoingDown, /* 44: other side going down, reason unknown */
  202. xpSystemGoingDown, /* 45: system is going down, reason unknown */
  203. xpSystemHalt, /* 46: system is being halted */
  204. xpSystemReboot, /* 47: system is being rebooted */
  205. xpSystemPoweroff, /* 48: system is being powered off */
  206. xpDisconnecting, /* 49: channel disconnecting (closing) */
  207. xpOpenCloseError, /* 50: channel open/close protocol error */
  208. xpDisconnected, /* 51: channel disconnected (closed) */
  209. xpBteCopyError, /* 52: bte_copy() returned error */
  210. xpSalError, /* 53: sn SAL error */
  211. xpUnknownReason /* 54: unknown reason - must be last in enum */
  212. };
  213. /*
  214. * Define the callout function type used by XPC to update the user on
  215. * connection activity and state changes via the user function registered
  216. * by xpc_connect().
  217. *
  218. * Arguments:
  219. *
  220. * reason - reason code.
  221. * partid - partition ID associated with condition.
  222. * ch_number - channel # associated with condition.
  223. * data - pointer to optional data.
  224. * key - pointer to optional user-defined value provided as the "key"
  225. * argument to xpc_connect().
  226. *
  227. * A reason code of xpConnected indicates that a connection has been
  228. * established to the specified partition on the specified channel. The data
  229. * argument indicates the max number of entries allowed in the message queue.
  230. *
  231. * A reason code of xpMsgReceived indicates that a XPC message arrived from
  232. * the specified partition on the specified channel. The data argument
  233. * specifies the address of the message's payload. The user must call
  234. * xpc_received() when finished with the payload.
  235. *
  236. * All other reason codes indicate failure. The data argmument is NULL.
  237. * When a failure reason code is received, one can assume that the channel
  238. * is not connected.
  239. */
  240. typedef void (*xpc_channel_func) (enum xp_retval reason, short partid,
  241. int ch_number, void *data, void *key);
  242. /*
  243. * Define the callout function type used by XPC to notify the user of
  244. * messages received and delivered via the user function registered by
  245. * xpc_send_notify().
  246. *
  247. * Arguments:
  248. *
  249. * reason - reason code.
  250. * partid - partition ID associated with condition.
  251. * ch_number - channel # associated with condition.
  252. * key - pointer to optional user-defined value provided as the "key"
  253. * argument to xpc_send_notify().
  254. *
  255. * A reason code of xpMsgDelivered indicates that the message was delivered
  256. * to the intended recipient and that they have acknowledged its receipt by
  257. * calling xpc_received().
  258. *
  259. * All other reason codes indicate failure.
  260. */
  261. typedef void (*xpc_notify_func) (enum xp_retval reason, short partid,
  262. int ch_number, void *key);
  263. /*
  264. * The following is a registration entry. There is a global array of these,
  265. * one per channel. It is used to record the connection registration made
  266. * by the users of XPC. As long as a registration entry exists, for any
  267. * partition that comes up, XPC will attempt to establish a connection on
  268. * that channel. Notification that a connection has been made will occur via
  269. * the xpc_channel_func function.
  270. *
  271. * The 'func' field points to the function to call when aynchronous
  272. * notification is required for such events as: a connection established/lost,
  273. * or an incoming message received, or an error condition encountered. A
  274. * non-NULL 'func' field indicates that there is an active registration for
  275. * the channel.
  276. */
  277. struct xpc_registration {
  278. struct mutex mutex;
  279. xpc_channel_func func; /* function to call */
  280. void *key; /* pointer to user's key */
  281. u16 nentries; /* #of msg entries in local msg queue */
  282. u16 msg_size; /* message queue's message size */
  283. u32 assigned_limit; /* limit on #of assigned kthreads */
  284. u32 idle_limit; /* limit on #of idle kthreads */
  285. } ____cacheline_aligned;
  286. #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
  287. /* the following are valid xpc_allocate() flags */
  288. #define XPC_WAIT 0 /* wait flag */
  289. #define XPC_NOWAIT 1 /* no wait flag */
  290. struct xpc_interface {
  291. void (*connect) (int);
  292. void (*disconnect) (int);
  293. enum xp_retval (*allocate) (short, int, u32, void **);
  294. enum xp_retval (*send) (short, int, void *);
  295. enum xp_retval (*send_notify) (short, int, void *,
  296. xpc_notify_func, void *);
  297. void (*received) (short, int, void *);
  298. enum xp_retval (*partid_to_nasids) (short, void *);
  299. };
  300. extern struct xpc_interface xpc_interface;
  301. extern void xpc_set_interface(void (*)(int),
  302. void (*)(int),
  303. enum xp_retval (*)(short, int, u32, void **),
  304. enum xp_retval (*)(short, int, void *),
  305. enum xp_retval (*)(short, int, void *,
  306. xpc_notify_func, void *),
  307. void (*)(short, int, void *),
  308. enum xp_retval (*)(short, void *));
  309. extern void xpc_clear_interface(void);
  310. extern enum xp_retval xpc_connect(int, xpc_channel_func, void *, u16,
  311. u16, u32, u32);
  312. extern void xpc_disconnect(int);
  313. static inline enum xp_retval
  314. xpc_allocate(short partid, int ch_number, u32 flags, void **payload)
  315. {
  316. return xpc_interface.allocate(partid, ch_number, flags, payload);
  317. }
  318. static inline enum xp_retval
  319. xpc_send(short partid, int ch_number, void *payload)
  320. {
  321. return xpc_interface.send(partid, ch_number, payload);
  322. }
  323. static inline enum xp_retval
  324. xpc_send_notify(short partid, int ch_number, void *payload,
  325. xpc_notify_func func, void *key)
  326. {
  327. return xpc_interface.send_notify(partid, ch_number, payload, func, key);
  328. }
  329. static inline void
  330. xpc_received(short partid, int ch_number, void *payload)
  331. {
  332. return xpc_interface.received(partid, ch_number, payload);
  333. }
  334. static inline enum xp_retval
  335. xpc_partid_to_nasids(short partid, void *nasids)
  336. {
  337. return xpc_interface.partid_to_nasids(partid, nasids);
  338. }
  339. extern u64 xp_nofault_PIOR_target;
  340. extern int xp_nofault_PIOR(void *);
  341. extern int xp_error_PIOR(void);
  342. #endif /* _DRIVERS_MISC_SGIXP_XP_H */