/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/sys/ras.h 1.51.1.6                               */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2004,2019              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)12	1.51.1.6  src/bos/kernel/sys/ras.h, sysras, bos72Q, q2019_13A4 2/6/19 00:42:56 */
/*
 * COMPONENT_NAME: (sysras) RAS Component Infrastructure
 *
 * FUNCTIONS: 
 *
 * ORIGINS: 27
 */

#ifndef _H_SYSRAS
#define _H_SYSRAS

#include <sys/ras_base.h>
#include <sys/eyec.h>
#include <sys/kerrno.h>
#include <sys/types.h>
#include <sys/limits.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/* RAS_FILE_ASSERT is meant for sanity checks of basic structures.  If
 * there's a problem, the compiler will complain about a negative
 * array size on the line with the failing assert.
 */
#define RAS_FILE_ASSERT(id,test)				\
	struct CoMpIlE_aSsErT__##id { char v[(test) ? 1 : -1]; }

#ifdef __64BIT__
#define RAS_FIELD_CHECK(__struct, __field, __pos32, __pos64) \
	RAS_FILE_ASSERT(__field, offsetof(__struct, __field) \
					== __pos64)
#else
#define RAS_FIELD_CHECK(__struct, __field, __pos32, __pos64) \
	RAS_FILE_ASSERT(__field, offsetof(__struct, __field) \
					== __pos32)
#endif

/* RAS_COMMAND_CHECK verifies that __cmd is a valid command
 * and has value __val. The main purpose for this is to be defensive
 * and ensure binary compatability, but this also means that one can
 * search for the hex version of the command in /usr/include/sys and
 * find it.
 */
