Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * (C) Copyright 2020 Hewlett Packard Enterprise Development LP
0007  * Copyright (C) 2004-2008 Silicon Graphics, Inc. All rights reserved.
0008  */
0009 
0010 /*
0011  * External Cross Partition (XP) structures and defines.
0012  */
0013 
0014 #ifndef _DRIVERS_MISC_SGIXP_XP_H
0015 #define _DRIVERS_MISC_SGIXP_XP_H
0016 
0017 #include <linux/mutex.h>
0018 
0019 #if defined CONFIG_X86_UV || defined CONFIG_IA64_SGI_UV
0020 #include <asm/uv/uv.h>
0021 #endif
0022 
0023 #ifdef USE_DBUG_ON
0024 #define DBUG_ON(condition)  BUG_ON(condition)
0025 #else
0026 #define DBUG_ON(condition)
0027 #endif
0028 
0029 /*
0030  * Define the maximum number of partitions the system can possibly support.
0031  * It is based on the maximum number of hardware partitionable regions. The
0032  * term 'region' in this context refers to the minimum number of nodes that
0033  * can comprise an access protection grouping. The access protection is in
0034  * regards to memory, IPI and IOI.
0035  *
0036  * The maximum number of hardware partitionable regions is equal to the
0037  * maximum number of nodes in the entire system divided by the minimum number
0038  * of nodes that comprise an access protection grouping.
0039  */
0040 #define XP_MAX_NPARTITIONS_SN2  64
0041 #define XP_MAX_NPARTITIONS_UV   256
0042 
0043 /*
0044  * XPC establishes channel connections between the local partition and any
0045  * other partition that is currently up. Over these channels, kernel-level
0046  * `users' can communicate with their counterparts on the other partitions.
0047  *
0048  * If the need for additional channels arises, one can simply increase
0049  * XPC_MAX_NCHANNELS accordingly. If the day should come where that number
0050  * exceeds the absolute MAXIMUM number of channels possible (eight), then one
0051  * will need to make changes to the XPC code to accommodate for this.
0052  *
0053  * The absolute maximum number of channels possible is limited to eight for
0054  * performance reasons on sn2 hardware. The internal cross partition structures
0055  * require sixteen bytes per channel, and eight allows all of this
0056  * interface-shared info to fit in one 128-byte cacheline.
0057  */
0058 #define XPC_MEM_CHANNEL     0   /* memory channel number */
0059 #define XPC_NET_CHANNEL     1   /* network channel number */
0060 
0061 #define XPC_MAX_NCHANNELS   2   /* max #of channels allowed */
0062 
0063 #if XPC_MAX_NCHANNELS > 8
0064 #error  XPC_MAX_NCHANNELS exceeds absolute MAXIMUM possible.
0065 #endif
0066 
0067 /*
0068  * Define macro, XPC_MSG_SIZE(), is provided for the user
0069  * that wants to fit as many msg entries as possible in a given memory size
0070  * (e.g. a memory page).
0071  */
0072 #define XPC_MSG_MAX_SIZE    128
0073 #define XPC_MSG_HDR_MAX_SIZE    16
0074 #define XPC_MSG_PAYLOAD_MAX_SIZE (XPC_MSG_MAX_SIZE - XPC_MSG_HDR_MAX_SIZE)
0075 
0076 #define XPC_MSG_SIZE(_payload_size) \
0077                 ALIGN(XPC_MSG_HDR_MAX_SIZE + (_payload_size), \
0078                       is_uv_system() ? 64 : 128)
0079 
0080 
0081 /*
0082  * Define the return values and values passed to user's callout functions.
0083  * (It is important to add new value codes at the end just preceding
0084  * xpUnknownReason, which must have the highest numerical value.)
0085  */
0086 enum xp_retval {
0087     xpSuccess = 0,
0088 
0089     xpNotConnected,     /*  1: channel is not connected */
0090     xpConnected,        /*  2: channel connected (opened) */
0091     xpRETIRED1,     /*  3: (formerly xpDisconnected) */
0092 
0093     xpMsgReceived,      /*  4: message received */
0094     xpMsgDelivered,     /*  5: message delivered and acknowledged */
0095 
0096     xpRETIRED2,     /*  6: (formerly xpTransferFailed) */
0097 
0098     xpNoWait,       /*  7: operation would require wait */
0099     xpRetry,        /*  8: retry operation */
0100     xpTimeout,      /*  9: timeout in xpc_allocate_msg_wait() */
0101     xpInterrupted,      /* 10: interrupted wait */
0102 
0103     xpUnequalMsgSizes,  /* 11: message size disparity between sides */
0104     xpInvalidAddress,   /* 12: invalid address */
0105 
0106     xpNoMemory,     /* 13: no memory available for XPC structures */
0107     xpLackOfResources,  /* 14: insufficient resources for operation */
0108     xpUnregistered,     /* 15: channel is not registered */
0109     xpAlreadyRegistered,    /* 16: channel is already registered */
0110 
0111     xpPartitionDown,    /* 17: remote partition is down */
0112     xpNotLoaded,        /* 18: XPC module is not loaded */
0113     xpUnloading,        /* 19: this side is unloading XPC module */
0114 
0115     xpBadMagic,     /* 20: XPC MAGIC string not found */
0116 
0117     xpReactivating,     /* 21: remote partition was reactivated */
0118 
0119     xpUnregistering,    /* 22: this side is unregistering channel */
0120     xpOtherUnregistering,   /* 23: other side is unregistering channel */
0121 
0122     xpCloneKThread,     /* 24: cloning kernel thread */
0123     xpCloneKThreadFailed,   /* 25: cloning kernel thread failed */
0124 
0125     xpNoHeartbeat,      /* 26: remote partition has no heartbeat */
0126 
0127     xpPioReadError,     /* 27: PIO read error */
0128     xpPhysAddrRegFailed,    /* 28: registration of phys addr range failed */
0129 
0130     xpRETIRED3,     /* 29: (formerly xpBteDirectoryError) */
0131     xpRETIRED4,     /* 30: (formerly xpBtePoisonError) */
0132     xpRETIRED5,     /* 31: (formerly xpBteWriteError) */
0133     xpRETIRED6,     /* 32: (formerly xpBteAccessError) */
0134     xpRETIRED7,     /* 33: (formerly xpBtePWriteError) */
0135     xpRETIRED8,     /* 34: (formerly xpBtePReadError) */
0136     xpRETIRED9,     /* 35: (formerly xpBteTimeOutError) */
0137     xpRETIRED10,        /* 36: (formerly xpBteXtalkError) */
0138     xpRETIRED11,        /* 37: (formerly xpBteNotAvailable) */
0139     xpRETIRED12,        /* 38: (formerly xpBteUnmappedError) */
0140 
0141     xpBadVersion,       /* 39: bad version number */
0142     xpVarsNotSet,       /* 40: the XPC variables are not set up */
0143     xpNoRsvdPageAddr,   /* 41: unable to get rsvd page's phys addr */
0144     xpInvalidPartid,    /* 42: invalid partition ID */
0145     xpLocalPartid,      /* 43: local partition ID */
0146 
0147     xpOtherGoingDown,   /* 44: other side going down, reason unknown */
0148     xpSystemGoingDown,  /* 45: system is going down, reason unknown */
0149     xpSystemHalt,       /* 46: system is being halted */
0150     xpSystemReboot,     /* 47: system is being rebooted */
0151     xpSystemPoweroff,   /* 48: system is being powered off */
0152 
0153     xpDisconnecting,    /* 49: channel disconnecting (closing) */
0154 
0155     xpOpenCloseError,   /* 50: channel open/close protocol error */
0156 
0157     xpDisconnected,     /* 51: channel disconnected (closed) */
0158 
0159     xpBteCopyError,     /* 52: bte_copy() returned error */
0160     xpSalError,     /* 53: sn SAL error */
0161     xpRsvdPageNotSet,   /* 54: the reserved page is not set up */
0162     xpPayloadTooBig,    /* 55: payload too large for message slot */
0163 
0164     xpUnsupported,      /* 56: unsupported functionality or resource */
0165     xpNeedMoreInfo,     /* 57: more info is needed by SAL */
0166 
0167     xpGruCopyError,     /* 58: gru_copy_gru() returned error */
0168     xpGruSendMqError,   /* 59: gru send message queue related error */
0169 
0170     xpBadChannelNumber, /* 60: invalid channel number */
0171     xpBadMsgType,       /* 61: invalid message type */
0172     xpBiosError,        /* 62: BIOS error */
0173 
0174     xpUnknownReason     /* 63: unknown reason - must be last in enum */
0175 };
0176 
0177 /*
0178  * Define the callout function type used by XPC to update the user on
0179  * connection activity and state changes via the user function registered
0180  * by xpc_connect().
0181  *
0182  * Arguments:
0183  *
0184  *  reason - reason code.
0185  *  partid - partition ID associated with condition.
0186  *  ch_number - channel # associated with condition.
0187  *  data - pointer to optional data.
0188  *  key - pointer to optional user-defined value provided as the "key"
0189  *        argument to xpc_connect().
0190  *
0191  * A reason code of xpConnected indicates that a connection has been
0192  * established to the specified partition on the specified channel. The data
0193  * argument indicates the max number of entries allowed in the message queue.
0194  *
0195  * A reason code of xpMsgReceived indicates that a XPC message arrived from
0196  * the specified partition on the specified channel. The data argument
0197  * specifies the address of the message's payload. The user must call
0198  * xpc_received() when finished with the payload.
0199  *
0200  * All other reason codes indicate failure. The data argmument is NULL.
0201  * When a failure reason code is received, one can assume that the channel
0202  * is not connected.
0203  */
0204 typedef void (*xpc_channel_func) (enum xp_retval reason, short partid,
0205                   int ch_number, void *data, void *key);
0206 
0207 /*
0208  * Define the callout function type used by XPC to notify the user of
0209  * messages received and delivered via the user function registered by
0210  * xpc_send_notify().
0211  *
0212  * Arguments:
0213  *
0214  *  reason - reason code.
0215  *  partid - partition ID associated with condition.
0216  *  ch_number - channel # associated with condition.
0217  *  key - pointer to optional user-defined value provided as the "key"
0218  *        argument to xpc_send_notify().
0219  *
0220  * A reason code of xpMsgDelivered indicates that the message was delivered
0221  * to the intended recipient and that they have acknowledged its receipt by
0222  * calling xpc_received().
0223  *
0224  * All other reason codes indicate failure.
0225  *
0226  * NOTE: The user defined function must be callable by an interrupt handler
0227  *       and thus cannot block.
0228  */
0229 typedef void (*xpc_notify_func) (enum xp_retval reason, short partid,
0230                  int ch_number, void *key);
0231 
0232 /*
0233  * The following is a registration entry. There is a global array of these,
0234  * one per channel. It is used to record the connection registration made
0235  * by the users of XPC. As long as a registration entry exists, for any
0236  * partition that comes up, XPC will attempt to establish a connection on
0237  * that channel. Notification that a connection has been made will occur via
0238  * the xpc_channel_func function.
0239  *
0240  * The 'func' field points to the function to call when aynchronous
0241  * notification is required for such events as: a connection established/lost,
0242  * or an incoming message received, or an error condition encountered. A
0243  * non-NULL 'func' field indicates that there is an active registration for
0244  * the channel.
0245  */
0246 struct xpc_registration {
0247     struct mutex mutex;
0248     xpc_channel_func func;  /* function to call */
0249     void *key;      /* pointer to user's key */
0250     u16 nentries;       /* #of msg entries in local msg queue */
0251     u16 entry_size;     /* message queue's message entry size */
0252     u32 assigned_limit; /* limit on #of assigned kthreads */
0253     u32 idle_limit;     /* limit on #of idle kthreads */
0254 } ____cacheline_aligned;
0255 
0256 #define XPC_CHANNEL_REGISTERED(_c)  (xpc_registrations[_c].func != NULL)
0257 
0258 /* the following are valid xpc_send() or xpc_send_notify() flags */
0259 #define XPC_WAIT    0   /* wait flag */
0260 #define XPC_NOWAIT  1   /* no wait flag */
0261 
0262 struct xpc_interface {
0263     void (*connect) (int);
0264     void (*disconnect) (int);
0265     enum xp_retval (*send) (short, int, u32, void *, u16);
0266     enum xp_retval (*send_notify) (short, int, u32, void *, u16,
0267                     xpc_notify_func, void *);
0268     void (*received) (short, int, void *);
0269     enum xp_retval (*partid_to_nasids) (short, void *);
0270 };
0271 
0272 extern struct xpc_interface xpc_interface;
0273 
0274 extern void xpc_set_interface(void (*)(int),
0275                   void (*)(int),
0276                   enum xp_retval (*)(short, int, u32, void *, u16),
0277                   enum xp_retval (*)(short, int, u32, void *, u16,
0278                          xpc_notify_func, void *),
0279                   void (*)(short, int, void *),
0280                   enum xp_retval (*)(short, void *));
0281 extern void xpc_clear_interface(void);
0282 
0283 extern enum xp_retval xpc_connect(int, xpc_channel_func, void *, u16,
0284                    u16, u32, u32);
0285 extern void xpc_disconnect(int);
0286 
0287 static inline enum xp_retval
0288 xpc_send(short partid, int ch_number, u32 flags, void *payload,
0289      u16 payload_size)
0290 {
0291     if (!xpc_interface.send)
0292         return xpNotLoaded;
0293 
0294     return xpc_interface.send(partid, ch_number, flags, payload,
0295                   payload_size);
0296 }
0297 
0298 static inline enum xp_retval
0299 xpc_send_notify(short partid, int ch_number, u32 flags, void *payload,
0300         u16 payload_size, xpc_notify_func func, void *key)
0301 {
0302     if (!xpc_interface.send_notify)
0303         return xpNotLoaded;
0304 
0305     return xpc_interface.send_notify(partid, ch_number, flags, payload,
0306                      payload_size, func, key);
0307 }
0308 
0309 static inline void
0310 xpc_received(short partid, int ch_number, void *payload)
0311 {
0312     if (xpc_interface.received)
0313         xpc_interface.received(partid, ch_number, payload);
0314 }
0315 
0316 static inline enum xp_retval
0317 xpc_partid_to_nasids(short partid, void *nasids)
0318 {
0319     if (!xpc_interface.partid_to_nasids)
0320         return xpNotLoaded;
0321 
0322     return xpc_interface.partid_to_nasids(partid, nasids);
0323 }
0324 
0325 extern short xp_max_npartitions;
0326 extern short xp_partition_id;
0327 extern u8 xp_region_size;
0328 
0329 extern unsigned long (*xp_pa) (void *);
0330 extern unsigned long (*xp_socket_pa) (unsigned long);
0331 extern enum xp_retval (*xp_remote_memcpy) (unsigned long, const unsigned long,
0332                size_t);
0333 extern int (*xp_cpu_to_nasid) (int);
0334 extern enum xp_retval (*xp_expand_memprotect) (unsigned long, unsigned long);
0335 extern enum xp_retval (*xp_restrict_memprotect) (unsigned long, unsigned long);
0336 
0337 extern u64 xp_nofault_PIOR_target;
0338 extern int xp_nofault_PIOR(void *);
0339 extern int xp_error_PIOR(void);
0340 
0341 extern struct device *xp;
0342 extern enum xp_retval xp_init_uv(void);
0343 extern void xp_exit_uv(void);
0344 
0345 #endif /* _DRIVERS_MISC_SGIXP_XP_H */