xp.h 12 KB

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