#define RAS_COMMAND_CHECK(__cmd, __val) \
	RAS_FILE_ASSERT( RAS_COMMAND_ ## __cmd, __cmd == __val )

/* ras_block_t is the only thing anyone outside of RAS should really
 * care about.
 */
typedef void *ras_block_t;

/* Type for a dump level */
typedef short   dmp_lvl_t;

/*
 * All kernel structures or fields added in this following structure
 * must be visible under the _RAS_INTERNAL flag.
 * It may break the compilation of some binaries (trcdead, ...) otherwise.
 */

#if (defined _RAS_INTERNAL) || (defined _KERNEL)
/* rasr_block_t is not meant to be used directly. If you need to
 * access one of these fields, use one of the read-only macros below.
 * It is a bug for any code outside of this .h to use the rasr_block_t
 * type.
 *
 * Any additions to the rasr_block_t should be at the end. This
 * structure must maintain binary compatibility, so care should be
 * taken if a field is no longer going to be used (like putting in a
 * dummy default value).
 *
 * Additions to this structure should also be made to RAS_BLOCK_NULL.
 */
struct rasr_block
{
	eye_catch_t	rrb_eyec;
	long		rrb_private;

        /* 
	 * Component Trace Domain properties
	 *  
	 * WARNING: Do not change this structure without updating 
	 *	    ml/POWER/ras_trace.m4.
	 */
			/* Encoded pointer to private trace block */
	long		rrb_trace_private;
			/* The current level of trace for private buffer */
	short		rrb_trace_privlevel;
			/* The current level of trace for system trace mode */
	short		rrb_trace_syslevel;            
			/* = max(rrb_trace_memlevel, rrb_trace_syslevel) */
	short		rrb_trace_level_summary;       
			/* The current level of trace for memory trace mode */
	short		rrb_trace_memlevel;            
					   
	/* 
	 * Error checking domain properties 
	 */
	short		rrb_errchecklevel;
	short		rrb_errlowsev_disp;
	short		rrb_errmedsev_disp;
	short		rrb_pad2;
	/*
	 * Dump domain properties.
	 * sdmp_lvl and ldmp_lvl are -1 if the component is enabled for dump.
	 */
	dmp_lvl_t	rrb_sdmp_lvl;	/* system dump detail level */
	dmp_lvl_t	rrb_ldmp_lvl;	/* live dump detail level */
	short		rrb_pad3[2];
#ifdef __64BIT__
	long		rrb_reserved[6];
#else
	long		rrb_reserved[4];
#endif
};

typedef struct rasr_block rasr_block_t;

/* Macros to retrieve rasr_block_t values, and compiler asserts to keep the
 * fields in the same place, for binary compatibility.
 */
#define rasrb_eyec(__rasb)	(((const rasr_block_t *)(__rasb))->rrb_eyec)
/* Note: the private field is intrinsically private, so no field
 * access macro is defined for it here.
 */

RAS_FIELD_CHECK(rasr_block_t, rrb_eyec, 0, 0);
RAS_FIELD_CHECK(rasr_block_t, rrb_private, 4, 8);

#endif	/* _RAS_INTERNAL || _KERNEL */

/* Constants: */

/* Limits: */
#define	RAS_NAME_MAX	64
#define RAS_DESC_MAX	256
#define RAS_PATH_MAX	1024

/* Domains: */

/* Define the "domains" that interact with the RAS infrastructure.
 * RASD_FIRST <= domain < RASD_LAST
 *
 * Any field or code using a domain should assume this enum goes to
 * 0xF (RASD_LIMIT defined below), in case more domains are added
 * later.
 */
#define RASD_FIRST 	1

enum ras_domain
{
	RASD_TRACE=RASD_FIRST,
	RASD_ERROR,
	RASD_DUMP,
	RASD_LAST
};

#define RASD_LIMIT	0x10

typedef enum ras_domain ras_domain_t;

RAS_FILE_ASSERT( toomanydomains, RASD_LAST < RASD_LIMIT );

/* Anyone using RASD_TO_RASD_FLAG should reserve 2 bytes (16 bits) for
 * domain flags, for extensibility. This gives room to add several
 * more domains.
 */
#define RASD_TO_INDEX(__domain)		( (__domain) - RASD_FIRST )
#define RASD_TO_RASD_FLAG(__domain)	( 1 << RASD_TO_INDEX(__domain) )
#define RASD_FLAG_MASK			0xFFFF

#define RASD_DOMAINS			(RASD_LAST - RASD_FIRST)


/* rascntl / ras_control / ras_callback command structure.
 *
 * The 64-bit ras_control command is formated as follows:
 *	EE00000FFFFCCCDD
 * where EE is an eye catcher, DD is the domain, CCC is a domain-specific command,
 * and FFFF is flags.  The remaining bits are reserved for future use.
 * Macros are provided to extract some of the fields.
 */

/* Command flags:
   NOCALLBACK is ored with the command paramter of RASC_COMMAND().
 */
#define	NOCALLBACK		0x010000ULL /* avoid calling callback */

/* Other command flags to be ored with the result of RASC_COMMAND() */
#define RAS_BUFFER		0x02000000ULL /* Multiple vals passed in buf. */
#define	RAS_PERSIST		0x00800000ULL /* Persistent call */

/* The following flags are generally used with RAS_PERSIST.. */
#define RAS_RUP			0x10000000ULL /* Recursive up */
#define RAS_RDOWN		0x20000000ULL /* Recursive down */
#define RAS_DELETE		0x40000000ULL /* Delete attribute */
#define	RAS_QUERY		0x80000000ULL /* Query attrribute */
/* #define RAS_...		0x00200000ULL *//* RESERVED for kernel */
/* #define RAS_...		0x00400000ULL *//* RESERVED for kernel */


/* Specify selector type in command. */
#define RAS_SELECTOR_MASK	0x0C000000ULL
#define RAS_SELECTOR_COMPONENT	0x04000000ULL
#define RAS_SELECTOR_TYPE	0x08000000ULL
#define RAS_SELECTOR_ALIAS	0x0C000000ULL

typedef unsigned long long ras_cmd_t;

#define RASC_HIGHBYTE_SHIFT	((sizeof(ras_cmd_t)-1) * 8 )
#define RASC_FLAGS_SHIFT	20	/* Shift amount to put flags in low-order
					 * bits.
					 */
#define RASC_LOWBYTE_MASK	((ras_cmd_t)0xFF )
#define RASC_HIGHBYTE_MASK	( RASC_LOWBYTE_MASK << RASC_HIGHBYTE_SHIFT )
#define RASC_DCOMMAND_MASK	0xFFF
#define RASC_GET_DOMAIN(__cmd)	((ras_cmd_t)(__cmd) & RASC_LOWBYTE_MASK )
#define RASC_GET_COMMAND(__cmd)	(((ras_cmd_t)(__cmd)&~(RASC_HIGHBYTE_MASK))>>8)
#define RASC_GET_DCOMMAND(__cmd) ((((ras_cmd_t)(__cmd))>>8)&RASC_DCOMMAND_MASK)
#define RASC_GET_EYEC(__cmd)	((ras_cmd_t)(__cmd) & RASC_HIGHBYTE_MASK )
#define RASC_EYEC_BYTE		0x52
#define RASC_EYEC	((ras_cmd_t)RASC_EYEC_BYTE << RASC_HIGHBYTE_SHIFT )

/* A macro to help define commands. Note: If __cmd or __dom are too
 * large, this macro will result in a -1L, which won't pass the eye
 * catcher checks in ras_control. This is intentional, since it's a
 * bad command.
 */
#define RASC_COMMAND_BADARGS(__dom, __cmd)	\
	( (((__cmd) << 8) & RASC_HIGHBYTE_MASK)	\
	  || ((__cmd) == 0) 			\
	  || ((__dom) & ~RASC_LOWBYTE_MASK) )

#define RASC_COMMAND(__dom, __cmd)					\
	( (RASC_EYEC							\
	   | ((ras_cmd_t)(__cmd) << 8)					\
	   | ((ras_cmd_t)(__dom)) )					\
	  | ( RASC_COMMAND_BADARGS((ras_cmd_t)(__dom),			\
				   (ras_cmd_t)(__cmd)) ? -1LL : 0) )

RAS_FILE_ASSERT( baddomain, RASC_COMMAND(0x100, 0x1) == -1LL );
RAS_FILE_ASSERT( badcmd,    RASC_COMMAND(0x1,   -1)  == -1LL );

/* Infrastructure ras_control/rascntl commands/domains: */

#define RASC_DOMAIN_GENERAL	0x10
#define RASC_DOMAIN_PATH	0x20	/* Understood by rascntl
					 * or ras_path_control only */

/* Commands understood by the infrastructure: */

/* General domain, works on both ras_block_t's and paths */
#define RASC_LOGICAL_ALIAS		RASC_COMMAND(RASC_DOMAIN_GENERAL, 0x1)
#define RASC_BLOCK_TO_FULL_PATH		RASC_COMMAND(RASC_DOMAIN_GENERAL, 0x2)
#define RASC_STAT_COMPONENT		RASC_COMMAND(RASC_DOMAIN_GENERAL, 0x3)
#define RASC_QUERY_PARMS		RASC_COMMAND(RASC_DOMAIN_GENERAL, 0x4)

/* Path domain, works ony for rascntl / ras_path_control */
#define RASC_ALIAS_TO_FULL_PATH		RASC_COMMAND(RASC_DOMAIN_PATH, 0x1)
#define RASC_LIST_COMPONENTS		RASC_COMMAND(RASC_DOMAIN_PATH, 0x2)
#define RASC_LIST_ALIASES		RASC_COMMAND(RASC_DOMAIN_PATH, 0x3)
#define RASC_LIST_COMPONENTS_BY_PATTERN	RASC_COMMAND(RASC_DOMAIN_PATH, 0x4)
#define RASC_LIST_ALIASES_BY_PATTERN	RASC_COMMAND(RASC_DOMAIN_PATH, 0x5)

RAS_COMMAND_CHECK(RASC_LOGICAL_ALIAS,		0x5200000000000110ull);
RAS_COMMAND_CHECK(RASC_BLOCK_TO_FULL_PATH,	0x5200000000000210ull);
RAS_COMMAND_CHECK(RASC_STAT_COMPONENT, 		0x5200000000000310ull);
RAS_COMMAND_CHECK(RASC_QUERY_PARMS,  		0x5200000000000410ull);
RAS_COMMAND_CHECK(RASC_ALIAS_TO_FULL_PATH, 	0x5200000000000120ull);
RAS_COMMAND_CHECK(RASC_LIST_COMPONENTS,		0x5200000000000220ull);
RAS_COMMAND_CHECK(RASC_LIST_ALIASES,		0x5200000000000320ull);

/* Eye-catcher for struct ras_stat: */ 
#define EYEC_RAS_STAT	__EYEC4('s','t','R','a')		/* stRa */

/* RASC_STAT_COMPONENT structure: */

/* Each domain is given 128 bytes in the stat structure as an opaque
 * section of memory for the domain to do with what it wishes. The
 * RASC_STAT_DOMAIN macro below should be used to access the domain-
 * specific section in a typed manner.
 */
typedef int ras_stat_domain_t[32];

struct ras_stat
{
	int rstat_eyec;
	int rstat_flags;
	
	char rstat_name[RAS_NAME_MAX];
	char rstat_desc[RAS_DESC_MAX];

	ras_type_t rstat_typesubtype;
	
	int rstat_reserved[8];

	ras_stat_domain_t rstat_domain[RASD_DOMAINS];
};
typedef struct ras_stat ras_stat_t; 

/* Structure for querying presistent customizations. */
struct ras_pstat
{
    ras_cmd_t	rpstat_cmd_flags;	/* For selector type and recursion flags.
					 * Eye-catcher is required for validation.
					 */
    short	rpstat_selector_offset;	/* Offset in structure to _rpstat_selector.
					*/
    short	rpstat_domain;
    short	rpstat_selector_length;
    char	rpstat_flags;
#define RAS_PSTAT_EXT 0x40		/* Pass-through attributes follow
					 * domain-specific info.
					 */
    char	_rpstat_pad;

    /* Structure can be extended here */

    char	_rpstat_selector[RAS_PATH_MAX];
};
typedef struct ras_pstat ras_pstat_t; 

/* ras_register / RASC_STAT_COMPONENT / RASC_LIST_COMPONENTS flags:
 */

#define RASF_TRACE_AWARE		RASD_TO_RASD_FLAG(RASD_TRACE)
#define RASF_ERROR_AWARE		RASD_TO_RASD_FLAG(RASD_ERROR)
#define RASF_DUMP_AWARE			RASD_TO_RASD_FLAG(RASD_DUMP)

/* RASF_REGISTER_FLAGS - Valid ras_register flags: */
#define RASF_REGISTER_FLAGS	\
	(RASF_TRACE_AWARE | RASF_ERROR_AWARE | RASF_DUMP_AWARE)

/* STAT / LIST only: */
#define RASF_ISALIAS			0x10000
#define RASF_HASCHILD			0x20000

/* RASC_STAT_DOMAIN: Get domain specific info from ras_stat_t buffer.
 *
 * Example: RASC_STAT_DOMAIN(statbuf, RASD_TRACE, rstat_trace_t *)
 */

#define RASC_STAT_DOMAIN(__rs, __dom, __type) \
	((__type)&((__rs)->rstat_domain[RASD_TO_INDEX(__dom)]))

/*
 * Eye-catchers for struct ras_pathent
 */
#define EYEC_RAS_PATHENT	__EYEC4('p','a','R','a')	/* paRa */
#define EYEC_RAS_PATHENT_LAST	__EYEC4('p','a','R','f')	/* paRf */

/* RASC_LIST_COMPONENTS structure: */
struct ras_pathent
{
	int rpent_eyec; /* eyec must stay first */
	int rpent_flags;
	ras_type_t rpent_typesubtype;
	int rpent_reserved[7];
	char rpent_name[RAS_NAME_MAX];
	char rpent_desc[RAS_DESC_MAX];
};

typedef struct ras_pathent ras_pathent_t;

/* The code relies on rpent_eyec being in position 0, so make sure. */
RAS_FIELD_CHECK(ras_pathent_t, rpent_eyec, 0, 0);

/*
 * Definition of an arg parameter of type that may be passed to ras_callback()
 * (component callback) function for certain RAS commands. This structure is
 * size invariant between 32-bit and 64-bit user and kernel space.
 */
typedef struct ras_arg
{
	eye_catch8b_t		arg_eyec;	/* eye catcher for this data */
	unsigned long long	argptr;		/* pointer to arg data	*/
	long long		argsize;	/* size of arg data	*/

} ras_arg_t;


/*
 * Kerrnos returned by interfaces declared in this file
 */

/* 
 * ras_callback service 
 */
#define	EINVAL_RAS_CALLBACK_PARAM	KERROR(EINVAL, sysras_BLOCK_00, 1)
#define	EINVAL_RAS_CALLBACK_UNKNOWN	KERROR(EINVAL, sysras_BLOCK_00, 2)
#define	EINVAL_RAS_CALLBACK_NOTSUPP	KERROR(EINVAL, sysras_BLOCK_00, 3)
#define	ENODEV_RAS_CALLBACK_SCRUBOFF	KERROR(ENODEV, sysras_BLOCK_00, 4)
#define	ENOMEM_RAS_CALLBACK_BUF2SML	KERROR(ENOMEM, sysras_BLOCK_00, 5)

/* 
 * ras_control service
 */
#define	EINVAL_RAS_CONTROL_PARAM	KERROR(EINVAL, sysras_BLOCK_00, 6)
#define	EINVAL_RAS_CONTROL_UNKNOWN	KERROR(EINVAL, sysras_BLOCK_00, 7)
#define	EINVAL_RAS_CONTROL_NOTSUPP	KERROR(EINVAL, sysras_BLOCK_00, 8)
#define	ENOMEM_RAS_CONTROL_BUF2SML	KERROR(ENOMEM, sysras_BLOCK_00, 9)
#define	EINVAL_RAS_CONTROL_NULLRASB	KERROR(EINVAL, sysras_BLOCK_00, 82)
#define	EINVAL_RAS_CONTROL_BADCMD	KERROR(EINVAL, sysras_BLOCK_00, 83)
#define	EINVAL_RAS_CONTROL_BADARGS	KERROR(EINVAL, sysras_BLOCK_00, 84)
#define	EINVAL_RAS_CONTROL_BADDOM	KERROR(EINVAL, sysras_BLOCK_00, 85)
#define	EINVAL_RAS_CONTROL_PATHNULL	KERROR(EINVAL, sysras_BLOCK_00, 86)
#define	EINVAL_RAS_CONTROL_PATHNONNULL	KERROR(EINVAL, sysras_BLOCK_00, 87)
#define	EINVAL_RAS_CONTROL_QUERYPARMS	KERROR(EINVAL, sysras_BLOCK_00, 102)
#define	EFAULT_RAS_CONTROL_QUERYPARMS	KERROR(EFAULT, sysras_BLOCK_00, 103)
#define	ENOMEM_RAS_CONTROL_QUERYPARMS	KERROR(ENOMEM, sysras_BLOCK_00, 104)
#define EPERM_RAS_CONTROL_INTPRI	KERROR(EPERM, sysras_BLOCK_00, 105)

/*
 * RAS infrastructure errors (ras_register, etc.)
 */
#define	EIDRM_RASP_CROSSCHECK		KERROR(EIDRM, sysras_BLOCK_00, 52)
#define	EIDRM_RASR_EYECATCH_R		KERROR(EIDRM, sysras_BLOCK_00, 53)
#define	EIDRM_RASR_EYECATCH_P		KERROR(EIDRM, sysras_BLOCK_00, 54)
#define	EIDRM_RASP_EYECATCH_R		KERROR(EIDRM, sysras_BLOCK_00, 55)
#define	EIDRM_RASP_EYECATCH_P		KERROR(EIDRM, sysras_BLOCK_00, 56)
#define	EPERM_RAS_INTPRI		KERROR(EPERM, sysras_BLOCK_00, 57)
#define	EINVAL_RAS_REG_RASBP		KERROR(EINVAL, sysras_BLOCK_00, 58)
#define	EINVAL_RAS_REG_NAMENULL		KERROR(EINVAL, sysras_BLOCK_00, 59)
#define	EINVAL_RAS_REG_NAMETOOLONG	KERROR(EINVAL, sysras_BLOCK_00, 60)
#define	EINVAL_RAS_REG_NAMEBAD		KERROR(EINVAL, sysras_BLOCK_00, 61)
#define	EINVAL_RAS_REG_NAMEEMPTY	KERROR(EINVAL, sysras_BLOCK_00, 62)
#define	EINVAL_RAS_REG_DESCNULL		KERROR(EINVAL, sysras_BLOCK_00, 63)
#define	EINVAL_RAS_REG_DESCTOOLONG	KERROR(EINVAL, sysras_BLOCK_00, 64)
#define	EINVAL_RAS_REG_BADFLAGS		KERROR(EINVAL, sysras_BLOCK_00, 65)
#define	EINVAL_RAS_REG_NULLCALL		KERROR(EINVAL, sysras_BLOCK_00, 66)
#define	EINVAL_RAS_REG_PATHTOOLONG	KERROR(EINVAL, sysras_BLOCK_00, 67)
#define	EINVAL_RAS_REG_CHILDTYPE	KERROR(EINVAL, sysras_BLOCK_00, 68)
#define	EINVAL_RAS_REG_PARENTTYPE	KERROR(EINVAL, sysras_BLOCK_00, 69)
#define	EEXIST_RAS_REG_NAMEFOUND	KERROR(EEXIST, sysras_BLOCK_00, 70)

#define	EINVAL_RAS_REG_WDEV_NAMETOOLONG	KERROR(EINVAL, sysras_BLOCK_00, 248)
#define ENXIO_RAS_REG_KWPARDEVV2RNAME   KERROR(ENXIO, sysras_BLOCK_00, 249)
#define EPERM_RAS_REG_KWPARDEVV2RNAME   KERROR(EPERM, sysras_BLOCK_00, 250)
#define EINVAL_RAS_REG_KWPARDEVV2RNAME  KERROR(EINVAL, sysras_BLOCK_00, 251)

#define	EEXIST_RAS_UNREG_STILLPARENT	KERROR(EEXIST, sysras_BLOCK_00, 71)
#define	EINVAL_RAS_LOOKUP_PATHTOOLONG	KERROR(EINVAL, sysras_BLOCK_00, 72)
#define	EINVAL_RAS_LOOKUP_EMPTYPATH	KERROR(EINVAL, sysras_BLOCK_00, 73)
#define	ENOENT_RAS_LOOKUP_EMPTYNODE	KERROR(ENOENT, sysras_BLOCK_00, 74)
#define	ENOENT_RAS_LOOKUP_NOTFOUND	KERROR(ENOENT, sysras_BLOCK_00, 75)
#define	EALREADY_RAS_MAKE_ALIAS		KERROR(EALREADY, sysras_BLOCK_00, 76)
#define	ENOENT_RAS_ALIAS_NOTFOUND	KERROR(ENOENT, sysras_BLOCK_00, 77)
#define	ENOMEM_RAS_CONSTRUCT		KERROR(ENOMEM, sysras_BLOCK_00, 78)
#define	ENOMEM_RAS_DOMAIN_CONSTRUCT	KERROR(ENOMEM, sysras_BLOCK_00, 79)
#define	EINVAL_RAS_CALLBACK		KERROR(EINVAL, sysras_BLOCK_00, 80)
#define	EMLINK_RAS_APPLY_TOODEEP	KERROR(EMLINK, sysras_BLOCK_00, 81)
#define	EPERM_RAS_MAKE_ALIAS		KERROR(EPERM, sysras_BLOCK_00, 82)
#define	EINVAL_RAS_STAT_BADLEN		KERROR(EINVAL, sysras_BLOCK_00, 88)
#define	ENOMEM_RAS_COPYOUT_TOOSHORT	KERROR(ENOMEM, sysras_BLOCK_00, 89)
#define	EACCES_RAS_CONTROL_NOTROOT	KERROR(EACCES, sysras_BLOCK_00, 90)
#define	EINVAL_RAS_TRACE_BADARGS	KERROR(EINVAL, sysras_BLOCK_00, 91)
#define	EBUSY_RAS_TRACE_OPINPROGRESS	KERROR(EBUSY, sysras_BLOCK_00, 92)
#define	EINVAL_RAS_TRACE_NOBUF		KERROR(EINVAL, sysras_BLOCK_00, 93)
#define	ENOMEM_RAS_TRACE_RASCT_PASS	KERROR(ENOMEM, sysras_BLOCK_00, 94)
#define	EINVAL_RAS_TRACE_BADLEVEL	KERROR(EINVAL, sysras_BLOCK_00, 95)
#define	EINVAL_RAS_TRACE_BADSIZE	KERROR(EINVAL, sysras_BLOCK_00, 96)
#define	ENOMEM_RAS_TRACE_TOO_MUCH	KERROR(ENOMEM, sysras_BLOCK_00, 97)
#define	EINVAL_RAS_TRACE_NOT_CUSTOMIZED	KERROR(EINVAL, sysras_BLOCK_00, 98)
#define	ENOMEM_RAS_TRACE_BUFTOOSMALL	KERROR(ENOMEM, sysras_BLOCK_00, 99)
#define	ENOMEM_RAS_TRACE_ALLOCBUF	KERROR(ENOMEM, sysras_BLOCK_00, 100)
#define	ENOMEM_RAS_TRACE_BUFRESIZE	KERROR(ENOMEM, sysras_BLOCK_00, 101)
#define EPERM_RAS_TRACE_STATIC          KERROR(EPERM, sysras_BLOCK_00, 150)
#define EINVAL_RAS_REG_BADPARENT        KERROR(EINVAL, sysras_BLOCK_00, 151)
#define ENOMEM_RAS_TRACE_ADDCPU         KERROR(ENOMEM, sysras_BLOCK_00, 152)
#define ERANGE_RAS_TRACE_GALLOC         KERROR(ERANGE, sysras_BLOCK_00, 153)

#define	EINVAL_RAS_LDMP_BADARGS KERROR(EINVAL, sysras_BLOCK_00, 130)
#define	ENOMEM_RAS_DMP_PASS_THROUGH KERROR(ENOMEM, sysras_BLOCK_00, 131)
#define	EFAULT_RAS_DMP_PASS_THROUGH KERROR(EFAULT, sysras_BLOCK_00, 132)
#define	ENOMEM_RAS_LDMP_ESTIMATE KERROR(ENOMEM, sysras_BLOCK_00, 133)
#define	EFAULT_RAS_LDMP_ESTIMATE KERROR(EFAULT, sysras_BLOCK_00, 134)

#define	EINVAL_RAS_DUMP_UNAWARE KERROR(EINVAL, sysras_BLOCK_00, 140)

#define EINVAL_RAS_SDMP_BADMDT		KERROR(EINVAL, sysras_BLOCK_00, 160)
#define EINVAL_RAS_SDMP_BADARGS		KERROR(EINVAL, sysras_BLOCK_00, 161)
#define EFAULT_RAS_SDMP_ESTIMATE	KERROR(EFAULT, sysras_BLOCK_00, 162)
#define ENOMEM_RAS_SDMP_ESTIMATE        KERROR(ENOMEM, sysras_BLOCK_00, 163)
#define ENOMEM_RAS_SDMP_STAGING 	KERROR(ENOMEM, sysras_BLOCK_00, 164)
#define EINVAL_RAS_SDMP_STAGING		KERROR(EINVAL, sysras_BLOCK_00, 165)
#define EINVAL_RAS_SDMP_CALLRESTART	KERROR(EINVAL, sysras_BLOCK_00, 166)
#define EFAULT_RAS_SDMP_DMPCTLADD	KERROR(EFAULT, sysras_BLOCK_00, 167)	
#define	EINVAL_RAS_SDMP_INVOFF		KERROR(EINVAL, sysras_BLOCK_00, 168)

#define ENOMEM_RAS_PERSIST		KERROR(ENOMEM, sysras_BLOCK_00, 169)
#define EINVAL_RAS_CONTROL_PERSISTENT	KERROR(EINVAL, sysras_BLOCK_00, 170)
#define EINVAL_RAS_PERSISTENT_DOMAIN	KERROR(EINVAL, sysras_BLOCK_00, 171)

#define EBADF_RAS_UPDATE_P		KERROR(EBADF,  sysras_BLOCK_00, 172)
#define EIDRM_RASP_PC_EYECATCH_GET	KERROR(EIDRM,  sysras_BLOCK_00, 173)
#define EIDRM_RASP_PC_EYECATCH_PUT	KERROR(EIDRM,  sysras_BLOCK_00, 174)
#define EINVAL_RASP_RDOWN		KERROR(EINVAL, sysras_BLOCK_00, 175)
#define EINVAL_RAS_PERSIST_PATHNULL	KERROR(EINVAL, sysras_BLOCK_00, 176)
#define EMLINK_RAS_PERSIST		KERROR(EMLINK, sysras_BLOCK_00, 177)
#define ENOENT_RAS_UPDATE_P		KERROR(ENOENT, sysras_BLOCK_00, 178)
#define ENOENT_RAS_UPDATE_PL		KERROR(ENOENT, sysras_BLOCK_00, 179)
#define ENOMEM_RASP_RDOWN2		KERROR(ENOMEM, sysras_BLOCK_00, 180)
#define ENOMEM_RASP_RDOWN		KERROR(ENOMEM, sysras_BLOCK_00, 181)
#define ENOMEM_RAS_UPDATE_P		KERROR(ENOMEM, sysras_BLOCK_00, 182)
#define ENOMEM_RAS_UPDATE_PL		KERROR(ENOMEM, sysras_BLOCK_00, 183)
#define ENOMEM_DOM_PCONTROL		KERROR(ENOMEM, sysras_BLOCK_00, 184)
#define EINVAL_DOM_PCONTROL		KERROR(EINVAL, sysras_BLOCK_00, 185)
#define EINVAL_DOM_PASSTHROUGH		KERROR(EINVAL, sysras_BLOCK_00, 186)
#define ENOMEM_DOM_PCONTROLX		KERROR(ENOMEM, sysras_BLOCK_00, 187)
#define EFAULT_DOM_PCONTROLX		KERROR(EFAULT, sysras_BLOCK_00, 188)
#define EINVAL_RAS_BAD_SELECTOR		KERROR(EINVAL, sysras_BLOCK_00, 189)
#define ENOENT_RAS_PC_UPDATE		KERROR(ENOENT, sysras_BLOCK_00, 190)
#define ENOENT_RAS_PC_LOOKUP		KERROR(ENOENT, sysras_BLOCK_00, 191)

#define EINVAL_RAS_TRACE_SYNC_SZ	KERROR(EINVAL, sysras_BLOCK_00, 192)
#define EINVAL_RAS_TRACE_SYNC_BUF	KERROR(EINVAL, sysras_BLOCK_00, 193)

#define EINVAL_RAS_REG_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 194)
#define EINVAL_RAS_REG_CT		KERROR(EINVAL, sysras_BLOCK_00, 195)
#define EINVAL_RAS_ALIAS_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 196)
#define EINVAL_RAS_ALIAS_CT		KERROR(EINVAL, sysras_BLOCK_00, 197)
#define EINVAL_RAS_CUST_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 198)
#define EINVAL_RAS_CUST_CT		KERROR(EINVAL, sysras_BLOCK_00, 199)
#define EINVAL_RASCB_BADCMD		KERROR(EINVAL, sysras_BLOCK_00, 200)
#define EINVAL_RAS_MEM_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 201)
#define EINVAL_RAS_MEM_CT		KERROR(EINVAL, sysras_BLOCK_00, 202)
#define EINVAL_RAS_ALLOC_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 203)
#define EINVAL_RAS_ALLOC_CT		KERROR(EINVAL, sysras_BLOCK_00, 204)
#define EINVAL_RAS_RESUME_INFRA		KERROR(EINVAL, sysras_BLOCK_00, 205)
#define EINVAL_RAS_RESUME_CT		KERROR(EINVAL, sysras_BLOCK_00, 206)
#define EINVAL_RAS_REG_PARENT_EYEC	KERROR(EINVAL, sysras_BLOCK_00, 207)
#define EINVAL_RAS_REG_SIB_EYEC		KERROR(EINVAL, sysras_BLOCK_00, 208)
#define EINVAL_RAS_INIT_ANCHOR		KERROR(EINVAL, sysras_BLOCK_00, 209)
#define EINVAL_RAS_INIT_RAS		KERROR(EINVAL, sysras_BLOCK_00, 210)
#define EINVAL_RAS_INIT_RAS_CUST	KERROR(EINVAL, sysras_BLOCK_00, 211)
#define EINVAL_RAS_INIT_KEY_HC		KERROR(EINVAL, sysras_BLOCK_00, 212)
#define EINVAL_RAS_INIT_KEY_KK		KERROR(EINVAL, sysras_BLOCK_00, 213)
#define EINVAL_RAS_PUT_DYING		KERROR(EINVAL, sysras_BLOCK_00, 214)
#define EINVAL_RAS_PUT_REFEVENT		KERROR(EINVAL, sysras_BLOCK_00, 215)
#define ENOMEM_RAS_CONSTRUCT_STATIC_R	KERROR(ENOMEM, sysras_BLOCK_00, 216)
#define ENOMEM_RAS_CONSTRUCT_STATIC_P	KERROR(ENOMEM, sysras_BLOCK_00, 217)
#define ENOMEM_RAS_CONSTRUCT_STATIC_DOM	KERROR(ENOMEM, sysras_BLOCK_00, 218)
#define EPERM_RAS_DESTRUCT_INTPRI	KERROR(EPERM, sysras_BLOCK_00, 219)
#define EIDRM_RAS_APPLY_CHILD		KERROR(EIDRM, sysras_BLOCK_00, 220)
#define EINVAL_RAS_PC_PUT_PLIST_EVENT	KERROR(EINVAL, sysras_BLOCK_00, 221)
#define EINVAL_RAS_PC_PUT_DYING		KERROR(EINVAL, sysras_BLOCK_00, 222)
#define EINVAL_RAS_PC_INIT_ERROR	KERROR(EINVAL, sysras_BLOCK_00, 223)
#define EINVAL_RAS_PC_RDOWN_CUST_EYEC_1	KERROR(EINVAL, sysras_BLOCK_00, 224)
#define EINVAL_RAS_PC_RDOWN_CUST_EYEC_2	KERROR(EINVAL, sysras_BLOCK_00, 225)
#define EINVAL_RAS_PC_RDOWN_CUST_EYEC_3	KERROR(EINVAL, sysras_BLOCK_00, 226)
#define ENOMEM_RAS_PL_REALLOC		KERROR(ENOMEM, sysras_BLOCK_00, 227)
#define EINVAL_RAS_KRASCNTL_CMD_EYEC	KERROR(EINVAL, sysras_BLOCK_00, 228)
#define EINVAL_RAS_TRACE_BUF_RSZ_IN	KERROR(EINVAL, sysras_BLOCK_00, 229)
#define EINVAL_RAS_TRACE_BUF_RSZ_BCOPY	KERROR(EINVAL, sysras_BLOCK_00, 230)
#define EINVAL_RAS_TRACE_BUF_CPY_BCOPY	KERROR(EINVAL, sysras_BLOCK_00, 231)
#define EINVAL_RAS_TRACE_BUF_CPY_IN	KERROR(EINVAL, sysras_BLOCK_00, 232)
#define EINVAL_RAS_TRACE_CONST_NULL	KERROR(EINVAL, sysras_BLOCK_00, 233)
#define EINVAL_RAS_TRACE_CONST_NULLCB	KERROR(EINVAL, sysras_BLOCK_00, 234)
#define EINVAL_RAS_TRACE_CONST_DISABLED	KERROR(EINVAL, sysras_BLOCK_00, 235)
#define EINVAL_RAS_TRACE_NOT_FREED_BUF	KERROR(EINVAL, sysras_BLOCK_00, 236)
#define EINVAL_RAS_TRACE_NOT_FREED_BUF1	KERROR(EINVAL, sysras_BLOCK_00, 237)
#define EINVAL_RAS_TRACE_CTRL_NULL	KERROR(EINVAL, sysras_BLOCK_00, 238)
#define EINVAL_RAS_TRACE_CTRL_EYEC	KERROR(EINVAL, sysras_BLOCK_00, 240)
#define EINVAL_RAS_TRACE_CUST_NULL	KERROR(EINVAL, sysras_BLOCK_00, 241)
#define EINVAL_RAS_TRACE_STAT_RASP_NULL	KERROR(EINVAL, sysras_BLOCK_00, 242)
#define EINVAL_RAS_TRACE_STAT_RSTT_NULL	KERROR(EINVAL, sysras_BLOCK_00, 243)
#define EINVAL_RAS_TRACE_DEST_FLAGS	KERROR(EINVAL, sysras_BLOCK_00, 244)
#define EINVAL_RAS_TRACE_DEST_DISABLED	KERROR(EINVAL, sysras_BLOCK_00, 245)
#define EINVAL_RAS_PC_BLOCK_UPDATE	KERROR(EINVAL, sysras_BLOCK_00, 246)
#define EINVAL_RAS_MTRC_READ		KERROR(EINVAL, sysras_BLOCK_00, 247)
#define ENOSUP_RAS_CTL_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 252)
#define EINVAL_RAS_CTL_ARG_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 253)
#define EINVAL_RAS_CTL_EYEC_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 254)
#define EINVAL_RAS_CTL_TYPE_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 255)
#define ENOSUP_RAS_CTL_UNMANAGED_CU	KERROR(EINVAL, sysras_BLOCK_00, 256)
#define EINVAL_RAS_CTL_ARG_UNMANAGED_CU	KERROR(EINVAL, sysras_BLOCK_00, 257)
#define EINVAL_RAS_CTL_TYPE_UNMANAGED_CU KERROR(EINVAL, sysras_BLOCK_00, 258)
#define EINVAL_RAS_CTL_BUF_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 259)
#define EINVAL_RAS_TRACE_NOT_FREED_UBUF	KERROR(EINVAL, sysras_BLOCK_00, 260)
#define EINVAL_RAS_TRACE_BAD_UCT	KERROR(EINVAL, sysras_BLOCK_00, 261)
#define EINVAL_RAS_TRACE_ADJ1_BAD_MOD	KERROR(EINVAL, sysras_BLOCK_00, 262)
#define EINVAL_RAS_TRACE_ADJ1_BAD_SZ	KERROR(EINVAL, sysras_BLOCK_00, 263)
#define EINVAL_RAS_TRACE_ADJ1_BAD_SZ1	KERROR(EINVAL, sysras_BLOCK_00, 264)
#define EINVAL_RAS_TRACE_ADJ1_BAD_EYEC	KERROR(EINVAL, sysras_BLOCK_00, 265)
#define EINVAL_RAS_TRACE_BAD_UCT2	KERROR(EINVAL, sysras_BLOCK_00, 266)
#define EINVAL_RAS_CTL_ALLOC_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 267)
#define EINVAL_RAS_TRACE_CUST_UNMANAGED	KERROR(EINVAL, sysras_BLOCK_00, 268)
#define EINVAL_RAS_TRACE_ADJ1_BAD_DATA_SZ KERROR(EINVAL, sysras_BLOCK_00, 269)
#define EINVAL_RAS_MTRC_LTUNPIN_FAILED  KERROR(EINVAL, sysras_BLOCK_00, 270)
#define ECORRUPT_RAS_MTRC_STAGGER	KERROR(ECORRUPT, sysras_BLOCK_00, 271)

/*
 * sysras_BLOCK_07 is reserved for wrapper KERRORs, such as
 * KERROR_RAS_STAT_UIOMOVE, used to wrap legacy interfaces yet clearly
 * indicate where the errors were from.
 */
#define KERROR_RAS_UIOMOVE(__rc)	KERROR(__rc, sysras_BLOCK_07, 00)
#define	ENOMEM_RAS_UIOMOVE		KERROR_RAS_UIOMOVE(ENOMEM)
#define	EFAULT_RAS_UIOMOVE		KERROR_RAS_UIOMOVE(EFAULT)
#define KERROR_RAS_COPYOUT(__rc)	KERROR(__rc, sysras_BLOCK_07, 01)
#define	ENOMEM_RAS_COPYOUT		KERROR_RAS_COPYOUT(ENOMEM)
#define	EFAULT_RAS_COPYOUT		KERROR_RAS_COPYOUT(EFAULT)
#define KERROR_RAS_COPYIN(__rc)		KERROR(__rc, sysras_BLOCK_07, 02)
#define	E2BIG_RAS_COPYIN		KERROR_RAS_COPYIN(E2BIG)
#define	EFAULT_RAS_COPYIN		KERROR_RAS_COPYIN(EFAULT)


#if (defined _RAS_INTERNAL) || (defined _KERNEL)

typedef kerrno_t (*ras_callback_t)(
	ras_block_t,
	ras_cmd_t,
	void *,
	void *);

#endif /* _RAS_INTERNAL || _KERNEL*/

#ifdef _KERNEL

/* Prototypes: */

extern kerrno_t ras_register(
	ras_block_t *rasbp,
	char *name,
	ras_block_t parent,
	ras_type_t typesubtype,
	char *desc,
	long flags,
	ras_callback_t ras_callback,
	void *callback_data);

extern kerrno_t ras_control(
	ras_block_t rasb,
	ras_cmd_t cmd,
	void *arg,
	long argsize);

extern kerrno_t ras_path_control(
	char *path,
	ras_cmd_t cmd,
	void *arg,
	long argsize);

extern kerrno_t ras_customize(ras_block_t rasb);

extern kerrno_t ras_unregister(ras_block_t rasb);

extern kerrno_t ras_null_callback(
	ras_block_t,
	ras_cmd_t,
	void *,
	void *);
#endif /* _KERNEL */

/* RAS utility services: */

#if (defined _RAS_INTERNAL) || (defined _KERNEL)

/*
 * This macro is common to both runtime and KDB execution environments.
 * The checker code can call this RASCHK_RT_ONLY that will have the desired
 * code in runtime environment and will be void in KDB environment. 
 */
#ifdef  __RT_RASCHK
#define	RASCHK_RT_ONLY(__statement)	do { __statement; } while(0)
#define	RASCHK_KDB_ONLY(__statement)	do { ; } while(0)
#endif

#ifdef  __KDB_RASCHK
#define	RASCHK_RT_ONLY(__statement)	do { ; } while(0)
#define	RASCHK_KDB_ONLY(__statement)	do { __statement; } while(0)
#endif

/* 
 * void *ENCODE_KPTR(void *ptr, short key) 
 */
#ifdef __64BIT_KERNEL
#define ENCODE_KPTR(__p, __key)	((void *)((ulong)(__p)^((0x8ULL<<60) | \
				   ( ((0x0000FFFFULL)&(__key)) << 44))))
