/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/sys/iostat.h 1.20.5.1                            */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1989,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                                                     */
/* @(#)28     1.20.5.1  src/bos/kernel/sys/iostat.h, sysios, bos72Q, q2019_13A4 2/6/19 00:40:43 */
#ifndef	_H_IOSTAT
#define	_H_IOSTAT
#include <sys/types.h>
#include <sys/kerrno.h>
#include <sys/corralid.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * COMPONENT_NAME: (SYSIOS) I/O Subsystem
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 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.
 */

/*
 * Iostat structure for tty
 */
struct ttystat
{
	long rawinch;		/* tty raw characters in count		*/
	long caninch;		/* tty canonical characters in count	*/
	long rawoutch;		/* tty characters out count		*/
};

/*
 * Iostat structure for tty (size-invariant - 64 bits)
 */
#ifdef _LONG_LONG
struct ttystat64
{
	long long rawinch;	/* tty raw characters in count		*/
	long long caninch;	/* tty canonical characters in count	*/
	long long rawoutch;	/* tty characters out count		*/
};
#endif

/*
 * Iostat structure for disks
 */
struct dkstat
{
	char		diskname[32];	/* disk's logical name		*/
	struct dkstat	*dknextp;	/* ptr to next entry in chain	*/
	ushort		dk_status; 	/* disk entry status flags	*/ 
#define IOST_DK_BUSY	0x1		/* disk is currently busy	*/
	ulong		dk_time;  	/* amount of time disk is active*/
	ulong		dk_xrate;	/* OBSOLETE: xfer rate capability*/
#define	__dk_rxfers	dk_xrate	/* #transfers from disk         */
	ulong		dk_bsize;	/* #bytes in a block for this disk*/
	ulong		dk_xfers;	/* #transfers to/from disk	*/
	ulong		dk_rblks;	/* #blocks read from disk	*/
	ulong		dk_wblks;	/* #blocks written to disk	*/
	ulong		dk_seek;	/* #seek operations for disks
					   with discrete seek commands	*/
/*
   Disks that support the q depth version of the dkstat structure
   will set dk_version to the dk_q_depth_magic number.  Similarly, 
   disks supporting the MPIO enabled version of the dkstat structure 
   will set dk_version to dk_qd_mpio_magic.  Users of the dkstat
   structure should test the version field for validity before
   reporting statistics dependent on the structure version.
 */
#define dk_q_depth_magic     0x31C4AF8C /* magic number for q depth	     */
#define dk_qd_mpio_magic     0x31C4AF8D /* magic number for q depth+MPIO     */
#define dk_qd_service_magic  0x31C4AF8E /* magic number for service+MPIO     */
#define dk_qd_service2_magic 0x31C4AF8F /* magic number for rxfers+q_sampled */
#define dk_tape_magic        0x31C4AF90 /* magic number for tapes            */
#define dk_loopback_magic    0x31C4AF91 /* magic number for loopback devices */
#define dk_thread_device     0x31C4AF92 /* magic number for thread dev  */
#define dk_thread_path       0x31C4AF93 /* magic number for thread path */
#define dk_thread_server     0x31C4AF94 /* magic number for thread serv */
#define dk_qd_magic dk_version          /* for source compatibility     */
	ulong		dk_version;	/* dkstat struct version	*/
	ulong		dk_q_depth;	/* queue depth 			*/
	struct dkstat *dk_mpio_anchor;  /* pointer to path data anchor  */
					/* for threaded devices, this points */
					/* to the virtual adapter entry	*/
	
	struct dkstat *dk_mpio_next_path;/* pointer to next path in chain */
					/* for threaded devices, next path */
					/* that is associated with the virtual */
					/* adapter			*/

#define dk_vscsi_initiator	0x1	/* vscsi initiator dk_mpio_path_id */
#define dk_vscsi_server		0x2	/* vscsi server dk_mpio_path_id */
#define dk_vscsi_target_device	0x3	/* vscsi target device dk_mpio_path_id*/
#define dk_pseudo_device        0x4     /* Pseudo devices dk_mpio_path_id */

