/* Backport from 2.5 LKCD
 * (:pserver:anonymous@cvs.sourceforge.net:/cvsroot/lkcd):
 * various header snippets for dumping via netconsole
 */

struct dump_dev;

struct dump_dev_ops {
	int (*open)(struct dump_dev *, unsigned long); /* configure */
	int (*release)(struct dump_dev *); /* unconfigure */
	int (*silence)(struct dump_dev *); /* when dump starts */
	int (*resume)(struct dump_dev *); /* when dump is over */
	int (*seek)(struct dump_dev *, loff_t);
	/* trigger a write (async in nature typically) */
	int (*write)(struct dump_dev *, void *, unsigned long);
	/* not usually used during dump, but option available */
	int (*read)(struct dump_dev *, void *, unsigned long);
	/* use to poll for completion */
	int (*ready)(struct dump_dev *, void *); 
	int (*ioctl)(struct dump_dev *, unsigned int, unsigned long);
};

/*
 *  linux/drivers/net/netconsole.h
 *
 *  Copyright (C) 2001  Ingo Molnar <mingo@redhat.com>
 *
 *  This file contains the implementation of an IRQ-safe, crash-safe
 *  kernel console implementation that outputs kernel messages to the
 *  network.
 *
 * Modification history:
 *
 * 2001-09-17    started by Ingo Molnar.
 */

/****************************************************************
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2, or (at your option)
 *      any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 ****************************************************************/

#define NETCONSOLE_VERSION 0x03

enum netdump_commands {
	COMM_NONE = 0,
	COMM_SEND_MEM = 1,
	COMM_EXIT = 2,
	COMM_REBOOT = 3,
	COMM_HELLO = 4,
	COMM_GET_NR_PAGES = 5,
	COMM_GET_PAGE_SIZE = 6,
	COMM_START_NETDUMP_ACK = 7,
	COMM_GET_REGS = 8,
	COMM_GET_MAGIC = 9,
	COMM_START_WRITE_NETDUMP_ACK = 10,
};

typedef struct netdump_req_s {
	u64 magic;
	u32 nr;
	u32 command;
	u32 from;
	u32 to;
} req_t;

enum netdump_replies {
	REPLY_NONE = 0,
	REPLY_ERROR = 1,
	REPLY_LOG = 2,
	REPLY_MEM = 3,
	REPLY_RESERVED = 4,
	REPLY_HELLO = 5,
	REPLY_NR_PAGES = 6,
	REPLY_PAGE_SIZE = 7,
	REPLY_START_NETDUMP = 8,
	REPLY_END_NETDUMP = 9,
	REPLY_REGS = 10,
	REPLY_MAGIC = 11,
	REPLY_START_WRITE_NETDUMP = 12,
};

typedef struct netdump_reply_s {
	u32 nr;
	u32 code;
	u32 info;
} reply_t;

#define HEADER_LEN (1 + sizeof(reply_t))

#define DUMP_PAGE_SHIFT 	PAGE_SHIFT
#define DUMP_PAGE_MASK		PAGE_MASK
#define DUMP_PAGE_ALIGN(addr)	PAGE_ALIGN(addr)
#define DUMP_HEADER_OFFSET	PAGE_SIZE

#define DUMP_memcpy		memcpy

/* necessary header files */
#include <asm/dump.h>			/* for architecture-specific header */

/* 
 * Size of the buffer that's used to hold:
 *
 *	1. the dump header (padded to fill the complete buffer)
 *	2. the possibly compressed page headers and data
 */
#define DUMP_BUFFER_SIZE	(64 * 1024)  /* size of dump buffer         */
#define DUMP_HEADER_SIZE	DUMP_BUFFER_SIZE

/* standard header definitions */
#define DUMP_MAGIC_NUMBER	0xa8190173618f23edULL  /* dump magic number */
#define DUMP_MAGIC_LIVE		0xa8190173618f23cdULL  /* live magic number */
#define DUMP_PANIC_LEN		0x100	/* dump panic string length         */

/* dump levels - type specific stuff added later -- add as necessary */
#define DUMP_LEVEL_NONE		0x0	/* no dumping at all -- just bail   */
#define DUMP_LEVEL_HEADER	0x1	/* kernel dump header only          */
#define DUMP_LEVEL_KERN		0x2	/* dump header and kernel pages     */
#define DUMP_LEVEL_USED		0x4	/* dump header, kernel/user pages   */
#define DUMP_LEVEL_ALL_RAM	0x8	/* dump header, all RAM pages       */
#define DUMP_LEVEL_ALL		0x10	/* dump all memory RAM and firmware */


/* dump compression options -- add as necessary */
#define DUMP_COMPRESS_NONE	0x0	/* don't compress this dump         */
#define DUMP_COMPRESS_RLE	0x1	/* use RLE compression              */
#define DUMP_COMPRESS_GZIP	0x2	/* use GZIP compression             */

/* dump flags - any dump-type specific flags -- add as necessary */
#define DUMP_FLAGS_NONE		0x0	/* no flags are set for this dump   */
#define DUMP_FLAGS_SOFTBOOT	0x2	/* 2 stage soft-boot based dump	    */

#define DUMP_FLAGS_TARGETMASK	0xf0000000 /* handle special case targets   */
#define DUMP_FLAGS_DISKDUMP	0x80000000 /* dump to local disk 	    */
#define DUMP_FLAGS_NETDUMP	0x40000000 /* dump over the network         */

