/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72D src/bos/kernel/sys/kinfo.h 1.11.1.4                             */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1985,1989              */
/* 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                                                     */
/* @(#)96	1.11.1.4  src/bos/kernel/sys/kinfo.h, incsys, bos72D, d2016_18B2 5/4/16 00:55:40 */
/*
 * COMPONENT_NAME:  Kernel Info Header
 *
 * FUNCTIONS: 
 *
 * ORIGINS: 26 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1985, 1989
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *
 * Copyright (c) 1989 The Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution is only permitted until one year after the first shipment
 * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
 * binary forms are permitted provided that: (1) source distributions retain
 * this entire copyright notice and comment, and (2) distributions including
 * binaries display the following acknowledgement:  This product includes
 * software developed by the University of California, Berkeley and its
 * contributors'' in the documentation or other materials provided with the
 * distribution and in all advertising materials mentioning features or use
 * of this software.  Neither the name of the University nor the names of
 * its contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *	(#)kinfo.h	7.4 (Berkeley) 6/28/90
 */

/************************************************************************************
* 4 byte integer variable is used to represent the operations such as KINFO_NDD(Get *
* the information about NDD), KINFO_READ, KINFO_WRITE etc, family (AF_INET,         *
* AF_INET6 etc). Additional versioning information is added for upgradation purpose *
* (new kernel, old binaries and visa versa).                                        *
*                                                                                   *
* Version 0:                                                                        *
*										    *
* 16(0-15)bits are used to represent the operation.                                 *
* 8(16-23)bits are used to represent the family.                                    *
* 8(24-31)bits are unused.                                                          *
*                                                                                   *
* Block representation:                                                             *
*                                                                                   *
* <--------------------------32bits ------------------------------------->          *
* |-----------------|------------------|--------------------------------|           *
* | Unused          |    Family        |  Operation                     |           *  
* |-----------------|------------------|--------------------------------|           *
* 31              24 23              16 15                              0           *
*                                                                                   *
*                                                                                   *
* Version 1:                                                                        *
*                                         					    *
* 24(0-23)bits are used to represent the operation.                                 *
* 6(24-29)bits are used to represent the family.                                    *
* 2(30 and 31)bits are used for version.                                            *
*                                                                                   *
* Block representation:                                                             *
*                                                                                   *
* <--------------------------32bits ------------------------------------->          *
* |------|-----------|---------------------------------------------------|          *
* | Vers |  Family   |              Operation                            |          *  
* |------|-----------|---------------------------------------------------|          *
* 31   30 29       24 23                                                 0          *
*                                                                                   *
*                                                                                   *
*************************************************************************************/



 
/*
 * Get kernel info
 */
#define KINFO_CUR_VERS 		0x1
#define KI_OP_MASK_V0		0x0000ffff
#define KI_OP_MASK_V1		0x00ffffff
#define ki_op_v0(x)		((x) & KI_OP_MASK_V0)
#define ki_op_v1(x)		((x) & KI_OP_MASK_V1)
#define KI_TYPE_MASK_V0		0x0000ff00
#define KI_TYPE_MASK_V1		0x00ffff00
#define ki_type_v0(x)		((x) & KI_TYPE_MASK_V0)
#define ki_type_v1(x)		((x) & KI_TYPE_MASK_V1)
#define KI_AF_MASK_V0      	0x00ff0000
#define KI_AF_MASK_V1		0x3f000000
#define KI_AF_SHIFT_V0 		16
#define KI_AF_SHIFT_V1 		24
#define ki_af_v0(x)		(((x) & KI_AF_MASK_V0) >>KI_AF_SHIFT_V0)
#define ki_af_v1(x)		(((x) & KI_AF_MASK_V1) >>KI_AF_SHIFT_V1)
#define KI_VER_MASK		0xc0000000
#define KI_VERS_SHIFT 		30
#define KINFO_VERS		(KINFO_CUR_VERS << KI_VERS_SHIFT)
#define ki_vers(x)	 	(((x) & KI_VER_MASK) >> KI_VERS_SHIFT)		


#define	IS_KINFO_CVERS(x)	(ki_vers(x) == KINFO_CUR_VERS)
#define ki_op(x)		(IS_KINFO_CVERS(x) ? ki_op_v1(x) : ki_op_v0(x))
#define ki_type(x)		(IS_KINFO_CVERS(x) ? ki_type_v1(x) :ki_type_v0(x))
#define ki_af(x)		(IS_KINFO_CVERS(x) ? ki_af_v1(x) :ki_af_v0(x))

/* 
 * proc info definitions.
 */