	ushort          dk_mpio_path_id;/* MPIO path id                 */
	cid_t           cid;		/* WPAR id                      */
	ulong		dk_q_full;	/*in flight queue full occurence count*/
	u_longlong_t	dk_rserv;	/* read or receive service time */
	ulong		dk_rtimeout;	/* number of read request timeouts */
	ulong		dk_rfailed;	/* number of failed read requests */
	u_longlong_t	dk_min_rserv;	/* min read or receive service time */
	u_longlong_t	dk_max_rserv;	/* max read or receive service time */
	u_longlong_t	dk_wserv;	/* write or send service time */
	ulong		dk_wtimeout;	/* number of write request timeouts */
	ulong		dk_wfailed;	/* number of failed write requests */
	u_longlong_t	dk_min_wserv;	/* min write or send service time */
	u_longlong_t	dk_max_wserv;	/* max write or send service time */
	ulong		dk_wq_depth;	/* driver wait queue depth */
	ulong		dk_wq_sampled;	/* accumulated sampled dk_wq_depth */
	u_longlong_t	dk_wq_time;	/* accumulated wait queueing time */
	u_longlong_t	dk_wq_min_time;	/* min wait queueing time */
	u_longlong_t	dk_wq_max_time;	/* max wait queueing time */
	union {
		/* adapter name (NULL for MPIO and vscsi server) */
		char	adapter[32];
		/* used only by initiator to identify server */
		struct {
			ulong partition_id;	/* server partition id */
			ulong instance_id;	/* server instance id */
		} serv;
	} ident;
	ulong		dk_q_sampled;	/* accumulated sampled dk_q_depth */
};

/*
 * Kernel structure for keeping i/o statistics on disks
 */
struct iostat
{
	struct dkstat	*dkstatp;	/* ptr to linked list of disk
					   entries, one per configured disk */
	ulong		dk_cnt;		/* # dkstat structures in list	*/
	ulong		dk_path_cnt;	/* # path dkstat structures in list */
};

int iostadd(			/* register an entry in iostat table */
	int    devtype,		/* device type */
        struct  dkstat  *dkstp);

void iostdel(			/* delete an entry from iostat table */
       struct  dkstat  *dkstp); /* pointer to structure to remove */

void update_stats(void);	/* update sysinfo/syswait data structures */
void update_stats64(void);	/* update sysinfo64 data structures */
void update_iostats(int tick_size,int share); /* update disk info structures */

/*
 * Device Statistics structure for enhanced IO statistics
 */

struct devstat {
	unsigned long dst_dev_version;	  /* version identification     */
	dev_t         dst_device_id;	  /* major, minor               */
	unsigned long dst_read_count;	  /* Number of reads            */
	unsigned long dst_write_count;	  /* Number of writes           */
	unsigned long dst_bytes_read;	  /* Number of bytes read       */
	unsigned long dst_bytes_written;  /* Number of bytes written    */
	unsigned long dst_read_time;	  /* Aggregate time (reads)     */
	unsigned long dst_write_time;	  /* Aggregate time (writes)    */
	unsigned long dst_read_errors;	  /* Number of reads in error   */
	unsigned long dst_write_errors;	  /* Number of writes in error  */
	unsigned long dst_pad[6];   	  /* reserved for future use    *
		                     	   * and Pad to 128 bytes.      */
};

/*
 * Definition for the version number
 */
#define DEVSTAT_VER0		0x4445565300000000ULL
#define DEVSTAT_VERSION		DEVSTAT_VER0

#define DEVSTAT_VER0_SIZE	(offsetof(struct devstat, dst_pad[5]) \
						+ sizeof(unsigned long))

/*
 * Definitions for the dev_stat_get_data kernel service
 */
#define DEVSTAT_GET_FIRST	0    /* Read stats data from the beginning   */
#define DEVSTAT_GET_NEXT	1    /* Read stats data from next unread     */

#define DEVSTAT_MORE_DATA	1	/* There is more stat data availble  */

/*
 * Definitions for the dev_stat_ctl kernel service
 *
 * Command:
 */
#define DEVSTAT_SET_STATE	1    /* Set state (enable/disable)           */
#define DEVSTAT_GET_STATE	2    /* Get current state (enabled/disabled) */
#define DEVSTAT_RESET_STATE	3    /* Reset state			     */

/*
 * Subcommand for the set state command:
 */
#define DEVSTAT_DISABLE		0    /* Disable device statistics            */
#define DEVSTAT_ENABLE		1    /* Enable device statistics             */

/*
 * Current state as reported by the get state command:
 */
#define DEVSTAT_IS_ENABLED	1    /* Current state: Device Stats enabled  */
#define DEVSTAT_IS_DISABLED	0    /* Current state: Device Stats disabled */

/*
 * Device Statistics Kernel Services - Function prototypes
 */
