	/*
	 * Copyright c 1987 Lee C. Erickson.  All rights reserved.
	 */

/* scsidev.h -- scsi device */

#ifndef SCSIDEV_H
#define SCSIDEV_H
#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif
#ifndef EXEC_NODES_H
#include <exec/nodes.h>
#endif
#ifndef EXEC_RESIDENT_H
#include <exec/resident.h>
#endif
#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif
#ifndef EXEC_DEVICES_H
#include <exec/devices.h>
#endif
#ifndef EXEC_IO_H
#include <exec/io.h>
#endif

#define MYPRI   10
#define MYNAME	"scsidev.device"
#define MYID	"scsidev 1.1.6(16 July 1988)\r\n"
#define MY_SCSI_ID	7	/* This is SCSI unit 7			*/
typedef LONG (*PFL)();		/* pointer to function returning 32-bit int*/
#define NUM_OF_PARTITIONS 7	/* Maximum number of partitions auto-mounted*/

struct extd_task {
	struct Task tsk ;
	struct MsgPort m_port ;
	int		stat ;
} ;

#define SENSE_VALID	0x80
#define SENSE_KEY_MASK	0x0F
struct sense_data {
    unsigned char	error_code;
    unsigned char	segment_no;
    unsigned char	sense_key;
    unsigned char	info_byte0;
    unsigned char	info_byte1;
    unsigned char	info_byte2;
    unsigned char	info_byte3;
    unsigned char	add_sense_length;
    unsigned char	cyl_high;
    unsigned char	cyl_low;
    unsigned char	head;
    unsigned char	sector;
    unsigned char	add_sense_code;
} ;

/* Device initialization table, used for AUTOINIT devices	      */
struct InitTable {
	ULONG	it_DataSize;	/* library data space size	      */
	PFL	*it_FuncTable;	/* table of entry points 	      */
	APTR	it_DataInit;	/* table of data initializers	      */
	PFL	it_InitFunc;	/* initialization function to run     */
};

struct partition_data
{
	ULONG	unit;			/* AmigaDOS Unit #		*/
	ULONG	flags;			/* Driver flags, see below	*/
	ULONG	tablesize;		/* # of longwords to follow, 11	*/
	ULONG	blocksize;		/* Longwords in a block (512/4)	*/
	ULONG	sector_org;		/* Not used. "0"		*/
	ULONG	number_heads;		/* # of surfaces. For SCSI, "1"	*/
	ULONG	sectors_per_block;	/* Sectors per block. "1"	*/
	ULONG	reserved_blocks;	/* Reserved blocks. "2"		*/
	ULONG	prefac;			/* Unused			*/
	ULONG	interleave;		/* Interleave. "0"		*/
	ULONG	low_cylinder;		/* 1st cylinder in partition	*/
	ULONG	upper_cylinder;		/* Last cylinder in partition	*/
	ULONG	number_of_buffers;	/* # of buffers. Default 20.	*/
	ULONG	BufMemType;		/* BufMemType. "0" for Fast	*/
	char	partition_name[10];	/* Partition name, eg. "DH0"	*/
					/* If 0, this partition not used*/
	char	boot_priority;		/* BOOT priority		*/
};

struct boot_block
{
	ULONG	magic;			/* "0x2BADBABE" show good block	*/
	ULONG	num_partitions;		/* How many partitions exist	*/
	struct partition_data partitions[NUM_OF_PARTITIONS];
};

#define SD_MOTOR        (CMD_NONSTD+0)  /* NO-OP			*/
#define SD_SEEK         (CMD_NONSTD+1)  /* explicit seek (for testing)	*/
#define SD_FORMAT       (CMD_NONSTD+2)  /* format disk			*/
#define SD_REMOVE       (CMD_NONSTD+3)  /* NO-OP			*/
#define SD_CHANGENUM    (CMD_NONSTD+4)  /* NO-OP			*/
#define SD_CHANGESTATE  (CMD_NONSTD+5)  /* Drive ready?			*/
#define SD_PROTSTATUS   (CMD_NONSTD+6)  /* is the disk write protected?	*/
#define SD_RAWREAD      (CMD_NONSTD+7)  /* Illegal			*/
#define SD_RAWWRITE     (CMD_NONSTD+8)  /* Illegal			*/
#define SD_GETDRIVETYPE (CMD_NONSTD+9)  /* Illegal			*/
#define SD_GETNUMTRACKS (CMD_NONSTD+10) /* # of tracks for this type drive */
#define SD_ADDCHANGEINT (CMD_NONSTD+11) /* NO-OP			*/
#define SD_REMCHANGEINT (CMD_NONSTD+12) /* NO-OP			*/
/* 12 - 17 left incase others expand	*/
#define	SD_SCSI		(CMD_NONSTD+18)	/* Execute supplied SCSI command*/
#define SD_TEST_RDY	(CMD_NONSTD+19)	/* SCSI TEST UNIT READY command	*/
#define SD_START_UNIT	(CMD_NONSTD+20)	/* SCSI START UNIT command	*/
#define SD_SCSI_RESET	(CMD_NONSTD+21)	/* Reset SCSI bus		*/
#define SD_REQ_SENSE	(CMD_NONSTD+22)	/* Internal REQUEST SENSE cmd	*/
#define SD_REASSIGN_BLK	(CMD_NONSTD+23)	/* Internal REASSIGN BLOCKS cmd	*/
#define SD_LASTCOMM     (CMD_NONSTD+24)

/*
 *	IOStdReq format for explicit SCSI commands:
 *
 *	io_Command	-> SD_SCSI
 *	io_Flags(0)	-> Bit 0(high order) high means SEND data to SCSI device
 *	io_Flags(1:3)	<- SCSI LUN bits 1 thru 3
 *	io_Error	<- SCSI STATUS
 *	io_Actual	<- Number of bytes successfully transferred
 *	io_Length	-> Length of data to send/receive
 *	io_Data		-> Points to sent/received data
 *	io_Offset	-> Points to SCSI command block
 */

#define	SCSI_SEND		0x80
#define SDERR_NotSpecified      20      /* general catchall */
#define SDERR_NoSecHdr          21      /* couldn't even find a sector */
#define SDERR_BadSecPreamble    22      /* sector looked wrong */
#define SDERR_BadSecID          23      /* ditto */
#define SDERR_BadHdrSum         24      /* header had incorrect checksum */
#define SDERR_BadSecSum         25      /* data had incorrect checksum */
#define SDERR_BadSecHdr         27      /* another "sector looked wrong" */
#define SDERR_WriteProt         28      /* can't write to a protected disk */
#define SDERR_DiskChanged       29      /* no disk in the drive */
#define SDERR_SeekError         30      /* couldn't find track 0 */
#define SDERR_NoMem             31      /* ran out of memory */
#define SDERR_BadUnitNum        32      /* asked for a unit > NUMUNITS */
#define SDERR_BadDriveType      33      /* not a drive that trackdisk groks */
#define SDERR_Timeout		80	/* SCSI device didn't respond	*/
					/* 	in time			*/

#endif