#define	KINFO_PROC_COM		(0x0<<8)
#define KINFO_PROC_ALL_COM	(KINFO_PROC_COM|0)	/* everything */
#define	KINFO_PROC_PID_COM	(KINFO_PROC_COM|1)	/* by process id */
#define	KINFO_PROC_PGRP_COM	(KINFO_PROC_COM|2)	/* by process group id */
#define	KINFO_PROC_SESSION_COM	(KINFO_PROC_COM|3)	/* by session of pid */
#define	KINFO_PROC_TTY_COM	(KINFO_PROC_COM|4)	/* by controlling tty */
#define	KINFO_PROC_UID_COM	(KINFO_PROC_COM|5)	/* by effective uid */
#define	KINFO_PROC_RUID_COM   	(KINFO_PROC_COM|6)	/* by real uid */

/* 
 * proc info definitions.
 */
#define	KINFO_PROC		(KINFO_PROC_COM|KINFO_VERS)
#define KINFO_PROC_ALL		(KINFO_PROC_ALL_COM|KINFO_VERS)		/* everything */
#define	KINFO_PROC_PID		(KINFO_PROC_PID_COM|KINFO_VERS)		/* by process id */
#define	KINFO_PROC_PGRP		(KINFO_PROC_PGRP_COM|KINFO_VERS)		/* by process group id */
#define	KINFO_PROC_SESSION 	(KINFO_PROC_SESSION_COM|KINFO_VERS)	/* by session of pid */
#define	KINFO_PROC_TTY		(KINFO_PROC_TTY_COM|KINFO_VERS)		/* by controlling tty */
#define	KINFO_PROC_UID		(KINFO_PROC_UID_COM|KINFO_VERS)		/* by effective uid */
#define	KINFO_PROC_RUID		(KINFO_PROC_RUID_COM|KINFO_VERS)	/* by real uid */

/*
 * Routing table definitions.
 */
#define KINFO_RT_COM		(0x1<<8)
#define KINFO_RT_DUMP_COM	(KINFO_RT_COM|1)	/* dump; may limit to a.f. */
#define KINFO_RT_FLAGS_COM	(KINFO_RT_COM|2)	/* by flags, e.g. RESOLVING */
#define KINFO_RT_IFLIST_COM	(KINFO_RT_COM|3)	/* dump ifnet list */

/*
 * Routing table definitions.
 */
#define KINFO_RT		(KINFO_RT_COM|KINFO_VERS)
#define KINFO_RT_DUMP		(KINFO_RT_DUMP_COM|KINFO_VERS)	/* dump; may limit to a.f. */
#define KINFO_RT_FLAGS		(KINFO_RT_FLAGS_COM|KINFO_VERS)	/* by flags, e.g. RESOLVING */
#define KINFO_RT_IFLIST		(KINFO_RT_IFLIST_COM|KINFO_VERS)	/* dump ifnet list */

/*
 * vnodes definition.
 */
#define	KINFO_VNODE_COM		(0x2<<8)

/*
 * vnodes definition.
 */
#define	KINFO_VNODE		(KINFO_VNODE_COM|KINFO_VERS)

/*
 * Network Device Drivers definition.
 */
#define	KINFO_NDD_COM		(0x4<<8)
#define KINFO_NETDEV_CLASS_COM	(KINFO_NDD_COM)
#define KINFO_NETDEV_IB_COM	(KINFO_NETDEV_CLASS_COM | 1)
#define	KINFO_NDD_CHAN_COM	(KINFO_NETDEV_CLASS_COM | 2)

/*
 * Network Device Drivers definition.
 */
#define	KINFO_NDD		(KINFO_NDD_COM | KINFO_VERS)
#define KINFO_NETDEV_CLASS	(KINFO_NETDEV_CLASS_COM | KINFO_VERS)
#define KINFO_NETDEV_IB		(KINFO_NETDEV_IB_COM | KINFO_VERS)
#define	KINFO_NDD_CHAN		(KINFO_NDD_CHAN_COM | KINFO_VERS)

/* 
 * Reading definition.
 */
#define KINFO_READ_COM		(0x8<<8)

/* 
 * Reading definition.
 */
#define KINFO_READ		(KINFO_READ_COM | KINFO_VERS)

/* 
 * Writing version0 definition.
 */
#define KINFO_WRITE_V0		(10<<8)

/* 
 * Writing version1 definition.
 */
#define KINFO_WRITE_V1		(0x10<<8)

/* 
 * Writing definition.
 */
#define KINFO_WRITE		(KINFO_WRITE_V1 | KINFO_VERS)



/* 
 * 64 bit version of read and write
 */
#define KINFO_READ64_V0		(20<<8)
#define KINFO_READ64_V1		(0x20<<8)
#define KINFO_READ64		(KINFO_READ64_V1 | KINFO_VERS)

#define KINFO_WRITE64_V0	(40<<8)
#define KINFO_WRITE64_V1	(0x40<<8)
#define KINFO_WRITE64		(KINFO_WRITE64_V1 | KINFO_VERS)

/*
 * Zero netkmem stats
 */
