xp.h 14 KB

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