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