#define KINFO_ZSTATS_V0		(80<<8)
#define KINFO_ZSTATS_V1		(0x80<<8)
#define KINFO_ZSTATS		(KINFO_ZSTATS_V1 | KINFO_VERS)

/* Set interface statistics for netstat -Zs/i */
#define KINFO_SET_IF_STATS_V0	(100<<8)
#define KINFO_SET_IF_STATS_V1	(0x100<<8)
#define KINFO_SET_IF_STATS      (KINFO_SET_IF_STATS_V1 | KINFO_VERS)

#define KINFO_SET_DMX_STATS_V0	(200<<8)
#define KINFO_SET_DMX_STATS_V1	(0x200<<8)
#define KINFO_SET_DMX_STATS     (KINFO_SET_DMX_STATS_V1 | KINFO_VERS)

/* Get the interface data for specified interface name. */
#define KINFO_GET_IFNET_V1	(0x400<<8)
#define KINFO_GET_IFNET         (KINFO_GET_IFNET_V1 | KINFO_VERS)

#define KINFO_GET_AVENRUN_COM	(KINFO_READ_COM|1)
#define KINFO_GET_AVENRUN	(KINFO_GET_AVENRUN_COM | KINFO_VERS)

#define KINFO_GET_IPL_COM	(KINFO_READ_COM|2)
#define KINFO_GET_IPL		(KINFO_GET_IPL_COM | KINFO_VERS)

#define KINFO_GET_TICKADJ_COM	(KINFO_READ_COM|3)
#define KINFO_GET_TICKADJ	(KINFO_GET_TICKADJ_COM | KINFO_VERS)

#define KINFO_GET_SCTP_COM	(KINFO_READ_COM|4)
#define KINFO_GET_SCTP          (KINFO_GET_SCTP_COM | KINFO_VERS)

#define KINFO_GET_SCTPHASH_COM	(KINFO_READ_COM|5)
#define KINFO_GET_SCTPHASH	(KINFO_GET_SCTPHASH_COM | KINFO_VERS)

#define KINFO_GET_RDS_COM	(KINFO_READ_COM|6)
#define KINFO_GET_RDS           (KINFO_GET_RDS_COM | KINFO_VERS)

#define KINFO_GET_MBSTAT_COM	(KINFO_READ_COM|7)
#define KINFO_GET_MBSTAT	(KINFO_GET_MBSTAT_COM | KINFO_VERS)

#define KINFO_GET_RTSTAT_COM	(KINFO_READ_COM|8)
#define KINFO_GET_RTSTAT	(KINFO_GET_RTSTAT_COM | KINFO_VERS)

#define KINFO_GET_ICMPSTAT_COM	(KINFO_READ_COM|9)
#define KINFO_GET_ICMPSTAT	(KINFO_GET_ICMPSTAT_COM | KINFO_VERS)

#define KINFO_PUT_SCTP_V0	(KINFO_WRITE_V0|1)
#define KINFO_PUT_SCTP_V1	(KINFO_WRITE_V1|1)
#define KINFO_PUT_SCTP          (KINFO_PUT_SCTP_V1 | KINFO_VERS)

#define KINFO_PUT_RDS_V0	(KINFO_WRITE_V0|2)
#define KINFO_PUT_RDS_V1	(KINFO_WRITE_V1|2)
#define KINFO_PUT_RDS           (KINFO_PUT_RDS_V1 | KINFO_VERS)

#define READ_STATS	1
#define RESET_STATS	2
#define GET_HASH	3

/* Define a macro for operation and family */
#define  AF_V6                  (AF_INET6 << KI_AF_SHIFT_V1)
#define  AF_V4                  (AF_INET << KI_AF_SHIFT_V1)
#define  AF(x)                  ((x) << KI_AF_SHIFT_V1)
#define KINFO_RT_IFLIST_INET    (KINFO_RT_IFLIST | AF_V4)
#define KINFO_RT_IFLIST_INET6   (KINFO_RT_IFLIST| AF_V6)
#define KINFO_RT_DUMP_INET      (KINFO_RT_DUMP| AF_V4)
#define KINFO_RT_DUMP_INET6     (KINFO_RT_DUMP| AF_V6)
#define KINFO_RT_DUMP_AF(x)     (KINFO_RT_DUMP| AF(x))
#define KINFO_RT_IFLIST_AF(x)   (KINFO_RT_IFLIST| AF(x))

/*
 * Locking and stats
 */
struct kinfo_lock {
	int	kl_lock;
	int	kl_want;
	int	kl_locked;
};

#ifdef KERNEL
extern struct kinfo_lock kinfo_lock;
#endif

/*
 * structure used by the KINFO_READ64 and KINFO_WRITE64 to allow a 32 bit
 * program to pass a 64 bit kernel address to a 64 bit kernel.
 */
struct kinfo_addr {
	long long addr;
};

typedef struct kinfo_addr kinfo_addr_t;