#else
#define ENCODE_KPTR(__p, __key)	((void *)(__p))
#endif

/* 
 * void *DECODE_KPTR(void *ptr, short key) 
 */
#define DECODE_KPTR(__p, __key)	ENCODE_KPTR(__p, __key)

/* 32/64 invarient macros */
#define INVALID_PTR64(__key)	((0x700DFEEDULL << 32) | (uint64_t)(__key))
#define INVALID_PTR32(__key)	((unsigned long) (0 | ((__key)%0x40)))
/* 
 * void *INVALID_PTR(int key) 
 */
#ifdef __64BIT__
#define INVALID_PTR(__key)	((void *)INVALID_PTR64(__key))
#else
#define INVALID_PTR(__key)	((void *)INVALID_PTR32(__key))
#endif /* __64BIT__ */

#define RAS_BLOCK_INVALID	INVALID_PTR(0x7262)	/* "rb" */

extern const ras_block_t RAS_BLOCK_NULL;

#endif /* _RAS_INTERNAL || _KERNEL */

int rascntl(
	char *path,
	ras_cmd_t cmd,
	void *arg,
	int argsize);

#ifdef _KERNEL

/* 
 * abend():  Report a kernel error and initiate recovery processing.
 *      The error_code and error_data parameters identify the error.
 */ 
