xp.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. * xpUnknownReason, which must have the highest numerical value.)
  143. */
  144. enum xp_retval {
  145. xpSuccess = 0,
  146. xpNotConnected, /* 1: channel is not connected */
  147. xpConnected, /* 2: channel connected (opened) */
  148. xpRETIRED1, /* 3: (formerly xpDisconnected) */
  149. xpMsgReceived, /* 4: message received */
  150. xpMsgDelivered, /* 5: message delivered and acknowledged */
  151. xpRETIRED2, /* 6: (formerly xpTransferFailed) */
  152. xpNoWait, /* 7: operation would require wait */
  153. xpRetry, /* 8: retry operation */
  154. xpTimeout, /* 9: timeout in xpc_allocate_msg_wait() */
  155. xpInterrupted, /* 10: interrupted wait */
  156. xpUnequalMsgSizes, /* 11: message size disparity between sides */
  157. xpInvalidAddress, /* 12: invalid address */
  158. xpNoMemory, /* 13: no memory available for XPC structures */
  159. xpLackOfResources, /* 14: insufficient resources for operation */
  160. xpUnregistered, /* 15: channel is not registered */
  161. xpAlreadyRegistered, /* 16: channel is already registered */
  162. xpPartitionDown, /* 17: remote partition is down */
  163. xpNotLoaded, /* 18: XPC module is not loaded */
  164. xpUnloading, /* 19: this side is unloading XPC module */
  165. xpBadMagic, /* 20: XPC MAGIC string not found */
  166. xpReactivating, /* 21: remote partition was reactivated */
  167. xpUnregistering, /* 22: this side is unregistering channel */
  168. xpOtherUnregistering, /* 23: other side is unregistering channel */
  169. xpCloneKThread, /* 24: cloning kernel thread */
  170. xpCloneKThreadFailed, /* 25: cloning kernel thread failed */
  171. xpNoHeartbeat, /* 26: remote partition has no heartbeat */
  172. xpPioReadError, /* 27: PIO read error */
  173. xpPhysAddrRegFailed, /* 28: registration of phys addr range failed */
  174. xpRETIRED3, /* 29: (formerly xpBteDirectoryError) */
  175. xpRETIRED4, /* 30: (formerly xpBtePoisonError) */
  176. xpRETIRED5, /* 31: (formerly xpBteWriteError) */
  177. xpRETIRED6, /* 32: (formerly xpBteAccessError) */
  178. xpRETIRED7, /* 33: (formerly xpBtePWriteError) */
  179. xpRETIRED8, /* 34: (formerly xpBtePReadError) */
  180. xpRETIRED9, /* 35: (formerly xpBteTimeOutError) */
  181. xpRETIRED10, /* 36: (formerly xpBteXtalkError) */
  182. xpRETIRED11, /* 37: (formerly xpBteNotAvailable) */
  183. xpRETIRED12, /* 38: (formerly xpBteUnmappedError) */
  184. xpBadVersion, /* 39: bad version number */
  185. xpVarsNotSet, /* 40: the XPC variables are not set up */
  186. xpNoRsvdPageAddr, /* 41: unable to get rsvd page's phys addr */
  187. xpInvalidPartid, /* 42: invalid partition ID */
  188. xpLocalPartid, /* 43: local partition ID */
  189. xpOtherGoingDown, /* 44: other side going down, reason unknown */
  190. xpSystemGoingDown, /* 45: system is going down, reason unknown */
  191. xpSystemHalt, /* 46: system is being halted */
  192. xpSystemReboot, /* 47: system is being rebooted */
  193. xpSystemPoweroff, /* 48: system is being powered off */
  194. xpDisconnecting, /* 49: channel disconnecting (closing) */
  195. xpOpenCloseError, /* 50: channel open/close protocol error */
  196. xpDisconnected, /* 51: channel disconnected (closed) */
  197. xpBteCopyError, /* 52: bte_copy() returned error */
  198. xpUnknownReason /* 53: unknown reason - must be last in enum */
  199. };
  200. /*
  201. * Define the callout function type used by XPC to update the user on
  202. * connection activity and state changes via the user function registered
  203. * by xpc_connect().
  204. *
  205. * Arguments:
  206. *
  207. * reason - reason code.
  208. * partid - partition ID associated with condition.
  209. * ch_number - channel # associated with condition.
  210. * data - pointer to optional data.
  211. * key - pointer to optional user-defined value provided as the "key"
  212. * argument to xpc_connect().
  213. *
  214. * A reason code of xpConnected indicates that a connection has been
  215. * established to the specified partition on the specified channel. The data
  216. * argument indicates the max number of entries allowed in the message queue.
  217. *
  218. * A reason code of xpMsgReceived indicates that a XPC message arrived from
  219. * the specified partition on the specified channel. The data argument
  220. * specifies the address of the message's payload. The user must call
  221. * xpc_received() when finished with the payload.
  222. *
  223. * All other reason codes indicate failure. The data argmument is NULL.
  224. * When a failure reason code is received, one can assume that the channel
  225. * is not connected.
  226. */
  227. typedef void (*xpc_channel_func) (enum xp_retval reason, short partid,
  228. int ch_number, void *data, void *key);
  229. /*
  230. * Define the callout function type used by XPC to notify the user of
  231. * messages received and delivered via the user function registered by
  232. * xpc_send_notify().
  233. *
  234. * Arguments:
  235. *
  236. * reason - reason code.
  237. * partid - partition ID associated with condition.
  238. * ch_number - channel # associated with condition.
  239. * key - pointer to optional user-defined value provided as the "key"
  240. * argument to xpc_send_notify().
  241. *
  242. * A reason code of xpMsgDelivered indicates that the message was delivered
  243. * to the intended recipient and that they have acknowledged its receipt by
  244. * calling xpc_received().
  245. *
  246. * All other reason codes indicate failure.
  247. */
  248. typedef void (*xpc_notify_func) (enum xp_retval reason, short partid,
  249. int ch_number, void *key);
  250. /*
  251. * The following is a registration entry. There is a global array of these,
  252. * one per channel. It is used to record the connection registration made
  253. * by the users of XPC. As long as a registration entry exists, for any
  254. * partition that comes up, XPC will attempt to establish a connection on
  255. * that channel. Notification that a connection has been made will occur via
  256. * the xpc_channel_func function.
  257. *
  258. * The 'func' field points to the function to call when aynchronous
  259. * notification is required for such events as: a connection established/lost,
  260. * or an incoming message received, or an error condition encountered. A
  261. * non-NULL 'func' field indicates that there is an active registration for
  262. * the channel.
  263. */
  264. struct xpc_registration {
  265. struct mutex mutex;
  266. xpc_channel_func func; /* function to call */
  267. void *key; /* pointer to user's key */
  268. u16 nentries; /* #of msg entries in local msg queue */
  269. u16 msg_size; /* message queue's message size */
  270. u32 assigned_limit; /* limit on #of assigned kthreads */
  271. u32 idle_limit; /* limit on #of idle kthreads */
  272. } ____cacheline_aligned;
  273. #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
  274. /* the following are valid xpc_allocate() flags */
  275. #define XPC_WAIT 0 /* wait flag */
  276. #define XPC_NOWAIT 1 /* no wait flag */
  277. struct xpc_interface {
  278. void (*connect) (int);
  279. void (*disconnect) (int);
  280. enum xp_retval (*allocate) (short, int, u32, void **);
  281. enum xp_retval (*send) (short, int, void *);
  282. enum xp_retval (*send_notify) (short, int, void *,
  283. xpc_notify_func, void *);
  284. void (*received) (short, int, void *);
  285. enum xp_retval (*partid_to_nasids) (short, void *);
  286. };
  287. extern struct xpc_interface xpc_interface;
  288. extern void xpc_set_interface(void (*)(int),
  289. void (*)(int),
  290. enum xp_retval (*)(short, int, u32, void **),
  291. enum xp_retval (*)(short, int, void *),
  292. enum xp_retval (*)(short, int, void *,
  293. xpc_notify_func, void *),
  294. void (*)(short, int, void *),
  295. enum xp_retval (*)(short, void *));
  296. extern void xpc_clear_interface(void);
  297. extern enum xp_retval xpc_connect(int, xpc_channel_func, void *, u16,
  298. u16, u32, u32);
  299. extern void xpc_disconnect(int);
  300. static inline enum xp_retval
  301. xpc_allocate(short partid, int ch_number, u32 flags, void **payload)
  302. {
  303. return xpc_interface.allocate(partid, ch_number, flags, payload);
  304. }
  305. static inline enum xp_retval
  306. xpc_send(short partid, int ch_number, void *payload)
  307. {
  308. return xpc_interface.send(partid, ch_number, payload);
  309. }
  310. static inline enum xp_retval
  311. xpc_send_notify(short partid, int ch_number, void *payload,
  312. xpc_notify_func func, void *key)
  313. {
  314. return xpc_interface.send_notify(partid, ch_number, payload, func, key);
  315. }
  316. static inline void
  317. xpc_received(short partid, int ch_number, void *payload)
  318. {
  319. return xpc_interface.received(partid, ch_number, payload);
  320. }
  321. static inline enum xp_retval
  322. xpc_partid_to_nasids(short partid, void *nasids)
  323. {
  324. return xpc_interface.partid_to_nasids(partid, nasids);
  325. }
  326. extern u64 xp_nofault_PIOR_target;
  327. extern int xp_nofault_PIOR(void *);
  328. extern int xp_error_PIOR(void);
  329. #endif /* _DRIVERS_MISC_SGIXP_XP_H */