/*
* This file contains the device dependent part of an experimental disk
* and tape driver for the Adaptec 154x SCSI Host Adapter family, written
* by James da Silva (jds@cs.umd.edu).
*
* I wrote this driver using the technical documentation for the AHA available
* from the Adaptec BBS at 1-408-945-7727, and from the SCSI standard drafts
* available on NCR's SCSI BBS at 1-316-636-8700. I suggest you get both
* these documents if you want to understand and hack this code.
*
* This code has been extensively modified by Kees J. Bot (kjb@cs.vu.nl) to
* a point that James will barely recognize it as his. It is completely
* remodeled and doubled in both size and functionality. It is no longer
* considered experimental either.
*
* The supported device numbers are as follows:
* # Name Device
* 0 sd0 disk 0, entire disk
* 1 sd1 disk 0, partition 1
* 2 sd2 disk 0, partition 2
* 3 sd3 disk 0, partition 3
* 4 sd4 disk 0, partition 4
* 5 sd5 disk 1, entire disk
* 6 sd6 disk 1, partition 1
* .. .... ....
* 39 sd39 disk 7, partition 4
*
* 64 nrst0 tape 0, no rewind
* 65 rst0 tape 0, rewind
* 66 nrst1 tape 1, no rewind
* .. .... ....
* 79 rst7 tape 7, rewind
*
* 128 sd1a disk 0, partition 1, subpartition 1
* 129 sd1b disk 0, partition 1, subpartition 2
* ... .... ....
* 255 sd39d disk 7, partition 4, subpartition 4
*
* The translation of device numbers to targets and logical units is very
* simple: The target is the same as the disk or tape number, the logical
* unit is always zero. Devices with logical unit numbers other then zero
* are virtually extinct. If you happen to have such a dinosaur device,
* then you can reprogram (e.g.) sd35 and st7 to target 0, lun 1 from the
* Boot Monitor with 'sd35=0,1'.
*
*
* The file contains one entry point:
*
* aha_scsi_task: main entry when system is brought up
*
*
* Changes:
* 5 May 1992 by Kees J. Bot: device dependent/independent split.
* 7 Jul 1992 by Kees J. Bot: speedup & features.
* 28 Dec 1992 by Kees J. Bot: completely remodeled & virtual memory.
* 18 Sep 1994 by Kees J. Bot: removed "send 2 commands at once" junk.
*/
#include "kernel.h"
#include "driver.h"
#include "drvlib.h"
#if ENABLE_ADAPTEC_SCSI
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include "assert.h"
INIT_ASSERT
#ifndef AHA_DEBUG
#define AHA_DEBUG 0 /* 1=print all SCSI errors | 2=dump ccb
* 4=show request | 8=dump scsi cmd
*/
#endif
/* AHA-154x port addresses */
#define AHA_BASEREG 0x330 /* default base port address of AHA registers */
#define AHA_CNTLREG aha_basereg+0 /* Control Register - write only */
#define AHA_STATREG aha_basereg+0 /* Status Register - read only */
#define AHA_DATAREG aha_basereg+1 /* Data Register - read/write */
#define AHA_INTRREG aha_basereg+2 /* Interrupt Flags - read only */
/* control register bits */
#define AHA_HRST 0x80 /* bit 7 - Hard Reset */
#define AHA_SRST 0x40 /* bit 6 - Soft Reset */
#define AHA_IRST 0x20 /* bit 5 - Interrupt Reset */
#define AHA_SCRST 0x10 /* bit 4 - SCSI Bus Reset */
/* 0x08 * bit 3 - Reserved (set to 0) */
/* 0x04 * bit 2 - Reserved (set to 0) */
/* 0x02 * bit 1 - Reserved (set to 0) */
/* 0x01 * bit 0 - Reserved (set to 0) */
/* status register bits */
#define AHA_STST 0x80 /* bit 7 - Self Test in Progress */
#define AHA_DIAGF 0x40 /* bit 6 - Internal Diagnostic Failure */
#define AHA_INIT 0x20 /* bit 5 - Mailbox Initialization Required */
#define AHA_IDLE 0x10 /* bit 4 - SCSI Host Adapter Idle */
#define AHA_CDF 0x08 /* bit 3 - Command/Data Out Port Full */
#define AHA_DF 0x04 /* bit 2 - Data In Port Full */
/* 0x02 * bit 1 - Reserved */
#define AHA_INVDCMD 0x01 /* bit 0 - Invalid Host Adapter Command */
/* interrupt flags register bits */
#define AHA_ANYINT 0x80 /* bit 7 - Any Interrupt */
/* 0x40 * bit 6 - Reserved */
/* 0x20 * bit 5 - Reserved */
/* 0x10 * bit 4 - Reserved */
#define AHA_SCRD 0x08 /* bit 3 - SCSI Reset Detected */
#define AHA_HACC 0x04 /* bit 2 - Host Adapter Command Complete */
#define AHA_MBOE 0x02 /* bit 1 - Mailbox Out Empty */
#define AHA_MBIF 0x01 /* bit 0 - Mailbox In Full */
/* AHA board models */
#define AHA1540 0x30
#define AHA1540A 0x41
#define AHA1640 0x42
#define AHA1740 0x43
#define AHA1540C 0x44
#define AHA1540CF 0x45
#define BT545 0x20 /* BusLogic */
/* AHA Command Codes */
#define AHACOM_INITBOX 0x01 /* Mailbox Initialization */
#define AHACOM_STARTSCSI 0x02 /* Start SCSI Command */
#define AHACOM_HAINQUIRY 0x04 /* Host Adapter Inquiry */
#define AHACOM_SETIMEOUT 0x06 /* Set SCSI selection time out value */
#define AHACOM_BUSON 0x07 /* Set DMA bus on time */
#define AHACOM_BUSOFF 0x08 /* Set DMA bus off time */
#define AHACOM_SPEED 0x09 /* Set DMA transfer speed */
#define AHACOM_INSTALLED 0x0A /* Return Installed Devices */
#define AHACOM_GETCONFIG 0x0B /* Return Configuration Data */
#define AHACOM_GETSETUP 0x0D /* Return Setup Data */
#define AHACOM_EXTBIOS 0x28 /* Return Extended BIOS Info */
#define AHACOM_MBOX_ENABLE 0x29 /* Enable Mailbox Interface */
/* AHA Mailbox Out Codes */
#define AHA_MBOXFREE 0x00 /* Mailbox is Free */
#define AHA_MBOXSTART 0x01 /* Start Command */
#define AHA_MBOXABORT 0x02 /* Abort Command */
/* AHA Mailbox In Codes */
#define AHA_MBOXOK 0x01 /* Command Completed Successfully */
#define AHA_MBOXERR 0x04 /* Command Completed with Error */
/* Basic types */
typedef unsigned char byte;
typedef byte big16[2]; /* 16 bit big-endian values */
typedef byte big24[3]; /* AHA uses 24 bit, big-endian values! */
typedef byte big32[4]; /* Group 1 SCSI commands use 32 bit big-endian values */
/* AHA Mailbox structure */
typedef struct {
byte status; /* Command or Status byte */
big24 ccbptr; /* pointer to Command Control Block */
} mailbox_t;
/* SCSI Group 0 Command Descriptor Block structure */
typedef union {
struct { /* Disk i/o commands */
byte d_scsi_op; /* SCSI Operation Code */
# define SCSI_UNITRDY 0x00 /* Test Unit Ready */
# define SCSI_REWIND 0x01 /* Rewind */
# define SCSI_REQSENSE 0x03 /* Request sense */
# define SCSI_RDLIMITS 0x05 /* Read Block Limits Opcode */
# define SCSI_READ 0x08 /* Group 0 Read Opcode */
# define SCSI_WRITE 0x0A /* Group 0 Write Opcode */
# define SCSI_WREOF 0x10 /* Write File Marks */
# define SCSI_SPACE 0x11 /* Space over filemarks/blocks */
# define SCSI_INQUIRY 0x12 /* Group 0 Inquiry Opcode */
# define SCSI_MDSELECT 0x15 /* Group 0 Mode Select Opcode */
# define SCSI_ERASE 0x19 /* Erase Tape */
# define SCSI_MDSENSE 0x1A /* Group 0 Mode Sense Opcode */
# define SCSI_STRTSTP 0x1B /* Start/Stop */
# define SCSI_LOADUNLD 0x1B /* Load/Unload */
big24 d_lba; /* LUN and logical block address */
byte d_nblocks; /* Transfer size in blocks */
byte d_control; /* Reserved and link bit fields, set to 0 */
} d;
struct { /* Tape i/o commands */
byte t_scsi_op; /* SCSI Operation Code */
byte t_fixed; /* Fixed length? */
big24 t_trlength; /* Transfer length */
byte t_control; /* reserved and link bit fields, set to 0 */
} t;
} cdb0_t;
#define scsi_op d.d_scsi_op
#define lba d.d_lba
#define nblocks d.d_nblocks
#define fixed t.t_fixed
#define trlength t.t_trlength
#define control d.d_control
/* SCSI Group 1 Command Descriptor Block structure */
typedef union {
struct { /* Disk i/o commands */
byte d_scsi_op; /* SCSI Operation Code */
# define SCSI_CAPACITY 0x25 /* Read Capacity */
# define SCSI_READ1 0x28 /* Group 1 Read Opcode */
# define SCSI_WRITE1 0x2A /* Group 1 Write Opcode */
byte d_lunra; /* LUN etc. */
big32 d_lba; /* Logical Block Address */
byte reserved;
big16 d_nblocks; /* transf
评论1
最新资源