1993-06-12 14:58:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Ported for use with the UltraStor 14f by Gary Close (gclose@wvnvms.wvnet.edu)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* Slight fixes to timeouts to run with the 34F
|
1993-06-12 14:58:17 +00:00
|
|
|
|
* Thanks to Julian Elischer for advice and help with this port.
|
|
|
|
|
*
|
|
|
|
|
* Written by Julian Elischer (julian@tfs.com)
|
|
|
|
|
* for TRW Financial Systems for use under the MACH(2.5) operating system.
|
|
|
|
|
*
|
|
|
|
|
* TRW Financial Systems, in accordance with their agreement with Carnegie
|
|
|
|
|
* Mellon University, makes this software available to CMU to distribute
|
|
|
|
|
* or use in any manner that they see fit as long as this message is kept with
|
|
|
|
|
* the software. For this reason TFS also grants any other persons or
|
|
|
|
|
* organisations permission to use or modify this software.
|
|
|
|
|
*
|
|
|
|
|
* TFS supplies this software to be publicly redistributed
|
|
|
|
|
* on the understanding that TFS is not responsible for the correct
|
|
|
|
|
* functioning of this software in any circumstances.
|
|
|
|
|
*
|
1993-08-20 09:21:40 +00:00
|
|
|
|
* commenced: Sun Sep 27 18:14:01 PDT 1992
|
1993-07-22 00:56:23 +00:00
|
|
|
|
* slight mod to make work with 34F as well: Wed Jun 2 18:05:48 WST 1993
|
1993-08-21 20:01:59 +00:00
|
|
|
|
*
|
1994-08-19 00:32:52 +00:00
|
|
|
|
* today: Fri Jun 2 17:21:03 EST 1994
|
|
|
|
|
* added 24F support ++sg
|
|
|
|
|
*
|
1997-09-21 21:41:49 +00:00
|
|
|
|
* $Id: ultra14f.c,v 1.56 1997/09/07 04:21:25 bde Exp $
|
1993-06-12 14:58:17 +00:00
|
|
|
|
*/
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
#ifdef KERNEL /* don't laugh.. this compiles to a program too.. look */
|
1996-10-15 19:22:46 +00:00
|
|
|
|
#include "uha.h"
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#include <sys/malloc.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
#include <sys/buf.h>
|
1997-09-07 04:21:25 +00:00
|
|
|
|
#include <sys/kernel.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1995-03-16 18:17:34 +00:00
|
|
|
|
#include <machine/clock.h>
|
|
|
|
|
|
1995-12-06 23:52:35 +00:00
|
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
|
#include <vm/pmap.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
#include <i386/isa/isa_device.h>
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#endif /*KERNEL */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
#include <scsi/scsiconf.h>
|
1997-03-23 06:33:55 +00:00
|
|
|
|
#include <scsi/scsi_debug.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1997-03-23 04:40:00 +00:00
|
|
|
|
#include "ioconf.h"
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/* */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1994-08-27 16:14:39 +00:00
|
|
|
|
#ifndef KERNEL
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define NUHA 1
|
|
|
|
|
#endif /*KERNEL */
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
unsigned char addr[4];
|
|
|
|
|
} physaddr;
|
|
|
|
|
typedef struct {
|
|
|
|
|
unsigned char len[4];
|
|
|
|
|
} physlen;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define KVTOPHYS(x) vtophys(x)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_MSCP_MAX 32 /* store up to 32MSCPs at any one time
|
|
|
|
|
* MAX = ?
|
|
|
|
|
*/
|
|
|
|
|
#define MSCP_HASH_SIZE 32 /* when we have a physical addr. for
|
|
|
|
|
* a mscp and need to find the mscp in
|
|
|
|
|
* space, look it up in the hash table
|
|
|
|
|
*/
|
|
|
|
|
#define MSCP_HASH_SHIFT 9 /* only hash on multiples of 512 */
|
|
|
|
|
#define MSCP_HASH(x) ((((long int)(x))>>MSCP_HASH_SHIFT) % MSCP_HASH_SIZE)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_NSEG 33 /* number of dma segments supported */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
/************************** board definitions *******************************/
|
1996-01-15 16:15:27 +00:00
|
|
|
|
struct uha_reg
|
1994-08-19 00:32:52 +00:00
|
|
|
|
{
|
|
|
|
|
int id; /* product id reg */
|
|
|
|
|
int type; /* product type reg */
|
|
|
|
|
int ectl; /* EISA expansion control bits */
|
|
|
|
|
int config; /* configuration bits */
|
|
|
|
|
int lmask; /* local doorbell mask reg */
|
|
|
|
|
int lint; /* local doorbell int/stat reg */
|
|
|
|
|
int smask; /* system doorbell mask reg */
|
|
|
|
|
int sint; /* system doorbell int/stat reg */
|
|
|
|
|
int ogmcmd; /* outgoing mail command */
|
|
|
|
|
int ogmptr; /* outgoing mail ptr */
|
|
|
|
|
int icmcmd; /* incoming mail command */
|
|
|
|
|
int icmptr; /* incoming mail ptr */
|
1996-01-15 16:15:27 +00:00
|
|
|
|
};
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
1996-01-15 16:15:27 +00:00
|
|
|
|
struct uha_bits
|
1994-08-19 00:32:52 +00:00
|
|
|
|
{
|
|
|
|
|
/* uha_lint (read) */
|
|
|
|
|
unsigned char ldip;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
/* uha_lint (write) */
|
|
|
|
|
unsigned char adrst;
|
|
|
|
|
unsigned char sbrst;
|
|
|
|
|
unsigned char asrst;
|
|
|
|
|
unsigned char abort;
|
|
|
|
|
unsigned char ogmint;
|
|
|
|
|
|
|
|
|
|
/* uha_sint (read) */
|
|
|
|
|
unsigned char sintp;
|
|
|
|
|
unsigned char abort_succ;
|
|
|
|
|
unsigned char abort_fail;
|
|
|
|
|
|
|
|
|
|
/* uha_sint (write) */
|
|
|
|
|
unsigned char abort_ack;
|
|
|
|
|
unsigned char icm_ack;
|
1996-01-15 16:15:27 +00:00
|
|
|
|
};
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_LINT bits (read)
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_LDIP 0x80 /* local doorbell int pending */
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define U24_LDIP 0x02
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_LINT bits (write)
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_ADRST 0x40 /* adapter soft reset */
|
|
|
|
|
#define UHA_SBRST 0x20 /* scsi bus reset */
|
|
|
|
|
#define UHA_ASRST 0x60 /* adapter and scsi reset */
|
|
|
|
|
#define UHA_ABORT 0x10 /* abort MSCP */
|
|
|
|
|
#define UHA_OGMINT 0x01 /* tell adapter to get mail */
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define U24_SBRST 0x40 /* scsi bus reset */
|
|
|
|
|
#define U24_ADRST 0x80 /* adapter soft reset */
|
|
|
|
|
#define U24_ASRST 0xc0 /* adapter and scsi reset */
|
|
|
|
|
#define U24_ABORT 0x10 /* same? */
|
|
|
|
|
#define U24_OGMINT 0x02 /* enable OGM interrupt */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_SMASK bits (read)
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_SINTEN 0x80 /* system doorbell interupt Enabled */
|
|
|
|
|
#define UHA_ABORT_COMPLETE_EN 0x10 /* abort MSCP command complete int Enabled */
|
|
|
|
|
#define UHA_ICM_ENABLED 0x01 /* ICM interrupt enabled */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_SMASK bits (write)
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_ENSINT 0x80 /* enable system doorbell interrupt */
|
|
|
|
|
#define UHA_EN_ABORT_COMPLETE 0x10 /* enable abort MSCP complete int */
|
|
|
|
|
#define UHA_ENICM 0x01 /* enable ICM interrupt */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_SINT bits (read)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define UHA_SINTP 0x80 /* system doorbell int pending */
|
|
|
|
|
#define UHA_ABORT_SUCC 0x10 /* abort MSCP successful */
|
|
|
|
|
#define UHA_ABORT_FAIL 0x18 /* abort MSCP failed */
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define U24_SINTP 0x02 /* system doorbell int pending */
|
|
|
|
|
#define U24_ABORT_SUCC 0x10 /* same? */
|
|
|
|
|
#define U24_ABORT_FAIL 0x18 /* same? */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* UHA_SINT bits (write)
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#define UHA_ABORT_ACK 0x18 /* acknowledge status and clear */
|
|
|
|
|
#define UHA_ICM_ACK 0x01 /* acknowledge ICM and clear */
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define U24_ABORT_ACK 0x18 /* same */
|
|
|
|
|
#define U24_ICM_ACK 0x02 /* 24F acknowledge ICM and clear */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
/*
|
1993-11-18 05:03:27 +00:00
|
|
|
|
* UHA_CONF1 bits (read only)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define UHA_DMA_CH5 0x00 /* DMA channel 5 */
|
|
|
|
|
#define UHA_DMA_CH6 0x40 /* 6 */
|
|
|
|
|
#define UHA_DMA_CH7 0x80 /* 7 */
|
|
|
|
|
#define UHA_IRQ15 0x00 /* IRQ 15 */
|
|
|
|
|
#define UHA_IRQ14 0x10 /* 14 */
|
|
|
|
|
#define UHA_IRQ11 0x20 /* 11 */
|
|
|
|
|
#define UHA_IRQ10 0x30 /* 10 */
|
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define EISA_CONFIG 0x0c80 /* Configuration base port */
|
|
|
|
|
#define EISA_DISABLE 0x01 /* EISA disable bit */
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* ha_status error codes
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define UHA_NO_ERR 0x00 /* No error supposedly */
|
|
|
|
|
#define UHA_SBUS_ABORT_ERR 0x84 /* scsi bus abort error */
|
|
|
|
|
#define UHA_SBUS_TIMEOUT 0x91 /* scsi bus selection timeout */
|
|
|
|
|
#define UHA_SBUS_OVER_UNDER 0x92 /* scsi bus over/underrun */
|
|
|
|
|
#define UHA_BAD_SCSI_CMD 0x96 /* illegal scsi command */
|
|
|
|
|
#define UHA_AUTO_SENSE_ERR 0x9b /* auto request sense err */
|
|
|
|
|
#define UHA_SBUS_RES_ERR 0xa3 /* scsi bus reset error */
|
|
|
|
|
#define UHA_BAD_SG_LIST 0xff /* invalid scatter gath list */
|
|
|
|
|
|
|
|
|
|
struct uha_dma_seg {
|
|
|
|
|
physaddr addr;
|
|
|
|
|
physlen len;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp {
|
|
|
|
|
unsigned char opcode:3;
|
|
|
|
|
#define U14_HAC 0x01 /* host adapter command */
|
|
|
|
|
#define U14_TSP 0x02 /* target scsi pass through command */
|
|
|
|
|
#define U14_SDR 0x04 /* scsi device reset */
|
|
|
|
|
unsigned char xdir:2; /* xfer direction */
|
|
|
|
|
#define U14_SDET 0x00 /* determined by scsi command */
|
|
|
|
|
#define U14_SDIN 0x01 /* scsi data in */
|
|
|
|
|
#define U14_SDOUT 0x02 /* scsi data out */
|
|
|
|
|
#define U14_NODATA 0x03 /* no data xfer */
|
|
|
|
|
unsigned char dcn:1; /* disable disconnect for this command */
|
|
|
|
|
unsigned char ca:1; /* cache control */
|
|
|
|
|
unsigned char sgth:1; /* scatter gather flag */
|
|
|
|
|
unsigned char target:3;
|
|
|
|
|
unsigned char chan:2; /* scsi channel (always 0 for 14f) */
|
|
|
|
|
unsigned char lun:3;
|
|
|
|
|
physaddr data;
|
|
|
|
|
physlen datalen;
|
|
|
|
|
physaddr link;
|
|
|
|
|
unsigned char link_id;
|
|
|
|
|
unsigned char sg_num; /*number of scat gath segs */
|
|
|
|
|
/*in s-g list if sg flag is */
|
|
|
|
|
/*set. starts at 1, 8bytes per */
|
|
|
|
|
unsigned char senselen;
|
|
|
|
|
unsigned char cdblen;
|
|
|
|
|
unsigned char cdb[12];
|
|
|
|
|
unsigned char ha_status;
|
|
|
|
|
unsigned char targ_status;
|
|
|
|
|
physaddr sense; /* if 0 no auto sense */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
/*-----------------end of hardware supported fields----------------*/
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *next; /* in free list */
|
|
|
|
|
struct scsi_xfer *xs; /* the scsi_xfer for this cmd */
|
|
|
|
|
int flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
#define MSCP_FREE 0
|
|
|
|
|
#define MSCP_ACTIVE 1
|
|
|
|
|
#define MSCP_ABORTED 2
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct uha_dma_seg uha_dma[UHA_NSEG];
|
|
|
|
|
struct scsi_sense_data mscp_sense;
|
|
|
|
|
struct mscp *nexthash;
|
|
|
|
|
long int hashkey;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
|
static struct uha_data {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
int flags;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
#define UHA_INIT 0x01
|
|
|
|
|
#define UHA_24F 0x02
|
1996-01-07 19:22:39 +00:00
|
|
|
|
int baseport;
|
|
|
|
|
struct mscp *mscphash[MSCP_HASH_SIZE];
|
|
|
|
|
struct mscp *free_mscp;
|
|
|
|
|
int unit;
|
|
|
|
|
int our_id; /* our scsi id */
|
|
|
|
|
int vect;
|
|
|
|
|
int dma;
|
|
|
|
|
int nummscps;
|
|
|
|
|
struct scsi_link sc_link;
|
|
|
|
|
struct uha_reg *ur;
|
|
|
|
|
struct uha_bits *ub;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} *uhadata[NUHA];
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
static int uha_abort __P((struct uha_data *uha, struct mscp *mscp));
|
1996-03-10 07:04:48 +00:00
|
|
|
|
static u_int32_t uha_adapter_info __P((int unit));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
static int uha_attach __P((struct isa_device *dev));
|
1996-01-07 19:22:39 +00:00
|
|
|
|
static void uha_done __P((struct uha_data *uha, struct mscp *mscp));
|
|
|
|
|
static void uha_free_mscp __P((struct uha_data *uha, struct mscp *mscp,
|
|
|
|
|
int flags));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
static struct mscp *
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_get_mscp __P((struct uha_data *uha, int flags));
|
|
|
|
|
static int uha_init __P((struct uha_data *uha));
|
|
|
|
|
static int uha24_init __P((struct uha_data *uha));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
static void uhaminphys __P((struct buf *bp));
|
|
|
|
|
static struct mscp *
|
|
|
|
|
uha_mscp_phys_kv __P((struct uha_data *uha, long mscp_phys));
|
1996-01-07 19:22:39 +00:00
|
|
|
|
static int uha_poll __P((struct uha_data *uha, int wait));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
#ifdef UHADEBUG
|
1996-01-07 19:22:39 +00:00
|
|
|
|
static void uha_print_active_mscp __P((struct uha_data *uha));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
static void uha_print_mscp __P((struct mscp *mscp));
|
|
|
|
|
#endif
|
|
|
|
|
static int uhaprobe __P((struct isa_device *dev));
|
1996-03-10 07:04:48 +00:00
|
|
|
|
static int32_t uha_scsi_cmd __P((struct scsi_xfer *xs));
|
1996-01-07 19:22:39 +00:00
|
|
|
|
static void uha_send_mbox __P((struct uha_data *uha, struct mscp *mscp));
|
1995-12-15 00:11:27 +00:00
|
|
|
|
static timeout_t
|
|
|
|
|
uha_timeout;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1995-07-25 15:53:11 +00:00
|
|
|
|
static struct mscp *cheat;
|
1995-12-10 13:40:44 +00:00
|
|
|
|
static unsigned long int scratch;
|
1995-03-23 09:00:20 +00:00
|
|
|
|
#define EISA_MAX_SLOTS 16 /* XXX This should go into a comon header */
|
|
|
|
|
static uha_slot = 0; /* slot last board was found in */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
static uha_unit = 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
#define UHA_SHOWMSCPS 0x01
|
|
|
|
|
#define UHA_SHOWINTS 0x02
|
|
|
|
|
#define UHA_SHOWCMDS 0x04
|
|
|
|
|
#define UHA_SHOWMISC 0x08
|
|
|
|
|
#define FAIL 1
|
|
|
|
|
#define SUCCESS 0
|
|
|
|
|
#define PAGESIZ 4096
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#ifdef KERNEL
|
|
|
|
|
struct isa_driver uhadriver =
|
|
|
|
|
{
|
|
|
|
|
uhaprobe,
|
|
|
|
|
uha_attach,
|
|
|
|
|
"uha"
|
|
|
|
|
};
|
|
|
|
|
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static struct scsi_adapter uha_switch =
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
|
|
|
|
uha_scsi_cmd,
|
|
|
|
|
uhaminphys,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
uha_adapter_info,
|
1993-08-28 03:07:44 +00:00
|
|
|
|
"uha",
|
1994-08-18 23:36:40 +00:00
|
|
|
|
{ 0, 0 }
|
1993-06-12 14:58:17 +00:00
|
|
|
|
};
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/* the below structure is so we have a default dev struct for out link struct */
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static struct scsi_device uha_dev =
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
NULL, /* Use default error handler */
|
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
|
NULL, /* Use default 'done' routine */
|
|
|
|
|
"uha",
|
|
|
|
|
0,
|
1994-08-18 23:36:40 +00:00
|
|
|
|
{ 0, 0 }
|
1993-11-18 05:03:27 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif /*KERNEL */
|
|
|
|
|
|
|
|
|
|
#ifndef KERNEL
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
printf("uha_data is %d bytes\n", sizeof(struct uha_data));
|
|
|
|
|
printf("mscp is %d bytes\n", sizeof(struct mscp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /*KERNEL*/
|
|
|
|
|
/*
|
|
|
|
|
* Function to send a command out through a mailbox
|
|
|
|
|
*/
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static void
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_send_mbox(struct uha_data *uha, struct mscp *mscp)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
{
|
|
|
|
|
int spincount = 100000; /* 1s should be enough */
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_reg *ur = uha->ur;
|
|
|
|
|
struct uha_bits *ub = uha->ub;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
int s = splbio();
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
while (--spincount) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if ((inb(ur->lint) & ub->ldip) == 0)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
break;
|
|
|
|
|
DELAY(100);
|
|
|
|
|
}
|
|
|
|
|
if (spincount == 0) {
|
1996-05-22 00:04:12 +00:00
|
|
|
|
printf("uha%d: uha_send_mbox, board is not responding\n",
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->unit);
|
1993-12-19 00:55:01 +00:00
|
|
|
|
Debugger("ultra14f");
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
outl(ur->ogmptr, KVTOPHYS(mscp));
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if (uha->flags & UHA_24F) outb(ur->ogmcmd, 1);
|
|
|
|
|
outb(ur->lint, ub->ogmint);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
splx(s);
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Function to send abort to 14f
|
|
|
|
|
*/
|
|
|
|
|
int
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_abort(struct uha_data *uha, struct mscp *mscp)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1996-01-07 19:22:39 +00:00
|
|
|
|
int spincount = 100; /* 1 mSec */
|
|
|
|
|
int abortcount = 200000; /*2 secs */
|
|
|
|
|
struct uha_reg *ur = uha->ur;
|
|
|
|
|
struct uha_bits *ub = uha->ub;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
int s = splbio();
|
|
|
|
|
|
|
|
|
|
while (--spincount) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if ((inb(ur->lint) & ub->ldip) == 0)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
break;
|
|
|
|
|
DELAY(10);
|
|
|
|
|
}
|
1994-01-29 10:29:14 +00:00
|
|
|
|
if (spincount == 0) {
|
1996-05-22 00:04:12 +00:00
|
|
|
|
printf("uha%d: uha_abort, board is not responding\n", uha->unit);
|
1993-12-19 00:55:01 +00:00
|
|
|
|
Debugger("ultra14f");
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1994-08-19 00:32:52 +00:00
|
|
|
|
outl(ur->ogmptr,KVTOPHYS(mscp));
|
|
|
|
|
if (uha->flags & UHA_24F) outb(ur->ogmcmd, 1);
|
|
|
|
|
outb(ur->lint, ub->abort);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while (--abortcount) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if (inb(ur->sint) & ub->abort_fail)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
break;
|
|
|
|
|
DELAY(10);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (abortcount == 0) {
|
1996-05-22 00:04:12 +00:00
|
|
|
|
printf("uha%d: uha_abort, board is not responding\n", uha->unit);
|
1993-12-19 00:55:01 +00:00
|
|
|
|
Debugger("ultra14f");
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if ((inb(ur->sint) & 0x10) != 0) {
|
|
|
|
|
outb(ur->sint, ub->abort_ack);
|
1994-01-29 10:29:14 +00:00
|
|
|
|
splx(s);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (1);
|
|
|
|
|
} else {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
outb(ur->sint, ub->abort_ack);
|
1994-01-29 10:29:14 +00:00
|
|
|
|
splx(s);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Function to poll for command completion when in poll mode.
|
|
|
|
|
*
|
|
|
|
|
* wait = timeout in msec
|
|
|
|
|
*/
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static int
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_poll(struct uha_data *uha, int wait)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_reg *ur = uha->ur;
|
|
|
|
|
struct uha_bits *ub = uha->ub;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
int stport = ur->sint;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
while (--wait) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if (inb(stport) & ub->sintp)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
break;
|
|
|
|
|
DELAY(1000); /* 1 mSec per loop */
|
|
|
|
|
}
|
|
|
|
|
if (wait == 0) {
|
1996-05-22 00:04:12 +00:00
|
|
|
|
printf("uha%d: uha_poll, board is not responding\n", uha->unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (EIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uhaintr(uha->unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Check if the device can be found at the port given and if so, set it up
|
|
|
|
|
* ready for further work as an argument, takes the isa_device structure
|
|
|
|
|
* from autoconf.c
|
|
|
|
|
*/
|
|
|
|
|
int
|
1993-06-12 14:58:17 +00:00
|
|
|
|
uhaprobe(dev)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct isa_device *dev;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
int unit = uha_unit;
|
|
|
|
|
struct uha_data *uha;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1995-04-12 20:48:13 +00:00
|
|
|
|
dev->id_unit = unit; /* XXX */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* find unit and check we have that many defined
|
|
|
|
|
*/
|
|
|
|
|
if (unit >= NUHA) {
|
|
|
|
|
printf("uha: unit number (%d) too high\n", unit);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
dev->id_unit = unit;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Allocate a storage area for us
|
|
|
|
|
*/
|
|
|
|
|
if (uhadata[unit]) {
|
|
|
|
|
printf("uha%d: memory already allocated\n", unit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
uha = malloc(sizeof(struct uha_data), M_TEMP, M_NOWAIT);
|
|
|
|
|
if (!uha) {
|
|
|
|
|
printf("uha%d: cannot malloc!\n", unit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
bzero(uha, sizeof(struct uha_data));
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->ur = malloc(sizeof(struct uha_reg), M_TEMP, M_NOWAIT);
|
|
|
|
|
if (!uha->ur) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
printf("uha%d: cannot malloc!\n", unit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1996-01-07 19:22:39 +00:00
|
|
|
|
bzero(uha->ur, sizeof(struct uha_reg));
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->ub = malloc(sizeof(struct uha_bits), M_TEMP, M_NOWAIT);
|
|
|
|
|
if (!uha->ub) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
printf("uha%d: cannot malloc!\n", unit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1996-01-07 19:22:39 +00:00
|
|
|
|
bzero(uha->ub, sizeof(struct uha_bits));
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uhadata[unit] = uha;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->unit = unit;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha->baseport = dev->id_iobase;
|
|
|
|
|
/*
|
|
|
|
|
* Try initialise a unit at this location
|
|
|
|
|
* sets up dma and bus speed, loads uha->vect
|
|
|
|
|
*/
|
1996-01-07 19:22:39 +00:00
|
|
|
|
if (uha_init(uha) != 0 && uha24_init(uha) != 0) {
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uhadata[unit] = NULL;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
free(uha->ur, M_TEMP);
|
|
|
|
|
free(uha->ub, M_TEMP);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
free(uha, M_TEMP);
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
/* if it's there put in its interrupt and DRQ vectors */
|
|
|
|
|
dev->id_irq = (1 << uha->vect);
|
|
|
|
|
dev->id_drq = uha->dma;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
dev->id_iobase = uha->baseport;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha_unit++;
|
|
|
|
|
return (16);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
|
*/
|
|
|
|
|
int
|
1993-06-12 14:58:17 +00:00
|
|
|
|
uha_attach(dev)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct isa_device *dev;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
int unit = dev->id_unit;
|
|
|
|
|
struct uha_data *uha = uhadata[unit];
|
1995-08-23 23:03:34 +00:00
|
|
|
|
struct scsibus_data *scbus;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* fill in the prototype scsi_link.
|
|
|
|
|
*/
|
|
|
|
|
uha->sc_link.adapter_unit = unit;
|
|
|
|
|
uha->sc_link.adapter_targ = uha->our_id;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->sc_link.adapter_softc = uha;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha->sc_link.adapter = &uha_switch;
|
|
|
|
|
uha->sc_link.device = &uha_dev;
|
1994-03-24 02:23:00 +00:00
|
|
|
|
uha->sc_link.flags = SDEV_BOUNCE;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
1995-08-23 23:03:34 +00:00
|
|
|
|
/*
|
|
|
|
|
* Prepare the scsibus_data area for the upperlevel
|
|
|
|
|
* scsi code.
|
|
|
|
|
*/
|
|
|
|
|
scbus = scsi_alloc_bus();
|
|
|
|
|
if(!scbus)
|
|
|
|
|
return 0;
|
|
|
|
|
scbus->adapter_link = &uha->sc_link;
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
|
*/
|
1995-08-23 23:03:34 +00:00
|
|
|
|
scsi_attachdevs(scbus);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
return 1;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Return some information to the caller about
|
|
|
|
|
* the adapter and it's capabilities
|
|
|
|
|
*/
|
1996-03-10 07:04:48 +00:00
|
|
|
|
u_int32_t
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha_adapter_info(unit)
|
|
|
|
|
int unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (2); /* 2 outstanding requests at a time per device */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Catch an interrupt from the adaptor
|
|
|
|
|
*/
|
1995-09-19 18:55:37 +00:00
|
|
|
|
void
|
1993-06-12 14:58:17 +00:00
|
|
|
|
uhaintr(unit)
|
1993-11-25 01:38:01 +00:00
|
|
|
|
int unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct uha_data *uha = uhadata[unit];
|
|
|
|
|
struct mscp *mscp;
|
|
|
|
|
u_char uhastat;
|
|
|
|
|
unsigned long int mboxval;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_reg *ur;
|
|
|
|
|
struct uha_bits *ub;
|
|
|
|
|
int port;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
ur = uha->ur;
|
|
|
|
|
ub = uha->ub;
|
|
|
|
|
port = uha->baseport;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-08-20 09:21:40 +00:00
|
|
|
|
#ifdef UHADEBUG
|
1993-11-18 05:03:27 +00:00
|
|
|
|
printf("uhaintr ");
|
|
|
|
|
#endif /*UHADEBUG */
|
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
while ((uhastat = inb(ur->sint)) & ub->sintp) {
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* First get all the information and then
|
|
|
|
|
* acknowledge the interrupt
|
|
|
|
|
*/
|
1994-08-19 00:32:52 +00:00
|
|
|
|
mboxval = inl(ur->icmptr);
|
|
|
|
|
outb(ur->sint, ub->icm_ack);
|
|
|
|
|
if (uha->flags & UHA_24F) outb(ur->icmcmd, 0);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-08-20 09:21:40 +00:00
|
|
|
|
#ifdef UHADEBUG
|
1993-11-18 05:03:27 +00:00
|
|
|
|
printf("status = 0x%x ", uhastat);
|
|
|
|
|
#endif /*UHADEBUG*/
|
|
|
|
|
/*
|
|
|
|
|
* Process the completed operation
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
mscp = uha_mscp_phys_kv(uha, mboxval);
|
|
|
|
|
if (!mscp) {
|
|
|
|
|
printf("uha: BAD MSCP RETURNED\n");
|
1995-09-19 18:55:37 +00:00
|
|
|
|
return; /* whatever it was, it'll timeout */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
}
|
1997-09-21 21:41:49 +00:00
|
|
|
|
untimeout(uha_timeout, (caddr_t)mscp, mscp->xs->timeout_ch);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_done(uha, mscp);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* We have a mscp which has been processed by the adaptor, now we look to see
|
|
|
|
|
* how the operation went.
|
|
|
|
|
*/
|
|
|
|
|
void
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_done(uha, mscp)
|
|
|
|
|
struct uha_data *uha;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscp;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct scsi_sense_data *s1, *s2;
|
|
|
|
|
struct scsi_xfer *xs = mscp->xs;
|
|
|
|
|
|
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB2, ("uha_done\n"));
|
|
|
|
|
/*
|
|
|
|
|
* Otherwise, put the results of the operation
|
|
|
|
|
* into the xfer and call whoever started it
|
|
|
|
|
*/
|
1995-05-07 06:54:01 +00:00
|
|
|
|
if (((mscp->ha_status != UHA_NO_ERR) || (mscp->targ_status != SCSI_OK))
|
|
|
|
|
&& ((xs->flags & SCSI_ERR_OK) == 0)) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
s1 = &(mscp->mscp_sense);
|
|
|
|
|
s2 = &(xs->sense);
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (mscp->ha_status != UHA_NO_ERR) {
|
|
|
|
|
switch (mscp->ha_status) {
|
1995-05-07 06:54:01 +00:00
|
|
|
|
case UHA_SBUS_ABORT_ERR:
|
|
|
|
|
case UHA_SBUS_TIMEOUT: /* No sel response */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3,
|
1995-05-07 06:54:01 +00:00
|
|
|
|
("abort or timeout; ha_status 0x%x\n",
|
|
|
|
|
mscp->ha_status));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_TIMEOUT;
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_SBUS_OVER_UNDER:
|
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3,
|
|
|
|
|
("scsi bus xfer over/underrun\n"));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
default: /* Other scsi protocol messes */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1995-05-07 06:54:01 +00:00
|
|
|
|
printf("uha%d: unexpected ha_status 0x%x (target status 0x%x)\n",
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->unit, mscp->ha_status,
|
1995-05-07 06:54:01 +00:00
|
|
|
|
mscp->targ_status);
|
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} else {
|
1995-05-07 06:54:01 +00:00
|
|
|
|
/* Target status problem */
|
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("target err 0x%x\n",
|
|
|
|
|
mscp->targ_status));
|
|
|
|
|
switch (mscp->targ_status) {
|
|
|
|
|
case 0x02:
|
|
|
|
|
*s2 = *s1;
|
|
|
|
|
xs->error = XS_SENSE;
|
|
|
|
|
break;
|
|
|
|
|
case 0x08:
|
|
|
|
|
xs->error = XS_BUSY;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("uha%d: unexpected targ_status 0x%x\n",
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->unit, mscp->targ_status);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1995-05-07 06:54:01 +00:00
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-05-07 06:54:01 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* All went correctly OR errors expected */
|
|
|
|
|
xs->resid = 0;
|
|
|
|
|
xs->error = 0;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
xs->flags |= ITSDONE;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_free_mscp(uha, mscp, xs->flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
scsi_done(xs);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* A mscp (and hence a mbx-out) is put onto the free list.
|
|
|
|
|
*/
|
|
|
|
|
void
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_free_mscp(uha, mscp, flags)
|
|
|
|
|
struct uha_data *uha;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscp;
|
1993-11-25 01:38:01 +00:00
|
|
|
|
int flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-25 01:38:01 +00:00
|
|
|
|
unsigned int opri = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
if (!(flags & SCSI_NOMASK))
|
1993-06-12 14:58:17 +00:00
|
|
|
|
opri = splbio();
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
mscp->next = uha->free_mscp;
|
|
|
|
|
uha->free_mscp = mscp;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->flags = MSCP_FREE;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* If there were none, wake abybody waiting for
|
|
|
|
|
* one to come free, starting with queued entries
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
if (!mscp->next) {
|
1993-11-25 01:38:01 +00:00
|
|
|
|
wakeup((caddr_t)&uha->free_mscp);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (!(flags & SCSI_NOMASK))
|
1993-06-12 14:58:17 +00:00
|
|
|
|
splx(opri);
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Get a free mscp
|
|
|
|
|
*
|
|
|
|
|
* If there are none, see if we can allocate a new one. If so, put it in the
|
|
|
|
|
* hash table too otherwise either return an error or sleep.
|
|
|
|
|
*/
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static struct mscp *
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_get_mscp(uha, flags)
|
|
|
|
|
struct uha_data *uha;
|
|
|
|
|
int flags;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-25 01:38:01 +00:00
|
|
|
|
unsigned opri = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscpp;
|
|
|
|
|
int hashnum;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (!(flags & SCSI_NOMASK))
|
1993-06-12 14:58:17 +00:00
|
|
|
|
opri = splbio();
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* If we can and have to, sleep waiting for one to come free
|
|
|
|
|
* but only if we can't allocate a new one
|
|
|
|
|
*/
|
|
|
|
|
while (!(mscpp = uha->free_mscp)) {
|
|
|
|
|
if (uha->nummscps < UHA_MSCP_MAX) {
|
|
|
|
|
if (mscpp = (struct mscp *)malloc(sizeof(struct mscp),
|
|
|
|
|
M_TEMP,
|
|
|
|
|
M_NOWAIT)) {
|
|
|
|
|
bzero(mscpp, sizeof(struct mscp));
|
|
|
|
|
uha->nummscps++;
|
|
|
|
|
mscpp->flags = MSCP_ACTIVE;
|
|
|
|
|
/*
|
|
|
|
|
* put in the phystokv hash table
|
|
|
|
|
* Never gets taken out.
|
|
|
|
|
*/
|
|
|
|
|
mscpp->hashkey = KVTOPHYS(mscpp);
|
|
|
|
|
hashnum = MSCP_HASH(mscpp->hashkey);
|
|
|
|
|
mscpp->nexthash = uha->mscphash[hashnum];
|
|
|
|
|
uha->mscphash[hashnum] = mscpp;
|
|
|
|
|
} else {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: Can't malloc MSCP\n", uha->unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
goto gottit;
|
|
|
|
|
} else {
|
|
|
|
|
if (!(flags & SCSI_NOSLEEP)) {
|
1994-03-20 00:30:04 +00:00
|
|
|
|
tsleep((caddr_t)&uha->free_mscp, PRIBIO,
|
|
|
|
|
"uhamscp", 0);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (mscpp) {
|
|
|
|
|
/* Get MSCP from from free list */
|
|
|
|
|
uha->free_mscp = mscpp->next;
|
|
|
|
|
mscpp->flags = MSCP_ACTIVE;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
gottit:
|
|
|
|
|
if (!(flags & SCSI_NOMASK))
|
1993-06-12 14:58:17 +00:00
|
|
|
|
splx(opri);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
return (mscpp);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* given a physical address, find the mscp that it corresponds to.
|
|
|
|
|
*/
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static struct mscp *
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha_mscp_phys_kv(uha, mscp_phys)
|
|
|
|
|
struct uha_data *uha;
|
|
|
|
|
long int mscp_phys;
|
|
|
|
|
{
|
|
|
|
|
int hashnum = MSCP_HASH(mscp_phys);
|
|
|
|
|
struct mscp *mscpp = uha->mscphash[hashnum];
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while (mscpp) {
|
|
|
|
|
if (mscpp->hashkey == mscp_phys)
|
|
|
|
|
break;
|
|
|
|
|
mscpp = mscpp->nexthash;
|
|
|
|
|
}
|
|
|
|
|
return mscpp;
|
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Start the board, ready for normal operation
|
|
|
|
|
*/
|
|
|
|
|
int
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_init(uha)
|
|
|
|
|
struct uha_data *uha;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
{
|
1993-06-12 14:58:17 +00:00
|
|
|
|
volatile unsigned char model;
|
|
|
|
|
volatile unsigned char submodel;
|
|
|
|
|
unsigned char config_reg1;
|
|
|
|
|
unsigned char config_reg2;
|
|
|
|
|
unsigned char dma_ch;
|
|
|
|
|
unsigned char irq_ch;
|
|
|
|
|
unsigned char uha_id;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
int port = uha->baseport;
|
|
|
|
|
int resetcount = 4000; /* 4 secs? */
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_reg *ur = uha->ur;
|
|
|
|
|
struct uha_bits *ub = uha->ub;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* Prepare to use a 14/34F.
|
|
|
|
|
*/
|
|
|
|
|
ur->id = port + 0x04;
|
|
|
|
|
ur->type = port + 0x00; /* 24F only */
|
|
|
|
|
ur->ectl = port + 0x00; /* 24F only */
|
|
|
|
|
ur->config = port + 0x06; /* 0-1 for 14F */
|
|
|
|
|
ur->lmask = port + 0x00;
|
|
|
|
|
ur->lint = port + 0x01;
|
|
|
|
|
ur->smask = port + 0x02;
|
|
|
|
|
ur->sint = port + 0x03;
|
|
|
|
|
ur->ogmcmd = port + 0x00; /* 24F only */
|
|
|
|
|
ur->ogmptr = port + 0x08;
|
|
|
|
|
ur->icmcmd = port + 0x00; /* 24F only */
|
|
|
|
|
ur->icmptr = port + 0x0c;
|
|
|
|
|
|
|
|
|
|
ub->ldip = UHA_LDIP;
|
|
|
|
|
ub->adrst = UHA_ADRST;
|
|
|
|
|
ub->sbrst = UHA_SBRST;
|
|
|
|
|
ub->asrst = UHA_ASRST;
|
|
|
|
|
ub->abort = UHA_ABORT;
|
|
|
|
|
ub->ogmint = UHA_OGMINT;
|
|
|
|
|
ub->sintp = UHA_SINTP;
|
|
|
|
|
ub->abort_succ = UHA_ABORT_SUCC;
|
|
|
|
|
ub->abort_fail = UHA_ABORT_FAIL;
|
|
|
|
|
ub->abort_ack = UHA_ABORT_ACK;
|
|
|
|
|
ub->icm_ack = UHA_ICM_ACK;
|
|
|
|
|
|
|
|
|
|
model = inb(ur->id);
|
|
|
|
|
submodel = inb(ur->id + 1);
|
|
|
|
|
if ((model != 0x56) & (submodel != 0x40)) return(ENXIO);
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: reading board settings, ", uha->unit);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
config_reg1 = inb(ur->config);
|
|
|
|
|
config_reg2 = inb(ur->config + 1);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
dma_ch = (config_reg1 & 0xc0);
|
|
|
|
|
irq_ch = (config_reg1 & 0x30);
|
|
|
|
|
uha_id = (config_reg2 & 0x07);
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
switch (dma_ch) {
|
|
|
|
|
case UHA_DMA_CH5:
|
|
|
|
|
uha->dma = 5;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("dma=5 ");
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_DMA_CH6:
|
|
|
|
|
uha->dma = 6;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("dma=6 ");
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_DMA_CH7:
|
|
|
|
|
uha->dma = 7;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("dma=7 ");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("illegal dma jumper setting\n");
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (EIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
switch (irq_ch) {
|
|
|
|
|
case UHA_IRQ10:
|
|
|
|
|
uha->vect = 10;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("int=10 ");
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_IRQ11:
|
|
|
|
|
uha->vect = 11;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("int=11 ");
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_IRQ14:
|
|
|
|
|
uha->vect = 14;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("int=14 ");
|
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
case UHA_IRQ15:
|
|
|
|
|
uha->vect = 15;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
printf("int=15 ");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("illegal int jumper setting\n");
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (EIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
/* who are we on the scsi bus */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
printf("id=%x\n", uha_id);
|
|
|
|
|
uha->our_id = uha_id;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Note that we are going and return (to probe)
|
|
|
|
|
*/
|
1994-08-19 00:32:52 +00:00
|
|
|
|
outb(ur->lint, ub->asrst);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while (--resetcount) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
if (inb(ur->lint))
|
1994-01-29 10:29:14 +00:00
|
|
|
|
break;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
DELAY(1000); /* 1 mSec per loop */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (resetcount == 0) {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: board timed out during reset\n", uha->unit);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (ENXIO);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1994-08-19 00:32:52 +00:00
|
|
|
|
outb(ur->smask, 0x81); /* make sure interrupts are enabled */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha->flags |= UHA_INIT;
|
|
|
|
|
return (0);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize an Ultrastor 24F
|
|
|
|
|
*/
|
|
|
|
|
int
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha24_init(uha)
|
|
|
|
|
struct uha_data *uha;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
{
|
1995-01-07 23:23:40 +00:00
|
|
|
|
unsigned char p0, p1, p2, p3, p5, p7;
|
|
|
|
|
unsigned char id[7], rev, haid;
|
1996-01-15 16:15:27 +00:00
|
|
|
|
int port = 0, irq;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
int resetcount = 4000;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_reg *ur = uha->ur;
|
|
|
|
|
struct uha_bits *ub = uha->ub;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
|
|
|
|
/* Search for the 24F's product ID */
|
1995-03-23 09:00:20 +00:00
|
|
|
|
uha_slot++;
|
|
|
|
|
while (uha_slot < EISA_MAX_SLOTS) {
|
1994-08-19 00:32:52 +00:00
|
|
|
|
/*
|
|
|
|
|
* Prepare to use a 24F.
|
|
|
|
|
*/
|
1995-03-23 09:00:20 +00:00
|
|
|
|
port = EISA_CONFIG | (uha_slot << 12);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
ur->id = port + 0x00;
|
|
|
|
|
ur->type = port + 0x02;
|
|
|
|
|
ur->ectl = port + 0x04;
|
|
|
|
|
ur->config = port + 0x05; /* 0-2 for 24F */
|
|
|
|
|
ur->lmask = port + 0x0c;
|
|
|
|
|
ur->lint = port + 0x0d;
|
|
|
|
|
ur->smask = port + 0x0e;
|
|
|
|
|
ur->sint = port + 0x0f;
|
|
|
|
|
ur->ogmcmd = port + 0x16;
|
|
|
|
|
ur->ogmptr = port + 0x17;
|
|
|
|
|
ur->icmcmd = port + 0x1b;
|
|
|
|
|
ur->icmptr = port + 0x1c;
|
|
|
|
|
|
|
|
|
|
ub->ldip = U24_LDIP;
|
|
|
|
|
ub->adrst = U24_ADRST;
|
|
|
|
|
ub->sbrst = U24_SBRST;
|
|
|
|
|
ub->asrst = U24_ASRST;
|
|
|
|
|
ub->abort = U24_ABORT;
|
|
|
|
|
ub->ogmint = U24_OGMINT;
|
|
|
|
|
ub->sintp = U24_SINTP;
|
|
|
|
|
ub->abort_succ = U24_ABORT_SUCC;
|
|
|
|
|
ub->abort_fail = U24_ABORT_FAIL;
|
|
|
|
|
ub->abort_ack = U24_ABORT_ACK;
|
|
|
|
|
ub->icm_ack = U24_ICM_ACK;
|
|
|
|
|
|
1995-03-23 09:00:20 +00:00
|
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
|
* Make sure an EISA card is installed in this slot,
|
1995-03-23 09:00:20 +00:00
|
|
|
|
* and if it is make sure that the card is enabled.
|
|
|
|
|
*/
|
1994-08-19 00:32:52 +00:00
|
|
|
|
outb(ur->id, 0xff);
|
|
|
|
|
p0 = inb(ur->id);
|
1995-03-23 09:00:20 +00:00
|
|
|
|
if ((p0 == 0xff) ||
|
|
|
|
|
((p0 & 0x80) != 0) ||
|
|
|
|
|
((inb(ur->ectl) & EISA_DISABLE) == 0)) {
|
|
|
|
|
uha_slot++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
|
|
|
|
/* Found an enabled card. Grab the product ID. */
|
|
|
|
|
p1 = inb(ur->id+1);
|
|
|
|
|
p2 = inb(ur->type);
|
|
|
|
|
p3 = inb(ur->type+1);
|
|
|
|
|
id[0] = 0x40 + ((p0 >> 2) & 0x1f);
|
|
|
|
|
id[1] = 0x40 + (((p0 & 0x03) << 3) | ((p1 >> 5) & 0x07));
|
|
|
|
|
id[2] = 0x40 + (p1 & 0x1f);
|
1996-01-15 16:15:27 +00:00
|
|
|
|
id[3] = hex2ascii((p2 >> 4) & 0x0f);
|
|
|
|
|
id[4] = hex2ascii(p2 & 0x0f);
|
|
|
|
|
id[5] = hex2ascii((p3 >> 4) & 0x0f);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
id[6] = '\0';
|
|
|
|
|
rev = p3 & 0xf;
|
|
|
|
|
|
|
|
|
|
/* We only want the 24F product ID. */
|
|
|
|
|
if (!strcmp(id, "USC024")) break;
|
1995-03-23 09:00:20 +00:00
|
|
|
|
uha_slot++;
|
1994-08-19 00:32:52 +00:00
|
|
|
|
}
|
1995-03-23 09:00:20 +00:00
|
|
|
|
if (uha_slot == EISA_MAX_SLOTS) return(ENODEV);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
|
|
|
|
/* We have the card! Grab remaining config. */
|
|
|
|
|
p5 = inb(ur->config);
|
|
|
|
|
p7 = inb(ur->config+2);
|
|
|
|
|
|
|
|
|
|
switch (p5 & 0xf0) {
|
|
|
|
|
case 0x10: irq = 15; break;
|
|
|
|
|
case 0x20: irq = 14; break;
|
|
|
|
|
case 0x40: irq = 11; break;
|
|
|
|
|
case 0x80: irq = 10; break;
|
|
|
|
|
default:
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: bad 24F irq\n", uha->unit);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
return(ENXIO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
haid = (p7 & 0x07);
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: UltraStor 24F int=%d id=%d\n", uha->unit, irq, haid);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
|
|
|
|
|
/* Issue SCSI and adapter reset */
|
|
|
|
|
outb(ur->lint, ub->asrst);
|
|
|
|
|
while (--resetcount) {
|
|
|
|
|
if (inb(ur->lint))
|
|
|
|
|
break;
|
|
|
|
|
DELAY(1000); /* 1 mSec per loop */
|
|
|
|
|
}
|
|
|
|
|
if (resetcount == 0) {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: board timed out during reset\n", uha->unit);
|
1994-08-19 00:32:52 +00:00
|
|
|
|
return (ENXIO);
|
|
|
|
|
}
|
|
|
|
|
outb(ur->smask, 0xc2); /* make sure interrupts are enabled */
|
|
|
|
|
uha->flags |= (UHA_INIT | UHA_24F);
|
|
|
|
|
uha->baseport = port;
|
|
|
|
|
uha->our_id = haid;
|
|
|
|
|
uha->vect = irq;
|
|
|
|
|
uha->dma = -1;
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
|
|
#ifndef min
|
|
|
|
|
#define min(x,y) (x < y ? x : y)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#endif /* min */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
void
|
|
|
|
|
uhaminphys(bp)
|
|
|
|
|
struct buf *bp;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (bp->b_bcount > ((UHA_NSEG - 1) * PAGESIZ)) {
|
|
|
|
|
bp->b_bcount = ((UHA_NSEG - 1) * PAGESIZ);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* start a scsi operation given the command and the data address. Also
|
|
|
|
|
* needs the unit, target and lu.
|
|
|
|
|
*/
|
1996-03-10 07:04:48 +00:00
|
|
|
|
static int32_t
|
1993-11-18 05:03:27 +00:00
|
|
|
|
uha_scsi_cmd(xs)
|
|
|
|
|
struct scsi_xfer *xs;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscp;
|
|
|
|
|
struct uha_dma_seg *sg;
|
|
|
|
|
int seg; /* scatter gather seg being worked on */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
int thiskv;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
unsigned long int thisphys, nextphys;
|
|
|
|
|
int bytes_this_seg, bytes_this_page, datalen, flags;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
struct uha_data *uha;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
int s;
|
|
|
|
|
unsigned long int templen;
|
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha = (struct uha_data *)xs->sc_link->adapter_softc;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB2, ("uha_scsi_cmd\n"));
|
|
|
|
|
/*
|
|
|
|
|
* get a mscp (mbox-out) to use. If the transfer
|
|
|
|
|
* is from a buf (possibly from interrupt time)
|
|
|
|
|
* then we can't allow it to sleep
|
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
flags = xs->flags;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (xs->bp)
|
|
|
|
|
flags |= (SCSI_NOSLEEP); /* just to be sure */
|
|
|
|
|
if (flags & ITSDONE) {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: Already done?", uha->unit);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->flags &= ~ITSDONE;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (!(flags & INUSE)) {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: Not in use?", uha->unit);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->flags |= INUSE;
|
|
|
|
|
}
|
1996-01-07 19:22:39 +00:00
|
|
|
|
if (!(mscp = uha_get_mscp(uha, flags))) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (TRY_AGAIN_LATER);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
cheat = mscp;
|
1995-05-11 19:26:53 +00:00
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("start mscp(%p)\n", mscp));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->xs = xs;
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Put all the arguments for the xfer in the mscp
|
|
|
|
|
*/
|
|
|
|
|
if (flags & SCSI_RESET) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->opcode = 0x04;
|
|
|
|
|
mscp->ca = 0x01;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} else {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->opcode = 0x02;
|
|
|
|
|
mscp->ca = 0x01;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
if (flags & SCSI_DATA_IN) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->xdir = 0x01;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
if (flags & SCSI_DATA_OUT) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->xdir = 0x02;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#ifdef GOTTABEJOKING
|
|
|
|
|
if (xs->sc_link->lun != 0) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_free_mscp(uha, mscp, flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (HAD_ERROR);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#endif
|
|
|
|
|
mscp->dcn = 0x00;
|
|
|
|
|
mscp->chan = 0x00;
|
|
|
|
|
mscp->target = xs->sc_link->target;
|
|
|
|
|
mscp->lun = xs->sc_link->lun;
|
|
|
|
|
mscp->link.addr[0] = 0x00;
|
|
|
|
|
mscp->link.addr[1] = 0x00;
|
|
|
|
|
mscp->link.addr[2] = 0x00;
|
|
|
|
|
mscp->link.addr[3] = 0x00;
|
|
|
|
|
mscp->link_id = 0x00;
|
|
|
|
|
mscp->cdblen = xs->cmdlen;
|
|
|
|
|
scratch = KVTOPHYS(&(mscp->mscp_sense));
|
|
|
|
|
mscp->sense.addr[0] = (scratch & 0xff);
|
|
|
|
|
mscp->sense.addr[1] = ((scratch >> 8) & 0xff);
|
|
|
|
|
mscp->sense.addr[2] = ((scratch >> 16) & 0xff);
|
|
|
|
|
mscp->sense.addr[3] = ((scratch >> 24) & 0xff);
|
|
|
|
|
mscp->senselen = sizeof(mscp->mscp_sense);
|
|
|
|
|
mscp->ha_status = 0x00;
|
|
|
|
|
mscp->targ_status = 0x00;
|
|
|
|
|
|
|
|
|
|
if (xs->datalen) { /* should use S/G only if not zero length */
|
|
|
|
|
scratch = KVTOPHYS(mscp->uha_dma);
|
|
|
|
|
mscp->data.addr[0] = (scratch & 0xff);
|
|
|
|
|
mscp->data.addr[1] = ((scratch >> 8) & 0xff);
|
|
|
|
|
mscp->data.addr[2] = ((scratch >> 16) & 0xff);
|
|
|
|
|
mscp->data.addr[3] = ((scratch >> 24) & 0xff);
|
|
|
|
|
sg = mscp->uha_dma;
|
|
|
|
|
seg = 0;
|
|
|
|
|
mscp->sgth = 0x01;
|
|
|
|
|
|
|
|
|
|
#ifdef TFS
|
|
|
|
|
if (flags & SCSI_DATA_UIO) {
|
|
|
|
|
iovp = ((struct uio *) xs->data)->uio_iov;
|
|
|
|
|
datalen = ((struct uio *) xs->data)->uio_iovcnt;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->datalen = 0;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while ((datalen) && (seg < UHA_NSEG)) {
|
|
|
|
|
scratch = (unsigned long) iovp->iov_base;
|
|
|
|
|
sg->addr.addr[0] = (scratch & 0xff);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
sg->addr.addr[1] = ((scratch >> 8) & 0xff);
|
|
|
|
|
sg->addr.addr[2] = ((scratch >> 16) & 0xff);
|
|
|
|
|
sg->addr.addr[3] = ((scratch >> 24) & 0xff);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
xs->datalen += *(unsigned long *) sg->len.len = iovp->iov_len;
|
|
|
|
|
SC_DEBUGN(xs->sc_link, SDEV_DB4, ("(0x%x@0x%x)",
|
|
|
|
|
iovp->iov_len,
|
|
|
|
|
iovp->iov_base));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
sg++;
|
|
|
|
|
iovp++;
|
|
|
|
|
seg++;
|
|
|
|
|
datalen--;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} else
|
|
|
|
|
#endif /*TFS */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Set up the scatter gather block
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB4,
|
1995-05-11 19:26:53 +00:00
|
|
|
|
("%ld @%p:- ", xs->datalen, xs->data));
|
1993-11-18 05:03:27 +00:00
|
|
|
|
datalen = xs->datalen;
|
|
|
|
|
thiskv = (int) xs->data;
|
|
|
|
|
thisphys = KVTOPHYS(thiskv);
|
|
|
|
|
templen = 0;
|
|
|
|
|
|
|
|
|
|
while ((datalen) && (seg < UHA_NSEG)) {
|
|
|
|
|
bytes_this_seg = 0;
|
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
/* put in the base address */
|
|
|
|
|
sg->addr.addr[0] = (thisphys & 0xff);
|
|
|
|
|
sg->addr.addr[1] = ((thisphys >> 8) & 0xff);
|
|
|
|
|
sg->addr.addr[2] = ((thisphys >> 16) & 0xff);
|
|
|
|
|
sg->addr.addr[3] = ((thisphys >> 24) & 0xff);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
1995-05-11 19:26:53 +00:00
|
|
|
|
SC_DEBUGN(xs->sc_link, SDEV_DB4, ("0x%lx",
|
|
|
|
|
thisphys));
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
/* do it at least once */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
nextphys = thisphys;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
while ((datalen) && (thisphys == nextphys))
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
|
* This page is contiguous (physically) with
|
|
|
|
|
* the the last, just extend the length
|
1993-11-18 05:03:27 +00:00
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
|
|
|
|
/* how far to the end of the page */
|
|
|
|
|
nextphys = (thisphys & (~(PAGESIZ - 1)))
|
1993-11-18 05:03:27 +00:00
|
|
|
|
+ PAGESIZ;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
bytes_this_page = nextphys - thisphys;
|
|
|
|
|
/**** or the data ****/
|
|
|
|
|
bytes_this_page = min(bytes_this_page
|
1993-11-18 05:03:27 +00:00
|
|
|
|
,datalen);
|
|
|
|
|
bytes_this_seg += bytes_this_page;
|
|
|
|
|
datalen -= bytes_this_page;
|
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
|
/* get more ready for the next page */
|
1993-11-18 05:03:27 +00:00
|
|
|
|
thiskv = (thiskv & (~(PAGESIZ - 1)))
|
|
|
|
|
+ PAGESIZ;
|
|
|
|
|
if (datalen)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
thisphys = KVTOPHYS(thiskv);
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* next page isn't contiguous, finish the seg
|
|
|
|
|
*/
|
|
|
|
|
SC_DEBUGN(xs->sc_link, SDEV_DB4,
|
|
|
|
|
("(0x%x)", bytes_this_seg));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
sg->len.len[0] = (bytes_this_seg & 0xff);
|
|
|
|
|
sg->len.len[1] = ((bytes_this_seg >> 8) & 0xff);
|
|
|
|
|
sg->len.len[2] = ((bytes_this_seg >> 16) & 0xff);
|
|
|
|
|
sg->len.len[3] = ((bytes_this_seg >> 24) & 0xff);
|
|
|
|
|
templen += bytes_this_seg;
|
|
|
|
|
sg++;
|
|
|
|
|
seg++;
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* end of iov/kv decision */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->datalen.len[0] = (templen & 0xff);
|
|
|
|
|
mscp->datalen.len[1] = ((templen >> 8) & 0xff);
|
|
|
|
|
mscp->datalen.len[2] = ((templen >> 16) & 0xff);
|
|
|
|
|
mscp->datalen.len[3] = ((templen >> 24) & 0xff);
|
|
|
|
|
mscp->sg_num = seg;
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
SC_DEBUGN(xs->sc_link, SDEV_DB4, ("\n"));
|
|
|
|
|
if (datalen) { /* there's still data, must have run out of segs! */
|
1993-08-21 20:01:59 +00:00
|
|
|
|
printf("uha%d: uha_scsi_cmd, more than %d DMA segs\n",
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha->unit, UHA_NSEG);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_free_mscp(uha, mscp, flags);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (HAD_ERROR);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} else { /* No data xfer, use non S/G values */
|
1993-06-12 14:58:17 +00:00
|
|
|
|
mscp->data.addr[0] = 0x00;
|
|
|
|
|
mscp->data.addr[1] = 0x00;
|
|
|
|
|
mscp->data.addr[2] = 0x00;
|
|
|
|
|
mscp->data.addr[3] = 0x00;
|
|
|
|
|
mscp->datalen.len[0] = 0x00;
|
|
|
|
|
mscp->datalen.len[1] = 0x00;
|
|
|
|
|
mscp->datalen.len[2] = 0x00;
|
|
|
|
|
mscp->datalen.len[3] = 0x00;
|
|
|
|
|
mscp->xdir = 0x03;
|
|
|
|
|
mscp->sgth = 0x00;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
mscp->sg_num = 0x00;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Put the scsi command in the mscp and start it
|
|
|
|
|
*/
|
|
|
|
|
bcopy(xs->cmd, mscp->cdb, xs->cmdlen);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
/*
|
|
|
|
|
* Usually return SUCCESSFULLY QUEUED
|
|
|
|
|
*/
|
|
|
|
|
if (!(flags & SCSI_NOMASK)) {
|
1993-06-12 14:58:17 +00:00
|
|
|
|
s = splbio();
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_send_mbox(uha, mscp);
|
1997-09-21 21:41:49 +00:00
|
|
|
|
xs->timeout_ch = timeout(uha_timeout, (caddr_t)mscp,
|
|
|
|
|
(xs->timeout * hz) / 1000);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
splx(s);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd_sent\n"));
|
|
|
|
|
return (SUCCESSFULLY_QUEUED);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If we can't use interrupts, poll on completion
|
|
|
|
|
*/
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_send_mbox(uha, mscp);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3, ("cmd_wait\n"));
|
|
|
|
|
do {
|
1996-01-07 19:22:39 +00:00
|
|
|
|
if (uha_poll(uha, xs->timeout)) {
|
1993-08-21 20:01:59 +00:00
|
|
|
|
if (!(xs->flags & SCSI_SILENT))
|
1996-01-07 19:22:39 +00:00
|
|
|
|
printf("uha%d: cmd fail\n", uha->unit);
|
|
|
|
|
if (!(uha_abort(uha, mscp))) {
|
|
|
|
|
printf("uha%d: abort failed in wait\n",
|
|
|
|
|
uha->unit);
|
|
|
|
|
uha_free_mscp(uha, mscp, flags);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
return (HAD_ERROR);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while (!(xs->flags & ITSDONE)); /* something (?) else finished */
|
|
|
|
|
if (xs->error) {
|
|
|
|
|
return (HAD_ERROR);
|
|
|
|
|
}
|
|
|
|
|
return (COMPLETE);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-14 09:53:17 +00:00
|
|
|
|
static void
|
1994-08-28 16:08:51 +00:00
|
|
|
|
uha_timeout(arg1)
|
|
|
|
|
void *arg1;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-25 01:38:01 +00:00
|
|
|
|
struct mscp *mscp = (struct mscp *)arg1;
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct uha_data *uha;
|
|
|
|
|
int s = splbio();
|
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha = (struct uha_data *)mscp->xs->sc_link->adapter_softc;
|
|
|
|
|
printf("uha%d:%d:%d (%s%d) timed out ", uha->unit
|
1993-11-18 05:03:27 +00:00
|
|
|
|
,mscp->xs->sc_link->target
|
|
|
|
|
,mscp->xs->sc_link->lun
|
|
|
|
|
,mscp->xs->sc_link->device->name
|
|
|
|
|
,mscp->xs->sc_link->dev_unit);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-08-20 09:21:40 +00:00
|
|
|
|
#ifdef UHADEBUG
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_print_active_mscp(uha);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#endif /*UHADEBUG */
|
1993-08-20 09:21:40 +00:00
|
|
|
|
|
1996-01-07 19:22:39 +00:00
|
|
|
|
if ((uha_abort(uha, mscp) != 1) || (mscp->flags = MSCP_ABORTED)) {
|
1993-08-20 09:21:40 +00:00
|
|
|
|
printf("AGAIN");
|
1993-11-18 05:03:27 +00:00
|
|
|
|
mscp->xs->retries = 0; /* I MEAN IT ! */
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_done(uha, mscp);
|
1993-11-18 05:03:27 +00:00
|
|
|
|
} else { /* abort the operation that has timed out */
|
1993-08-20 09:21:40 +00:00
|
|
|
|
printf("\n");
|
1997-09-21 21:41:49 +00:00
|
|
|
|
mscp->xs->timeout_ch = timeout(uha_timeout, (caddr_t)mscp,
|
|
|
|
|
2 * hz);
|
1993-08-20 09:21:40 +00:00
|
|
|
|
mscp->flags = MSCP_ABORTED;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
splx(s);
|
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#ifdef UHADEBUG
|
|
|
|
|
void
|
1993-06-12 14:58:17 +00:00
|
|
|
|
uha_print_mscp(mscp)
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscp;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
|
|
|
|
printf("mscp:%x op:%x cmdlen:%d senlen:%d\n"
|
1993-11-18 05:03:27 +00:00
|
|
|
|
,mscp
|
|
|
|
|
,mscp->opcode
|
|
|
|
|
,mscp->cdblen
|
|
|
|
|
,mscp->senselen);
|
1993-08-20 09:21:40 +00:00
|
|
|
|
printf(" sg:%d sgnum:%x datlen:%d hstat:%x tstat:%x flags:%x\n"
|
1993-11-18 05:03:27 +00:00
|
|
|
|
,mscp->sgth
|
|
|
|
|
,mscp->sg_num
|
|
|
|
|
,mscp->datalen
|
|
|
|
|
,mscp->ha_status
|
|
|
|
|
,mscp->targ_status
|
|
|
|
|
,mscp->flags);
|
|
|
|
|
show_scsi_cmd(mscp->xs);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
void
|
1996-01-07 19:22:39 +00:00
|
|
|
|
uha_print_active_mscp(struct uha_data *uha)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
{
|
1993-11-18 05:03:27 +00:00
|
|
|
|
struct mscp *mscp;
|
|
|
|
|
int i = 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
1993-11-18 05:03:27 +00:00
|
|
|
|
while (i < MSCP_HASH_SIZE) {
|
|
|
|
|
mscp = uha->mscphash[i];
|
|
|
|
|
while (mscp) {
|
|
|
|
|
if (mscp->flags != MSCP_FREE) {
|
|
|
|
|
uha_print_mscp(mscp);
|
|
|
|
|
}
|
|
|
|
|
mscp = mscp->nexthash;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1993-11-18 05:03:27 +00:00
|
|
|
|
#endif /*UHADEBUG */
|
|
|
|
|
#endif /*KERNEL */
|