/* dump header flags -- add as necessary */
#define DUMP_DH_FLAGS_NONE	0x0	/* no flags set (error condition!)  */
#define DUMP_DH_RAW		0x1	/* raw page (no compression)        */
#define DUMP_DH_COMPRESSED	0x2	/* page is compressed               */
#define DUMP_DH_END		0x4	/* end marker on a full dump        */
#define DUMP_DH_TRUNCATED	0x8	/* dump is incomplete               */
#define DUMP_DH_TEST_PATTERN	0x10	/* dump page is a test pattern      */
#define DUMP_DH_NOT_USED	0x20	/* 1st bit not used in flags        */

/* names for various dump parameters in /proc/kernel */
#define DUMP_ROOT_NAME		"sys/dump"
#define DUMP_ADDR_NAME		"addr"

#define DUMP_SYSRQ_KEY		'd'	/* key to use for MAGIC_SYSRQ key   */

/* CTL_DUMP names: */
enum
{
	CTL_DUMP_DEVICE=1,
	CTL_DUMP_COMPRESS=3,
	CTL_DUMP_LEVEL=3,
	CTL_DUMP_FLAGS=4,
	CTL_DUMP_ADDR=5,
	CTL_DUMP_TEST=6,
};


/* page size for gzip compression -- buffered slightly beyond hardware PAGE_SIZE used by DUMP */
#define DUMP_DPC_PAGE_SIZE	(DUMP_PAGE_SIZE + 512)

/* dump ioctl() control options */
#define DIOSDUMPDEV		1	/* set the dump device              */
#define DIOGDUMPDEV		2	/* get the dump device              */
#define DIOSDUMPLEVEL		3	/* set the dump level               */
#define DIOGDUMPLEVEL		4	/* get the dump level               */
#define DIOSDUMPFLAGS		5	/* set the dump flag parameters     */
#define DIOGDUMPFLAGS		6	/* get the dump flag parameters     */
#define DIOSDUMPCOMPRESS	7	/* set the dump compress level      */
#define DIOGDUMPCOMPRESS	8	/* get the dump compress level      */

/* these ioctls are used only by netdump module */
#define DIOSTARGETIP		9	/* set the target m/c's ip	    */
#define DIOGTARGETIP		10	/* get the target m/c's ip	    */
#define DIOSTARGETPORT		11	/* set the target m/c's port	    */
#define DIOGTARGETPORT		12	/* get the target m/c's port	    */
#define DIOSSOURCEPORT		13	/* set the source m/c's port	    */
#define DIOGSOURCEPORT		14	/* get the source m/c's port	    */
#define DIOSETHADDR		15	/* set ethernet address		    */
#define DIOGETHADDR		16	/* get ethernet address		    */
#define DIOSIFNAME		17	/* set ethernet interface name	    */

/*
 * Structure: __dump_header
 *  Function: This is the header dumped at the top of every valid crash
 *            dump.  
 */
struct __dump_header {
	/* the dump magic number -- unique to verify dump is valid */
	u64	dh_magic_number;

	/* the version number of this dump */
	u32	dh_version;

	/* the size of this header (in case we can't read it) */
	u32	dh_header_size;

	/* the level of this dump (just a header?) */
	u32	dh_dump_level;

	/* 
	 * We assume dump_page_size to be 4K in every case.
	 * Store here the configurable system page size (4K, 8K, 16K, etc.) 
	 */
	u32	dh_page_size;

	/* the size of all physical memory */
	u64	dh_memory_size;

	/* the start of physical memory */
	u64	dh_memory_start;

	/* the end of physical memory */
	u64	dh_memory_end;

	/* the number of hardware/physical pages in this dump specifically */
	u32	dh_num_dump_pages;

	/* the panic string, if available */
	char	dh_panic_string[DUMP_PANIC_LEN];

	/* timeval depends on architecture, two long values */
	struct {
		u64 tv_sec;
		u64 tv_usec;
	} dh_time; /* the time of the system crash */

	/* the NEW utsname (uname) information -- in character form */
	/* we do this so we don't have to include utsname.h         */
	/* plus it helps us be more architecture independent        */
	/* now maybe one day soon they'll make the [65] a #define!  */
	char	dh_utsname_sysname[65];
	char	dh_utsname_nodename[65];
	char	dh_utsname_release[65];
	char	dh_utsname_version[65];
	char	dh_utsname_machine[65];
	char	dh_utsname_domainname[65];

	/* the address of current task (OLD = void *, NEW = u64) */
	u64	dh_current_task;

	/* what type of compression we're using in this dump (if any) */
	u32	dh_dump_compress;

	/* any additional flags */
	u32	dh_dump_flags;

	/* any additional flags */
	u32	dh_dump_device;
} __attribute__((packed));

/*
 * Structure: __dump_page
 *  Function: To act as the header associated to each physical page of
 *            memory saved in the system crash dump.  This allows for
 *            easy reassembly of each crash dump page.  The address bits
 *            are split to make things easier for 64-bit/32-bit system
 *            conversions.
 *
 * dp_byte_offset and dp_page_index are landmarks that are helpful when
 * looking at a hex dump of /dev/vmdump,
 */
struct __dump_page {
	/* the address of this dump page */
	u64	dp_address;

	/* the size of this dump page */
	u32	dp_size;

	/* flags (currently DUMP_COMPRESSED, DUMP_RAW or DUMP_END) */
	u32	dp_flags;
} __attribute__((packed));

/*
 * Structure: __lkcdinfo
 * Function:  This structure contains information needed for the lkcdutils
 *            package (particularly lcrash) to determine what information is
 *            associated to this kernel, specifically.
 */
struct __lkcdinfo {
	int	arch;
	int	ptrsz;
	int	byte_order;
	int	linux_release;
	int	page_shift;
	int	page_size;
	u64	page_mask;
	u64	page_offset;
	int	stack_offset;
};
