xp.h 12 KB

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