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