extern void abend(
	kerrno_t error_code,
	long error_data,
	... /* detail data */);

#ifndef __INFREQUENT

#if __IBMC__ >= 900 && __C99_PRAGMA_OPERATOR
#define __INFREQUENT	_Pragma("execution_frequency(very_low)")
#else
#define __INFREQUENT
#endif /* __IBMC__ >= 900 */

#endif /* ! __INFREQUENT */

/*
 * AVOW():  Check a run time condition and abend if condition is not met.
 */
#define AVOW(_cond, _kerrno, _data)		                  	\
	do {					                  	\
		if (!(_cond)) {			                  	\
			__INFREQUENT;			 		\
			abend(_kerrno, (long)(_data));                 	\
		}				                  	\
	} while (0)

/* 
 * AVOWX():  Check a run time condition and abend if condition is not 
 *	met with a variable number of abend() parameters.
 * 
 *	There must be at least 1 argument for the ... part of the macro
 *	invocation.
 */
#if !defined(__cplusplus) &&                                            \
    ((__STDC_VERSION__ >= 199901L) || defined(__C99_MACRO_WITH_VA_ARGS))
#define AVOWX(_cond, _kerrno, _data, ... /* detail data*/)		\
	do {								\
		if (!(_cond)) {						\
			__INFREQUENT;					\
			abend(_kerrno, (long)(_data), __VA_ARGS__);	\
		}							\
	} while (0)
