xp.h 13 KB

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