xp.h 12 KB

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