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
6 * Copyright (C) 2004-2008 Silicon Graphics, Inc. All rights reserved.
10 * External Cross Partition (XP) structures and defines.
13 #ifndef _DRIVERS_MISC_SGIXP_XP_H
14 #define _DRIVERS_MISC_SGIXP_XP_H
16 #include <linux/cache.h>
17 #include <linux/hardirq.h>
18 #include <linux/mutex.h>
19 #include <asm/sn/types.h>
20 #include <asm/sn/bte.h>
23 #define DBUG_ON(condition) BUG_ON(condition)
25 #define DBUG_ON(condition)
29 * Define the maximum number of logically defined partitions the system
30 * can support. It is constrained by the maximum number of hardware
31 * partitionable regions. The term 'region' in this context refers to the
32 * minimum number of nodes that can comprise an access protection grouping.
33 * The access protection is in regards to memory, IPI and IOI.
35 * The maximum number of hardware partitionable regions is equal to the
36 * maximum number of nodes in the entire system divided by the minimum number
37 * of nodes that comprise an access protection grouping.
39 #define XP_MAX_PARTITIONS 64
42 * Define the number of u64s required to represent all the C-brick nasids
43 * as a bitmap. The cross-partition kernel modules deal only with
44 * C-brick nasids, thus the need for bitmaps which don't account for
45 * odd-numbered (non C-brick) nasids.
47 #define XP_MAX_PHYSNODE_ID (MAX_NUMALINK_NODES / 2)
48 #define XP_NASID_MASK_BYTES ((XP_MAX_PHYSNODE_ID + 7) / 8)
49 #define XP_NASID_MASK_WORDS ((XP_MAX_PHYSNODE_ID + 63) / 64)
52 * Wrapper for bte_copy() that should it return a failure status will retry
53 * the bte_copy() once in the hope that the failure was due to a temporary
54 * aberration (i.e., the link going down temporarily).
56 * src - physical address of the source of the transfer.
57 * vdst - virtual address of the destination of the transfer.
58 * len - number of bytes to transfer from source to destination.
59 * mode - see bte_copy() for definition.
60 * notification - see bte_copy() for definition.
62 * Note: xp_bte_copy() should never be called while holding a spinlock.
64 static inline bte_result_t
65 xp_bte_copy(u64 src
, u64 vdst
, u64 len
, u64 mode
, void *notification
)
68 u64 pdst
= ia64_tpa(vdst
);
71 * Ensure that the physically mapped memory is contiguous.
73 * We do this by ensuring that the memory is from region 7 only.
74 * If the need should arise to use memory from one of the other
75 * regions, then modify the BUG_ON() statement to ensure that the
76 * memory from that region is always physically contiguous.
78 BUG_ON(REGION_NUMBER(vdst
) != RGN_KERNEL
);
80 ret
= bte_copy(src
, pdst
, len
, mode
, notification
);
81 if ((ret
!= BTE_SUCCESS
) && BTE_ERROR_RETRY(ret
)) {
85 ret
= bte_copy(src
, pdst
, len
, mode
, notification
);
92 * XPC establishes channel connections between the local partition and any
93 * other partition that is currently up. Over these channels, kernel-level
94 * `users' can communicate with their counterparts on the other partitions.
96 * The maxinum number of channels is limited to eight. For performance reasons,
97 * the internal cross partition structures require sixteen bytes per channel,
98 * and eight allows all of this interface-shared info to fit in one cache line.
100 * XPC_NCHANNELS reflects the total number of channels currently defined.
101 * If the need for additional channels arises, one can simply increase
102 * XPC_NCHANNELS accordingly. If the day should come where that number
103 * exceeds the MAXIMUM number of channels allowed (eight), then one will need
104 * to make changes to the XPC code to allow for this.
106 #define XPC_MEM_CHANNEL 0 /* memory channel number */
107 #define XPC_NET_CHANNEL 1 /* network channel number */
109 #define XPC_NCHANNELS 2 /* #of defined channels */
110 #define XPC_MAX_NCHANNELS 8 /* max #of channels allowed */
112 #if XPC_NCHANNELS > XPC_MAX_NCHANNELS
113 #error XPC_NCHANNELS exceeds MAXIMUM allowed.
117 * The format of an XPC message is as follows:
119 * +-------+--------------------------------+
120 * | flags |////////////////////////////////|
121 * +-------+--------------------------------+
123 * +----------------------------------------+
124 * | payload (user-defined message) |
128 * +----------------------------------------+
130 * The size of the payload is defined by the user via xpc_connect(). A user-
131 * defined message resides in the payload area.
133 * The user should have no dealings with the message header, but only the
134 * message's payload. When a message entry is allocated (via xpc_allocate())
135 * a pointer to the payload area is returned and not the actual beginning of
136 * the XPC message. The user then constructs a message in the payload area
137 * and passes that pointer as an argument on xpc_send() or xpc_send_notify().
139 * The size of a message entry (within a message queue) must be a cacheline
140 * sized multiple in order to facilitate the BTE transfer of messages from one
141 * message queue to another. A macro, XPC_MSG_SIZE(), is provided for the user
142 * that wants to fit as many msg entries as possible in a given memory size
143 * (e.g. a memory page).
146 u8 flags
; /* FOR XPC INTERNAL USE ONLY */
147 u8 reserved
[7]; /* FOR XPC INTERNAL USE ONLY */
148 s64 number
; /* FOR XPC INTERNAL USE ONLY */
150 u64 payload
; /* user defined portion of message */
153 #define XPC_MSG_PAYLOAD_OFFSET (u64) (&((struct xpc_msg *)0)->payload)
154 #define XPC_MSG_SIZE(_payload_size) \
155 L1_CACHE_ALIGN(XPC_MSG_PAYLOAD_OFFSET + (_payload_size))
158 * Define the return values and values passed to user's callout functions.
159 * (It is important to add new value codes at the end just preceding
160 * xpcUnknownReason, which must have the highest numerical value.)
165 xpcNotConnected
, /* 1: channel is not connected */
166 xpcConnected
, /* 2: channel connected (opened) */
167 xpcRETIRED1
, /* 3: (formerly xpcDisconnected) */
169 xpcMsgReceived
, /* 4: message received */
170 xpcMsgDelivered
, /* 5: message delivered and acknowledged */
172 xpcRETIRED2
, /* 6: (formerly xpcTransferFailed) */
174 xpcNoWait
, /* 7: operation would require wait */
175 xpcRetry
, /* 8: retry operation */
176 xpcTimeout
, /* 9: timeout in xpc_allocate_msg_wait() */
177 xpcInterrupted
, /* 10: interrupted wait */
179 xpcUnequalMsgSizes
, /* 11: message size disparity between sides */
180 xpcInvalidAddress
, /* 12: invalid address */
182 xpcNoMemory
, /* 13: no memory available for XPC structures */
183 xpcLackOfResources
, /* 14: insufficient resources for operation */
184 xpcUnregistered
, /* 15: channel is not registered */
185 xpcAlreadyRegistered
, /* 16: channel is already registered */
187 xpcPartitionDown
, /* 17: remote partition is down */
188 xpcNotLoaded
, /* 18: XPC module is not loaded */
189 xpcUnloading
, /* 19: this side is unloading XPC module */
191 xpcBadMagic
, /* 20: XPC MAGIC string not found */
193 xpcReactivating
, /* 21: remote partition was reactivated */
195 xpcUnregistering
, /* 22: this side is unregistering channel */
196 xpcOtherUnregistering
, /* 23: other side is unregistering channel */
198 xpcCloneKThread
, /* 24: cloning kernel thread */
199 xpcCloneKThreadFailed
, /* 25: cloning kernel thread failed */
201 xpcNoHeartbeat
, /* 26: remote partition has no heartbeat */
203 xpcPioReadError
, /* 27: PIO read error */
204 xpcPhysAddrRegFailed
, /* 28: registration of phys addr range failed */
206 xpcBteDirectoryError
, /* 29: maps to BTEFAIL_DIR */
207 xpcBtePoisonError
, /* 30: maps to BTEFAIL_POISON */
208 xpcBteWriteError
, /* 31: maps to BTEFAIL_WERR */
209 xpcBteAccessError
, /* 32: maps to BTEFAIL_ACCESS */
210 xpcBtePWriteError
, /* 33: maps to BTEFAIL_PWERR */
211 xpcBtePReadError
, /* 34: maps to BTEFAIL_PRERR */
212 xpcBteTimeOutError
, /* 35: maps to BTEFAIL_TOUT */
213 xpcBteXtalkError
, /* 36: maps to BTEFAIL_XTERR */
214 xpcBteNotAvailable
, /* 37: maps to BTEFAIL_NOTAVAIL */
215 xpcBteUnmappedError
, /* 38: unmapped BTEFAIL_ error */
217 xpcBadVersion
, /* 39: bad version number */
218 xpcVarsNotSet
, /* 40: the XPC variables are not set up */
219 xpcNoRsvdPageAddr
, /* 41: unable to get rsvd page's phys addr */
220 xpcInvalidPartid
, /* 42: invalid partition ID */
221 xpcLocalPartid
, /* 43: local partition ID */
223 xpcOtherGoingDown
, /* 44: other side going down, reason unknown */
224 xpcSystemGoingDown
, /* 45: system is going down, reason unknown */
225 xpcSystemHalt
, /* 46: system is being halted */
226 xpcSystemReboot
, /* 47: system is being rebooted */
227 xpcSystemPoweroff
, /* 48: system is being powered off */
229 xpcDisconnecting
, /* 49: channel disconnecting (closing) */
231 xpcOpenCloseError
, /* 50: channel open/close protocol error */
233 xpcDisconnected
, /* 51: channel disconnected (closed) */
235 xpcBteSh2Start
, /* 52: BTE CRB timeout */
237 /* 53: 0x1 BTE Error Response Short */
238 xpcBteSh2RspShort
= xpcBteSh2Start
+ BTEFAIL_SH2_RESP_SHORT
,
240 /* 54: 0x2 BTE Error Response Long */
241 xpcBteSh2RspLong
= xpcBteSh2Start
+ BTEFAIL_SH2_RESP_LONG
,
243 /* 56: 0x4 BTE Error Response DSB */
244 xpcBteSh2RspDSB
= xpcBteSh2Start
+ BTEFAIL_SH2_RESP_DSP
,
246 /* 60: 0x8 BTE Error Response Access */
247 xpcBteSh2RspAccess
= xpcBteSh2Start
+ BTEFAIL_SH2_RESP_ACCESS
,
249 /* 68: 0x10 BTE Error CRB timeout */
250 xpcBteSh2CRBTO
= xpcBteSh2Start
+ BTEFAIL_SH2_CRB_TO
,
252 /* 84: 0x20 BTE Error NACK limit */
253 xpcBteSh2NACKLimit
= xpcBteSh2Start
+ BTEFAIL_SH2_NACK_LIMIT
,
256 xpcBteSh2End
= xpcBteSh2Start
+ BTEFAIL_SH2_ALL
,
258 xpcUnknownReason
/* 116: unknown reason - must be last in enum */
262 * Define the callout function types used by XPC to update the user on
263 * connection activity and state changes (via the user function registered by
264 * xpc_connect()) and to notify them of messages received and delivered (via
265 * the user function registered by xpc_send_notify()).
267 * The two function types are xpc_channel_func and xpc_notify_func and
268 * both share the following arguments, with the exception of "data", which
269 * only xpc_channel_func has.
273 * reason - reason code. (See following table.)
274 * partid - partition ID associated with condition.
275 * ch_number - channel # associated with condition.
276 * data - pointer to optional data. (See following table.)
277 * key - pointer to optional user-defined value provided as the "key"
278 * argument to xpc_connect() or xpc_send_notify().
280 * In the following table the "Optional Data" column applies to callouts made
281 * to functions registered by xpc_connect(). A "NA" in that column indicates
282 * that this reason code can be passed to functions registered by
283 * xpc_send_notify() (i.e. they don't have data arguments).
285 * Also, the first three reason codes in the following table indicate
286 * success, whereas the others indicate failure. When a failure reason code
287 * is received, one can assume that the channel is not connected.
290 * Reason Code | Cause | Optional Data
291 * =====================+================================+=====================
292 * xpcConnected | connection has been established| max #of entries
293 * | to the specified partition on | allowed in message
294 * | the specified channel | queue
295 * ---------------------+--------------------------------+---------------------
296 * xpcMsgReceived | an XPC message arrived from | address of payload
297 * | the specified partition on the |
298 * | specified channel | [the user must call
299 * | | xpc_received() when
300 * | | finished with the
302 * ---------------------+--------------------------------+---------------------
303 * xpcMsgDelivered | notification that the message | NA
304 * | was delivered to the intended |
305 * | recipient and that they have |
306 * | acknowledged its receipt by |
307 * | calling xpc_received() |
308 * =====================+================================+=====================
309 * xpcUnequalMsgSizes | can't connect to the specified | NULL
310 * | partition on the specified |
311 * | channel because of mismatched |
313 * ---------------------+--------------------------------+---------------------
314 * xpcNoMemory | insufficient memory avaiable | NULL
315 * | to allocate message queue |
316 * ---------------------+--------------------------------+---------------------
317 * xpcLackOfResources | lack of resources to create | NULL
318 * | the necessary kthreads to |
319 * | support the channel |
320 * ---------------------+--------------------------------+---------------------
321 * xpcUnregistering | this side's user has | NULL or NA
322 * | unregistered by calling |
323 * | xpc_disconnect() |
324 * ---------------------+--------------------------------+---------------------
325 * xpcOtherUnregistering| the other side's user has | NULL or NA
326 * | unregistered by calling |
327 * | xpc_disconnect() |
328 * ---------------------+--------------------------------+---------------------
329 * xpcNoHeartbeat | the other side's XPC is no | NULL or NA
330 * | longer heartbeating |
332 * ---------------------+--------------------------------+---------------------
333 * xpcUnloading | this side's XPC module is | NULL or NA
336 * ---------------------+--------------------------------+---------------------
337 * xpcOtherUnloading | the other side's XPC module is | NULL or NA
338 * | is being unloaded |
340 * ---------------------+--------------------------------+---------------------
341 * xpcPioReadError | xp_nofault_PIOR() returned an | NULL or NA
342 * | error while sending an IPI |
344 * ---------------------+--------------------------------+---------------------
345 * xpcInvalidAddress | the address either received or | NULL or NA
346 * | sent by the specified partition|
348 * ---------------------+--------------------------------+---------------------
349 * xpcBteNotAvailable | attempt to pull data from the | NULL or NA
350 * xpcBtePoisonError | specified partition over the |
351 * xpcBteWriteError | specified channel via a |
352 * xpcBteAccessError | bte_copy() failed |
353 * xpcBteTimeOutError | |
354 * xpcBteXtalkError | |
355 * xpcBteDirectoryError | |
356 * xpcBteGenericError | |
357 * xpcBteUnmappedError | |
358 * ---------------------+--------------------------------+---------------------
359 * xpcUnknownReason | the specified channel to the | NULL or NA
360 * | specified partition was |
361 * | unavailable for unknown reasons|
362 * =====================+================================+=====================
365 typedef void (*xpc_channel_func
) (enum xpc_retval reason
, partid_t partid
,
366 int ch_number
, void *data
, void *key
);
368 typedef void (*xpc_notify_func
) (enum xpc_retval reason
, partid_t partid
,
369 int ch_number
, void *key
);
372 * The following is a registration entry. There is a global array of these,
373 * one per channel. It is used to record the connection registration made
374 * by the users of XPC. As long as a registration entry exists, for any
375 * partition that comes up, XPC will attempt to establish a connection on
376 * that channel. Notification that a connection has been made will occur via
377 * the xpc_channel_func function.
379 * The 'func' field points to the function to call when aynchronous
380 * notification is required for such events as: a connection established/lost,
381 * or an incoming message received, or an error condition encountered. A
382 * non-NULL 'func' field indicates that there is an active registration for
385 struct xpc_registration
{
387 xpc_channel_func func
; /* function to call */
388 void *key
; /* pointer to user's key */
389 u16 nentries
; /* #of msg entries in local msg queue */
390 u16 msg_size
; /* message queue's message size */
391 u32 assigned_limit
; /* limit on #of assigned kthreads */
392 u32 idle_limit
; /* limit on #of idle kthreads */
393 } ____cacheline_aligned
;
395 #define XPC_CHANNEL_REGISTERED(_c) (xpc_registrations[_c].func != NULL)
397 /* the following are valid xpc_allocate() flags */
398 #define XPC_WAIT 0 /* wait flag */
399 #define XPC_NOWAIT 1 /* no wait flag */
401 struct xpc_interface
{
402 void (*connect
) (int);
403 void (*disconnect
) (int);
404 enum xpc_retval (*allocate
) (partid_t
, int, u32
, void **);
405 enum xpc_retval (*send
) (partid_t
, int, void *);
406 enum xpc_retval (*send_notify
) (partid_t
, int, void *,
407 xpc_notify_func
, void *);
408 void (*received
) (partid_t
, int, void *);
409 enum xpc_retval (*partid_to_nasids
) (partid_t
, void *);
412 extern struct xpc_interface xpc_interface
;
414 extern void xpc_set_interface(void (*)(int),
416 enum xpc_retval (*)(partid_t
, int, u32
, void **),
417 enum xpc_retval (*)(partid_t
, int, void *),
418 enum xpc_retval (*)(partid_t
, int, void *,
419 xpc_notify_func
, void *),
420 void (*)(partid_t
, int, void *),
421 enum xpc_retval (*)(partid_t
, void *));
422 extern void xpc_clear_interface(void);
424 extern enum xpc_retval
xpc_connect(int, xpc_channel_func
, void *, u16
,
426 extern void xpc_disconnect(int);
428 static inline enum xpc_retval
429 xpc_allocate(partid_t partid
, int ch_number
, u32 flags
, void **payload
)
431 return xpc_interface
.allocate(partid
, ch_number
, flags
, payload
);
434 static inline enum xpc_retval
435 xpc_send(partid_t partid
, int ch_number
, void *payload
)
437 return xpc_interface
.send(partid
, ch_number
, payload
);
440 static inline enum xpc_retval
441 xpc_send_notify(partid_t partid
, int ch_number
, void *payload
,
442 xpc_notify_func func
, void *key
)
444 return xpc_interface
.send_notify(partid
, ch_number
, payload
, func
, key
);
448 xpc_received(partid_t partid
, int ch_number
, void *payload
)
450 return xpc_interface
.received(partid
, ch_number
, payload
);
453 static inline enum xpc_retval
454 xpc_partid_to_nasids(partid_t partid
, void *nasids
)
456 return xpc_interface
.partid_to_nasids(partid
, nasids
);
459 extern u64 xp_nofault_PIOR_target
;
460 extern int xp_nofault_PIOR(void *);
461 extern int xp_error_PIOR(void);
463 #endif /* _DRIVERS_MISC_SGIXP_XP_H */