#ifndef	XETEC_SCSI_H
#define	XETEC_SCSI_H
#ifndef	EXEC_TYPES_H
#include	"exec/types.h"
#endif
#ifndef	EXEC_LIBRARIES_H
#include	"exec/libraries.h"
#endif
#ifndef	EXEC_PORTS_H
#include	"exec/ports.h"
#endif
#ifndef	EXEC_DEVICES_H
#include	"exec/devices.h"
#endif

/***************************************************************\
*         TM							*
* FastTrak       header file					*
*								*
* Marty Flickinger                              March 16, 1988  *
*								*
* Copyright (c) 1988, 1989  Xetec, Inc.				*
\***************************************************************/


#define	XETECDEVNAME	"harddisk.device"

#define	MANUFAC		2022	/* Xetec Manufacturer ID */
#define FASTTRAK	1	/* FastTrak/FastCard SCSI controller */
#define	FASTCARDPLUS	3	/* FastCard plus SCSI controller */


/*------ SCSI bus command types-----*/

#define	SCSI_TUR	0
#define	SCSI_Check	3
#define	SCSI_Read	8
#define	SCSI_Write	0xA
#define	SCSI_Seek	0xB
#define	SCSI_ExtRead	0x28
#define	SCSI_ExtWrite	0x2A

#define	MD_NUMUNITS	16	/* Maximum number of units */
#define	MYPROCSTACKSIZE	2048	/* Stack size */

/*---------------------------------------------------------------------*\
;									;
; Device command definitions						;
;									;
\*---------------------------------------------------------------------*/

#define	CMD_MOTOR		9
#define	CMD_SEEK		10
#define	CMD_FORMAT		11
#define	CMD_REMOVE		12
#define	CMD_CHANGENUM		13
#define	CMD_CHANGESTATE		14
#define	CMD_PROTSTATUS		15
#define	CMD_RAWREAD		16
#define	CMD_RAWWRITE		17
#define	CMD_GETDRIVETYPE	18
#define	CMD_GETNUMTRACKS	19
#define	CMD_ADDCHANGEINT	20
#define	CMD_REMCHANGEINT	21
#define	CMD_Undef1		22
#define	CMD_Undef2		23
#define	CMD_Undef3		24
#define	CMD_SCSIFLAGS		25
#define	CMD_REQSENSE		26
#define	CMD_TUR			27
#define	CMD_SCSI		28


/*---------------------------------------------------------------------*\
;									;
; Device data structure                                                 ;
;									;
\*---------------------------------------------------------------------*/

struct   XetecDevice {
	struct	Library	md_lib;
	UBYTE	md_Flags;
	UBYTE	md_SCSIid;		/* SCSI id (0 - 7) */
	ULONG	md_SysLib;		/* Exec Base */
	ULONG	md_SegList;
	ULONG	md_Base;		/* Base address of my host adaptor */
	ULONG	md_Base2;		/* Second Xetec host adaptor */
	ULONG	md_ConfigDev;		/* Next 4: my copy of CurrentBinding */
	ULONG	md_FileName;
	ULONG	md_ProductString;
	ULONG	md_ToolTypes;
	ULONG	md_UnitJunk[17];	/* Many units, don't access from C */
	ULONG	md_UnitFlags;		/* Special flags for each unit */
};

#ifndef  	DEVICES_SCSIDISK_H

struct	SCSICmd {
	UWORD	*scsi_Data;	/* word aligned data for SCSI Data Phase */
	ULONG	scsi_Length;	/* even length of Data area */
	ULONG	scsi_Actual;	/* actual Data used */
	UBYTE	*scsi_Command;	/* SCSI Command (same options as scsi_Data) */
	UWORD	scsi_CmdLength;	/* length of Command */
	UWORD	scsi_CmdActual;	/* actual Command used */
	UBYTE	scsi_Flags;	/* includes intended data direction */
	UBYTE	scsi_Status;	/* SCSI status of command */
	UBYTE	*scsi_SenseData;    /* Pointer to buffer for request sense */
	UWORD	scsi_SenseLength;   /* And its length */ 
	UWORD	scsi_SenseActual;   /* ReqSense actually read */
};

#define	SCSIF_WRITE	0	/* intended data direction is out */
#define SCSIF_READ	1	/* intended data direction is in */
#define	SCSIF_NOSENSE		0
#define	SCSIF_AUTOSENSE		2
#define	SCSIF_OLDAUTOSENSE	6
#define	SCSIF_DMAX      	64

/*------ IO_ERROR values ------*/
#define	FTERR_SelfUnit		40	/* cannot issue SCSI command to self */
#define FTERR_DMA		41	/* DMA error */
#define FTERR_Phase		42	/* illegal or unexpected SCSI phase */
#define FTERR_Parity		43	/* SCSI parity error */
#define FTERR_SelTimeout	44	/* Select timed out */
#define FTERR_BadStatus		45	/* status and/or sense error */
#define FTERR_NoBoard		50	/* Open failed for non-existant board */

#endif

#define  READ  1
#define  WRITE 0

#define SENSEINFO_VALID 0x80
#define SENSE_KEY_MASK  0x0F

struct sense_data {
   UBYTE error_code;
   UBYTE segment_num;
   UBYTE sense_key;
   UBYTE info_byte0;
   UBYTE info_byte1;
   UBYTE info_byte2;
   UBYTE info_byte3;
   UBYTE add_sense_length;
   UBYTE cyl_high;
   UBYTE cyl_low;
   UBYTE head;
   UBYTE sector;
   UBYTE add_sense_code;
   UBYTE reserved;
   UBYTE fru_failed;
   UBYTE flags;
   UWORD field_ptr;
};

#endif
