/*
 *	Copyright (c) 1986 by D.Friede & D.Konnerth
 */
/*
 * @(#)wn.h	1.0
 *
 *	LF Disk Controller Declarations. 
 * 
 * Programmer: Dieter Konnerth  7.86
 *
 */

#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long


#define WN_AUTOLAYOUT			/* if this is defined layout of */
					/* a disk is on the disk, else  */
					/* it is compiled into the kernel */

#define	SPL		 spl6		/* for driver mutex */
#define	WN_RETRY	  6		/* retry count */

#define	WN_MAXDRIVE	  3		/* # of drives */
#define WN_MAXPART	 16		/* # of partitions per drive */

#define WN_LAYOUTOFFSET  (256L*6L)	/* offset of layout info */
#define WN_LAYOUTMAGIC	 0x7997		/* magic number for valid layout info */

#define WN_SECSIZ	256L		/* real physical sectorsize, */
					/* only one size suported by hw */
#define WN_SECPTRACK	 46		/* 46 real sectors */
#define WN_PBSHIFT	  8
#define LPBOFFSET	  0L		/* offset of logical parameter block */

/*
 * Mapping of minor dev number to drive and partition
 *
 * minor number:    0ddppppp	
 *		      ^  ^
 *		      |	 |
 *		      |	 partition
 *		      drive number
 *
 */

#define	DRIVE(dev)	( (minor(dev) >> 5) & 0x03 )
#define	PART(dev)	( minor(dev) & 0x1f )
#define MINOR(drive,part) ( (drive << 5) | part)

/*
 * Partition structure.  One per wn_parttab[] entry.
 */

struct	wn_part {
	int p_parts;
	struct wn_partfield {
		daddr_t	p_fsec;			/* first  sector */
	        daddr_t	p_nsec;			/* number sectors  */
	} p_ptab[WN_MAXPART];
};

/*
 * Per device driver static data
 */

struct wn_devchar {
	int d_cylno;
	char d_heads; 
	char d_ontime;
	char d_offtime;
	int d_lowcurcyl;
	int d_precompcyl;
};

struct wn_ftk {
	int  f_track;
	struct { char f_badflg;
		 struct { char sbadflg,secno } f_maparr[WN_SECPTRACK];
	       } f_map;
};

/*
 * The following is the logical parameter block structure which resides
 * on sector 0, track 0 of all winchesters. Most of the fields are of no
 * use whatsoever, but that's whats out there and if ever you need to use
 * it then please do so.
 */

/*struct lpb {*/
/*	uint	LPBFlg;		/* LPB flag (0xFFC6 = 16 bit)*/
/*	uchar	LOff;		/* LPB offset value (default = 0x0b) */
/*	uchar	LSInt;		/* LPB sector interleave */
/*	uint	Unusd1;		/* LPB execution address */
/*	uint	Unusd2;		/* LPB load segment address */
/*	uint	Unusd3;		/* LPB load offset address */
/*	uint	Unusd4;		/* LPB number of bytes to load */
/*	uint	OSTrack;	/* LPB O/S load track */
/*	uint	OSSector;	/* LPB O/S load sector */
/*	uchar	Unusd5[10];	/* Reserved bytes */
/*	uint	LBPS;		/* LPB bytes per sector*/
/*	uchar	LHeads;		/* LPB number of heads */
/*	uint	LSPT;		/* LPB sectors per track */
/*	uint	LCyls;		/* LPB number of cylinders */
/*	uchar	Unusd6[23];	/* Reserved bytes */
/*	uchar	OnTime;		/* FIRMWARE On load time */
/*	uint	OffTime;	/* FIRMWARE off load time */
/*	uchar	Heads;		/* FIRMWARE number of heads */
/*	uint	Cylinders;	/* FIRMWARE number of cylinders */
/*	uint	LCCyl;		/* FIRMWARE low current cylinder */
/*	uint	PCCyl;		/* FIRMWARE precomp cylinders */
/*	uint	Wcode;		/* LPB winchester code (set to 0x464C, 'LF') */
/*	uchar	Partition;	/* LPB partitioning byte */
/*	uchar	PartInfo[32];	/* LPB 32 bytes of partiton info */
/*	uchar	Unusd7[27];	/* Reserved bytes */
/*	uchar	RestrkInfo[128];/* LPB 128 bytes of restrk info */
/*	};*/

/*
 * Per board driver "dynamic" data.
 */

/*
 * Per-Unit State Flags.
 */

#define	SF_OPEN		0x01	/* unit is open   */
#define	SF_READY	0x02	/* unit is ready (i.e. open and formatted) */
#define SF_EXISTS	0x04	/* unit exists    */

/*
 * Controller opcodes
 */

#define WN_NOOP		-1
#define WN_READ         0
#define	WN_WRITE	1
#define	WN_SEEK		2
#define	WN_FORMAT	3
#define	WN_READY	4
#define	WN_PASCAR	5
#define	WN_RECAL	6
#define	WN_TRIES	7

#define WN_INIT		5		/* no real opcode, it is send to */
					/* syncport */
/*
 * Errors returned to user 
 * Error byte 1 is high byte, byte 2 is low byte
 */

#define	WN_NOSEC 	0xA000	/* sector not found */
#define	WN_NODATA	0x9000	/* data address mark not found */
#define	WN_ALTFULL      0x8800	/* alternate sector table full */
#define	WN_HARD		0x8400	/* hardware fault */
#define WN_DATAERR	0x8200  /* data error */
#define WN_NOUNIT	0x8040  /* unit doesn't exist */
#define WN_NOTFORMAT	0x8020  /* unit not formatted */
#define WN_NOTREADY	0x8010  /* unit not ready */
#define WN_NOCMD	0x8080	/* command error */
#define WN_BUFOVFL	0x7000  /* buffer overflow */
#define WN_BUFUNFL	0x7010  /* buffer underflow */
#define WN_NOERROR	0x0000  /* successful operation */ 


/* 
 *
 * Addresses of controller ports
 *
 */

#define WN_CMDPORT	0x0380	/* command/data/status port  */
#define WN_SYNCPORT     0x0382	/* handshake port */

/* 
 * Bits used for handshake with controller
 */

#define WN_CMDBUSY	0x02	/* command not yet retrieved by controller */
#define WN_STATREADY    0x01	/* status byte available */


struct wn_dskblck {
	ulong	addr;
	ulong	secno;
	uint	blocks;
	uint	actblks;
	uint	unit;
	int	func;
	unsigned status;
} ;