#endif /* !defined(__cplusplus) && ... */ 

#ifndef __RECOVERY_BARRIERS
#define __RECOVERY_BARRIERS

/*
 * frr_barrier_add():  Increment the recovery barrier count in the top 
 *      FRR entry on the recovery stack.  
 */ 
void frr_barrier_add(void);
#pragma mc_func frr_barrier_add{ "48015903" }
#pragma reg_killed_by frr_barrier_add gr0,gr10-gr12,cr0-cr1,lr

/*
 * frr_barrier_delete():  Decrement the recovery barrier count in the top
 *      FRR entry on the recovery stack.
 */
void frr_barrier_delete(void);
#pragma mc_func frr_barrier_delete{ "48015A03" }
#pragma reg_killed_by frr_barrier_delete gr0,gr10-gr12,cr0-cr1,lr

#endif /* __RECOVERY_BARRIERS */
#endif /* _KERNEL */

/* Parameter Domains */
typedef enum ras_parmdomain {
	RASPD_TRACE_PASS_THROUGH,
	RASPD_ERROR_PASSTHROUGH,
	RASPD_DUMP_PASSTHROUGH,
	RASPD_LIVEDUMP,
	RASPD_LAST
} ras_parmdomain_t;

/* Structure argument to the RAS_QUERY_PARMS ras_control command. */
typedef struct ras_query_parms {
	eye_catch4b_t	rqp_eyec;	/* EYEC_RQP */
	int		rqp_vers;	/* version */
	ras_parmdomain_t rqp_pdomain;	/* the parameter domain */
	int		rqp_len;	/* input size and returned data lnth */
	int		rqp_fmtlen;	/* length of the format string */
	char		rqp_text[1];	/* help text */
} ras_query_parms_t;

#define EYEC_RQP	__EYEC4('r','q','p','p') /* rqpp */
#define RQP_VERS1	1		/* version 1 */
#define RQP_MAXTEXT	4096		/* max text length */

extern kerrno_t ras_ret_query_parms(
        ras_query_parms_t *retp,        /* Return structure */
        char *fmtstr,                   /* format string */
        int numstrings,                 /* # help strings */
        char *descr[]);                 /* help strings */

#ifdef __cplusplus
}
#endif

#endif /* _H_SYSRAS */
