blob: 3054fae8b02304655c722dc9fbd8a41750d2cb05 [file] [log] [blame]
Dean Nelsonb0d82bd2005-03-23 19:46:00 -07001/*
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 *
Dean Nelson45d9ca42008-04-22 14:46:56 -05006 * Copyright (C) 2004-2008 Silicon Graphics, Inc. All rights reserved.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -07007 */
8
Dean Nelsonb0d82bd2005-03-23 19:46:00 -07009/*
10 * External Cross Partition (XP) structures and defines.
11 */
12
Dean Nelson45d9ca42008-04-22 14:46:56 -050013#ifndef _DRIVERS_MISC_SGIXP_XP_H
14#define _DRIVERS_MISC_SGIXP_XP_H
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070015
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070016#include <linux/cache.h>
17#include <linux/hardirq.h>
Jes Sorensenf9e505a2006-01-17 12:52:21 -050018#include <linux/mutex.h>
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070019#include <asm/sn/types.h>
Dean Nelsonbc63d382008-07-29 22:34:04 -070020#ifdef CONFIG_IA64
21#include <asm/sn/arch.h>
22#endif
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070023
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070024#ifdef USE_DBUG_ON
25#define DBUG_ON(condition) BUG_ON(condition)
26#else
27#define DBUG_ON(condition)
28#endif
29
Dean Nelson355c54d2008-07-29 22:34:02 -070030#ifndef is_shub1
31#define is_shub1() 0
32#endif
33
34#ifndef is_shub2
35#define is_shub2() 0
36#endif
37
38#ifndef is_shub
39#define is_shub() (is_shub1() || is_shub2())
40#endif
41
42#ifndef is_uv
43#define is_uv() 0
44#endif
45
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070046/*
Dean Nelsonbc63d382008-07-29 22:34:04 -070047 * Define the maximum number of partitions the system can possibly support.
48 * It is based on the maximum number of hardware partitionable regions. The
49 * term 'region' in this context refers to the minimum number of nodes that
50 * can comprise an access protection grouping. The access protection is in
51 * regards to memory, IPI and IOI.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070052 *
53 * The maximum number of hardware partitionable regions is equal to the
54 * maximum number of nodes in the entire system divided by the minimum number
55 * of nodes that comprise an access protection grouping.
56 */
Dean Nelsonbc63d382008-07-29 22:34:04 -070057#define XP_MAX_NPARTITIONS_SN2 64
58#define XP_MAX_NPARTITIONS_UV 256
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070059
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070060/*
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070061 * XPC establishes channel connections between the local partition and any
62 * other partition that is currently up. Over these channels, kernel-level
63 * `users' can communicate with their counterparts on the other partitions.
64 *
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070065 * If the need for additional channels arises, one can simply increase
Dean Nelsonbc63d382008-07-29 22:34:04 -070066 * XPC_MAX_NCHANNELS accordingly. If the day should come where that number
67 * exceeds the absolute MAXIMUM number of channels possible (eight), then one
68 * will need to make changes to the XPC code to accommodate for this.
69 *
Dean Nelsonea57f802008-07-29 22:34:14 -070070 * The absolute maximum number of channels possible is limited to eight for
71 * performance reasons on sn2 hardware. The internal cross partition structures
Dean Nelsonbc63d382008-07-29 22:34:04 -070072 * require sixteen bytes per channel, and eight allows all of this
73 * interface-shared info to fit in one 128-byte cacheline.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070074 */
75#define XPC_MEM_CHANNEL 0 /* memory channel number */
76#define XPC_NET_CHANNEL 1 /* network channel number */
77
Dean Nelsonbc63d382008-07-29 22:34:04 -070078#define XPC_MAX_NCHANNELS 2 /* max #of channels allowed */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070079
Dean Nelsonbc63d382008-07-29 22:34:04 -070080#if XPC_MAX_NCHANNELS > 8
81#error XPC_MAX_NCHANNELS exceeds absolute MAXIMUM possible.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070082#endif
83
Dean Nelsonb0d82bd2005-03-23 19:46:00 -070084/*
85 * The format of an XPC message is as follows:
86 *
87 * +-------+--------------------------------+
88 * | flags |////////////////////////////////|
89 * +-------+--------------------------------+
90 * | message # |
91 * +----------------------------------------+
92 * | payload (user-defined message) |
93 * | |
94 * :
95 * | |
96 * +----------------------------------------+
97 *
98 * The size of the payload is defined by the user via xpc_connect(). A user-
99 * defined message resides in the payload area.
100 *
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700101 * The size of a message entry (within a message queue) must be a cacheline
102 * sized multiple in order to facilitate the BTE transfer of messages from one
103 * message queue to another. A macro, XPC_MSG_SIZE(), is provided for the user
104 * that wants to fit as many msg entries as possible in a given memory size
105 * (e.g. a memory page).
106 */
107struct xpc_msg {
108 u8 flags; /* FOR XPC INTERNAL USE ONLY */
109 u8 reserved[7]; /* FOR XPC INTERNAL USE ONLY */
110 s64 number; /* FOR XPC INTERNAL USE ONLY */
111
112 u64 payload; /* user defined portion of message */
113};
114
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700115#define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload)
116#define XPC_MSG_SIZE(_payload_size) \
117 L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size))
118
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700119/*
120 * Define the return values and values passed to user's callout functions.
121 * (It is important to add new value codes at the end just preceding
Dean Nelson65c17b82008-05-12 14:02:02 -0700122 * xpUnknownReason, which must have the highest numerical value.)
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700123 */
Dean Nelson65c17b82008-05-12 14:02:02 -0700124enum xp_retval {
125 xpSuccess = 0,
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700126
Dean Nelson65c17b82008-05-12 14:02:02 -0700127 xpNotConnected, /* 1: channel is not connected */
128 xpConnected, /* 2: channel connected (opened) */
129 xpRETIRED1, /* 3: (formerly xpDisconnected) */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700130
Dean Nelson65c17b82008-05-12 14:02:02 -0700131 xpMsgReceived, /* 4: message received */
132 xpMsgDelivered, /* 5: message delivered and acknowledged */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700133
Dean Nelson65c17b82008-05-12 14:02:02 -0700134 xpRETIRED2, /* 6: (formerly xpTransferFailed) */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700135
Dean Nelson65c17b82008-05-12 14:02:02 -0700136 xpNoWait, /* 7: operation would require wait */
137 xpRetry, /* 8: retry operation */
138 xpTimeout, /* 9: timeout in xpc_allocate_msg_wait() */
139 xpInterrupted, /* 10: interrupted wait */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700140
Dean Nelson65c17b82008-05-12 14:02:02 -0700141 xpUnequalMsgSizes, /* 11: message size disparity between sides */
142 xpInvalidAddress, /* 12: invalid address */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700143
Dean Nelson65c17b82008-05-12 14:02:02 -0700144 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 */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700148
Dean Nelson65c17b82008-05-12 14:02:02 -0700149 xpPartitionDown, /* 17: remote partition is down */
150 xpNotLoaded, /* 18: XPC module is not loaded */
151 xpUnloading, /* 19: this side is unloading XPC module */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700152
Dean Nelson65c17b82008-05-12 14:02:02 -0700153 xpBadMagic, /* 20: XPC MAGIC string not found */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700154
Dean Nelson65c17b82008-05-12 14:02:02 -0700155 xpReactivating, /* 21: remote partition was reactivated */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700156
Dean Nelson65c17b82008-05-12 14:02:02 -0700157 xpUnregistering, /* 22: this side is unregistering channel */
158 xpOtherUnregistering, /* 23: other side is unregistering channel */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700159
Dean Nelson65c17b82008-05-12 14:02:02 -0700160 xpCloneKThread, /* 24: cloning kernel thread */
161 xpCloneKThreadFailed, /* 25: cloning kernel thread failed */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700162
Dean Nelson65c17b82008-05-12 14:02:02 -0700163 xpNoHeartbeat, /* 26: remote partition has no heartbeat */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700164
Dean Nelson65c17b82008-05-12 14:02:02 -0700165 xpPioReadError, /* 27: PIO read error */
166 xpPhysAddrRegFailed, /* 28: registration of phys addr range failed */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700167
Dean Nelson65c17b82008-05-12 14:02:02 -0700168 xpRETIRED3, /* 29: (formerly xpBteDirectoryError) */
169 xpRETIRED4, /* 30: (formerly xpBtePoisonError) */
170 xpRETIRED5, /* 31: (formerly xpBteWriteError) */
171 xpRETIRED6, /* 32: (formerly xpBteAccessError) */
172 xpRETIRED7, /* 33: (formerly xpBtePWriteError) */
173 xpRETIRED8, /* 34: (formerly xpBtePReadError) */
174 xpRETIRED9, /* 35: (formerly xpBteTimeOutError) */
175 xpRETIRED10, /* 36: (formerly xpBteXtalkError) */
176 xpRETIRED11, /* 37: (formerly xpBteNotAvailable) */
177 xpRETIRED12, /* 38: (formerly xpBteUnmappedError) */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700178
Dean Nelson65c17b82008-05-12 14:02:02 -0700179 xpBadVersion, /* 39: bad version number */
180 xpVarsNotSet, /* 40: the XPC variables are not set up */
181 xpNoRsvdPageAddr, /* 41: unable to get rsvd page's phys addr */
182 xpInvalidPartid, /* 42: invalid partition ID */
183 xpLocalPartid, /* 43: local partition ID */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700184
Dean Nelson65c17b82008-05-12 14:02:02 -0700185 xpOtherGoingDown, /* 44: other side going down, reason unknown */
186 xpSystemGoingDown, /* 45: system is going down, reason unknown */
187 xpSystemHalt, /* 46: system is being halted */
188 xpSystemReboot, /* 47: system is being rebooted */
189 xpSystemPoweroff, /* 48: system is being powered off */
Dean Nelsona607c3892005-09-01 14:01:37 -0500190
Dean Nelson65c17b82008-05-12 14:02:02 -0700191 xpDisconnecting, /* 49: channel disconnecting (closing) */
Dean Nelsona607c3892005-09-01 14:01:37 -0500192
Dean Nelson65c17b82008-05-12 14:02:02 -0700193 xpOpenCloseError, /* 50: channel open/close protocol error */
Dean Nelsone54af722005-10-25 14:07:43 -0500194
Dean Nelson65c17b82008-05-12 14:02:02 -0700195 xpDisconnected, /* 51: channel disconnected (closed) */
Dean Nelson246c7e32005-12-22 14:32:56 -0600196
Dean Nelson65c17b82008-05-12 14:02:02 -0700197 xpBteCopyError, /* 52: bte_copy() returned error */
Dean Nelsonda970522008-07-29 22:34:03 -0700198 xpSalError, /* 53: sn SAL error */
Dean Nelson94bd2702008-07-29 22:34:05 -0700199 xpRsvdPageNotSet, /* 54: the reserved page is not set up */
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700200 xpPayloadTooBig, /* 55: payload too large for message slot */
Russ Anderson64135fa2007-08-21 16:45:12 -0500201
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700202 xpUnsupported, /* 56: unsupported functionality or resource */
203 xpUnknownReason /* 57: unknown reason - must be last in enum */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700204};
205
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700206/*
Dean Nelson65c17b82008-05-12 14:02:02 -0700207 * Define the callout function type used by XPC to update the user on
208 * connection activity and state changes via the user function registered
209 * by xpc_connect().
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700210 *
211 * Arguments:
212 *
Dean Nelson65c17b82008-05-12 14:02:02 -0700213 * reason - reason code.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700214 * partid - partition ID associated with condition.
215 * ch_number - channel # associated with condition.
Dean Nelson65c17b82008-05-12 14:02:02 -0700216 * data - pointer to optional data.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700217 * key - pointer to optional user-defined value provided as the "key"
Dean Nelson65c17b82008-05-12 14:02:02 -0700218 * argument to xpc_connect().
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700219 *
Dean Nelson65c17b82008-05-12 14:02:02 -0700220 * A reason code of xpConnected indicates that a connection has been
221 * established to the specified partition on the specified channel. The data
222 * argument indicates the max number of entries allowed in the message queue.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700223 *
Dean Nelson65c17b82008-05-12 14:02:02 -0700224 * A reason code of xpMsgReceived indicates that a XPC message arrived from
225 * the specified partition on the specified channel. The data argument
226 * specifies the address of the message's payload. The user must call
227 * xpc_received() when finished with the payload.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700228 *
Dean Nelson65c17b82008-05-12 14:02:02 -0700229 * All other reason codes indicate failure. The data argmument is NULL.
230 * When a failure reason code is received, one can assume that the channel
231 * is not connected.
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700232 */
Dean Nelson64d032b2008-05-12 14:02:03 -0700233typedef void (*xpc_channel_func) (enum xp_retval reason, short partid,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500234 int ch_number, void *data, void *key);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700235
Dean Nelson65c17b82008-05-12 14:02:02 -0700236/*
237 * Define the callout function type used by XPC to notify the user of
238 * messages received and delivered via the user function registered by
239 * xpc_send_notify().
240 *
241 * Arguments:
242 *
243 * reason - reason code.
244 * partid - partition ID associated with condition.
245 * ch_number - channel # associated with condition.
246 * key - pointer to optional user-defined value provided as the "key"
247 * argument to xpc_send_notify().
248 *
249 * A reason code of xpMsgDelivered indicates that the message was delivered
250 * to the intended recipient and that they have acknowledged its receipt by
251 * calling xpc_received().
252 *
253 * All other reason codes indicate failure.
254 */
Dean Nelson64d032b2008-05-12 14:02:03 -0700255typedef void (*xpc_notify_func) (enum xp_retval reason, short partid,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500256 int ch_number, void *key);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700257
258/*
259 * The following is a registration entry. There is a global array of these,
260 * one per channel. It is used to record the connection registration made
261 * by the users of XPC. As long as a registration entry exists, for any
262 * partition that comes up, XPC will attempt to establish a connection on
263 * that channel. Notification that a connection has been made will occur via
264 * the xpc_channel_func function.
265 *
266 * The 'func' field points to the function to call when aynchronous
267 * notification is required for such events as: a connection established/lost,
Dean Nelsone54af722005-10-25 14:07:43 -0500268 * or an incoming message received, or an error condition encountered. A
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700269 * non-NULL 'func' field indicates that there is an active registration for
270 * the channel.
271 */
272struct xpc_registration {
Jes Sorensenf9e505a2006-01-17 12:52:21 -0500273 struct mutex mutex;
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500274 xpc_channel_func func; /* function to call */
275 void *key; /* pointer to user's key */
276 u16 nentries; /* #of msg entries in local msg queue */
277 u16 msg_size; /* message queue's message size */
278 u32 assigned_limit; /* limit on #of assigned kthreads */
279 u32 idle_limit; /* limit on #of idle kthreads */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700280} ____cacheline_aligned;
281
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700282#define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
283
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700284/* the following are valid xpc_send() or xpc_send_notify() flags */
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500285#define XPC_WAIT 0 /* wait flag */
286#define XPC_NOWAIT 1 /* no wait flag */
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700287
288struct xpc_interface {
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500289 void (*connect) (int);
290 void (*disconnect) (int);
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700291 enum xp_retval (*send) (short, int, u32, void *, u16);
292 enum xp_retval (*send_notify) (short, int, u32, void *, u16,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500293 xpc_notify_func, void *);
Dean Nelson64d032b2008-05-12 14:02:03 -0700294 void (*received) (short, int, void *);
295 enum xp_retval (*partid_to_nasids) (short, void *);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700296};
297
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700298extern struct xpc_interface xpc_interface;
299
300extern void xpc_set_interface(void (*)(int),
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500301 void (*)(int),
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700302 enum xp_retval (*)(short, int, u32, void *, u16),
303 enum xp_retval (*)(short, int, u32, void *, u16,
304 xpc_notify_func, void *),
Dean Nelson64d032b2008-05-12 14:02:03 -0700305 void (*)(short, int, void *),
306 enum xp_retval (*)(short, void *));
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700307extern void xpc_clear_interface(void);
308
Dean Nelson65c17b82008-05-12 14:02:02 -0700309extern enum xp_retval xpc_connect(int, xpc_channel_func, void *, u16,
Dean Nelson4a3ad2d2008-04-22 14:48:01 -0500310 u16, u32, u32);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700311extern void xpc_disconnect(int);
312
Dean Nelson65c17b82008-05-12 14:02:02 -0700313static inline enum xp_retval
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700314xpc_send(short partid, int ch_number, u32 flags, void *payload,
315 u16 payload_size)
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700316{
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700317 return xpc_interface.send(partid, ch_number, flags, payload,
318 payload_size);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700319}
320
Dean Nelson65c17b82008-05-12 14:02:02 -0700321static inline enum xp_retval
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700322xpc_send_notify(short partid, int ch_number, u32 flags, void *payload,
323 u16 payload_size, xpc_notify_func func, void *key)
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700324{
Dean Nelson97bf1aa2008-07-29 22:34:08 -0700325 return xpc_interface.send_notify(partid, ch_number, flags, payload,
326 payload_size, func, key);
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700327}
328
329static inline void
Dean Nelson64d032b2008-05-12 14:02:03 -0700330xpc_received(short partid, int ch_number, void *payload)
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700331{
332 return xpc_interface.received(partid, ch_number, payload);
333}
334
Dean Nelson65c17b82008-05-12 14:02:02 -0700335static inline enum xp_retval
Dean Nelson64d032b2008-05-12 14:02:03 -0700336xpc_partid_to_nasids(short partid, void *nasids)
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700337{
338 return xpc_interface.partid_to_nasids(partid, nasids);
339}
340
Dean Nelsonbc63d382008-07-29 22:34:04 -0700341extern short xp_max_npartitions;
342
Dean Nelson908787d2008-07-29 22:34:05 -0700343extern enum xp_retval (*xp_remote_memcpy) (void *, const void *, size_t);
344
Dean Nelsonb0d82bd2005-03-23 19:46:00 -0700345extern u64 xp_nofault_PIOR_target;
346extern int xp_nofault_PIOR(void *);
347extern int xp_error_PIOR(void);
348
Dean Nelsonbc63d382008-07-29 22:34:04 -0700349extern struct device *xp;
350extern enum xp_retval xp_init_sn2(void);
351extern enum xp_retval xp_init_uv(void);
352extern void xp_exit_sn2(void);
353extern void xp_exit_uv(void);
354
Dean Nelson45d9ca42008-04-22 14:46:56 -0500355#endif /* _DRIVERS_MISC_SGIXP_XP_H */