kerrno_t dev_stat_register (unsigned long, unsigned long *);
kerrno_t dev_stat_get_count (unsigned long, unsigned long *);
kerrno_t dev_stat_get_data ( unsigned long, unsigned long, void *,
                                            unsigned long, unsigned long *);
kerrno_t dev_stat_reset	(unsigned long);
kerrno_t dev_stat_unregister (unsigned long);
kerrno_t dev_stat_ctl (unsigned long, unsigned long, void *);

/*
 * Return codes for the device statistics kernel services (KERRNOs)
 */
#define EINVAL_DEVSTAT_CTL_UNKN_CMD	    KERROR(EINVAL, sysios_BLOCK_00, 40)
#define EINVAL_DEVSTAT_CTL_UNKN_STATE	    KERROR(EINVAL, sysios_BLOCK_00, 41)
#define EINVAL_DEVSTAT_CTL_CTXT		    KERROR(EINVAL, sysios_BLOCK_00, 42)
#define EINVAL_DEVSTAT_CTL_NOT_SUPP	    KERROR(EINVAL, sysios_BLOCK_00, 43)
#define EINVAL_DEVSTAT_CTL_UNKN_HANDLE	    KERROR(EINVAL, sysios_BLOCK_00, 44)
#define EINVAL_DEVSTAT_GET_COUNT_CTXT	    KERROR(EINVAL, sysios_BLOCK_00, 47)
#define EINVAL_DEVSTAT_GET_COUNT_NOT_SUPP   KERROR(EINVAL, sysios_BLOCK_00, 48)
#define EINVAL_DEVSTAT_GET_COUNT_UNKN_HANDLE \
					    KERROR(EINVAL, sysios_BLOCK_00, 50)
#define EINVAL_DEVSTAT_GET_DATA_BADDEV	    KERROR(EINVAL, sysios_BLOCK_00, 51)
#define EINVAL_DEVSTAT_GET_DATA_BUF_SIZE    KERROR(EINVAL, sysios_BLOCK_00, 52)
#define EINVAL_DEVSTAT_GET_DATA_CTXT	    KERROR(EINVAL, sysios_BLOCK_00, 53)
#define EINVAL_DEVSTAT_GET_DATA_NOT_SUPP    KERROR(EINVAL, sysios_BLOCK_00, 54)
#define EINVAL_DEVSTAT_GET_DATA_STAT_DISABLED \
					    KERROR(EINVAL, sysios_BLOCK_00, 55)
#define EINVAL_DEVSTAT_GET_DATA_UNKN_HANDLE KERROR(EINVAL, sysios_BLOCK_00, 56)
#define EINVAL_DEVSTAT_INVAL_CMD	    KERROR(EINVAL, sysios_BLOCK_00, 57)
#define EINVAL_DEVSTAT_REG_UNKN_VERSION	    KERROR(EINVAL, sysios_BLOCK_00, 58)
#define EINVAL_DEVSTAT_REG_CTXT		    KERROR(EINVAL, sysios_BLOCK_00, 59)
#define EINVAL_DEVSTAT_REG_NOT_SUPP	    KERROR(EINVAL, sysios_BLOCK_00, 60)
#define EINVAL_DEVSTAT_RESET_CTXT	    KERROR(EINVAL, sysios_BLOCK_00, 61)
#define EINVAL_DEVSTAT_RESET_NOT_SUPP	    KERROR(EINVAL, sysios_BLOCK_00, 62)
#define EINVAL_DEVSTAT_RESET_STAT_DISABLED  KERROR(EINVAL, sysios_BLOCK_00, 63)
#define EINVAL_DEVSTAT_RESET_UNKN_HANDLE    KERROR(EINVAL, sysios_BLOCK_00, 64)
#define EINVAL_DEVSTAT_UNREG_UNKN_HANDLE    KERROR(EINVAL, sysios_BLOCK_00, 65)
#define EINVAL_DEVSTAT_UNREG_CTXT	    KERROR(EINVAL, sysios_BLOCK_00, 66)
#define EINVAL_DEVSTAT_UNREG_NOT_SUPP	    KERROR(EINVAL, sysios_BLOCK_00, 67)
#define ENODEV_DEVSTAT_GET_DATA		    KERROR(EINVAL, sysios_BLOCK_00, 68)
#define ENOMEM_DEVSTAT_REG		    KERROR(EINVAL, sysios_BLOCK_00, 69)

#ifdef __cplusplus
}
#endif

#endif	/* _H_IOSTAT */
