1995-07-24 11:16:44 +04:00
|
|
|
/* $NetBSD: ultra14f.c,v 1.50 1995/07/24 07:17:29 cgd Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Charles Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/*
|
|
|
|
* Ported for use with the UltraStor 14f by Gary Close (gclose@wvnvms.wvnet.edu)
|
1994-03-29 08:30:15 +04:00
|
|
|
* Slight fixes to timeouts to run with the 34F
|
1993-03-21 21:04:42 +03:00
|
|
|
* Thanks to Julian Elischer for advice and help with this port.
|
|
|
|
*
|
1994-03-29 08:30:15 +04:00
|
|
|
* Originally written by Julian Elischer (julian@tfs.com)
|
1993-03-21 21:04:42 +03:00
|
|
|
* 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.
|
|
|
|
*
|
1994-03-29 08:30:15 +04:00
|
|
|
* commenced: Sun Sep 27 18:14:01 PDT 1992
|
|
|
|
* slight mod to make work with 34F as well: Wed Jun 2 18:05:48 WST 1993
|
1993-03-21 21:04:42 +03:00
|
|
|
*/
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
#include <sys/types.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
#include <sys/kernel.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/user.h>
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
#include <scsi/scsi_all.h>
|
|
|
|
#include <scsi/scsiconf.h>
|
|
|
|
|
1993-04-15 11:57:50 +04:00
|
|
|
#ifdef DDB
|
1994-12-28 22:42:47 +03:00
|
|
|
int Debugger();
|
|
|
|
#else /* DDB */
|
|
|
|
#define Debugger() panic("should call debugger here (ultra14f.c)")
|
|
|
|
#endif /* DDB */
|
|
|
|
|
|
|
|
typedef u_long physaddr;
|
|
|
|
typedef u_long physlen;
|
|
|
|
|
|
|
|
#define KVTOPHYS(x) vtophys(x)
|
|
|
|
|
|
|
|
#define UHA_MSCP_MAX 32 /* store up to 32 MSCPs at one time */
|
|
|
|
#define MSCP_HASH_SIZE 32 /* hash table size for phystokv */
|
|
|
|
#define MSCP_HASH_SHIFT 9
|
|
|
|
#define MSCP_HASH(x) ((((long)(x))>>MSCP_HASH_SHIFT) & (MSCP_HASH_SIZE - 1))
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
#define UHA_NSEG 33 /* number of dma segments supported */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/************************** board definitions *******************************/
|
|
|
|
/*
|
|
|
|
* I/O Port Interface
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
1994-06-08 15:16:49 +04:00
|
|
|
#define U14_LMASK 0x0000 /* local doorbell mask reg */
|
|
|
|
#define U14_LINT 0x0001 /* local doorbell int/stat reg */
|
|
|
|
#define U14_SMASK 0x0002 /* system doorbell mask reg */
|
|
|
|
#define U14_SINT 0x0003 /* system doorbell int/stat reg */
|
|
|
|
#define U14_ID 0x0004 /* product id reg (2 ports) */
|
|
|
|
#define U14_CONFIG 0x0006 /* config reg (2 ports) */
|
|
|
|
#define U14_OGMPTR 0x0008 /* outgoing mail ptr (4 ports) */
|
|
|
|
#define U14_ICMPTR 0x000c /* incoming mail ptr (4 ports) */
|
|
|
|
|
|
|
|
#define U24_CONFIG 0x0c85 /* config reg (3 ports) */
|
|
|
|
#define U24_LMASK 0x0c8c /* local doorbell mask reg */
|
|
|
|
#define U24_LINT 0x0c8d /* local doorbell int/stat reg */
|
|
|
|
#define U24_SMASK 0x0c8e /* system doorbell mask reg */
|
|
|
|
#define U24_SINT 0x0c8f /* system doorbell int/stat reg */
|
|
|
|
#define U24_OGMCMD 0x0c96 /* outgoing commands */
|
|
|
|
#define U24_OGMPTR 0x0c97 /* outgoing mail ptr (4 ports) */
|
|
|
|
#define U24_ICMCMD 0x0c9b /* incoming commands */
|
|
|
|
#define U24_ICMPTR 0x0c9c /* incoming mail ptr (4 ports) */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* UHA_LMASK bits (read only)
|
|
|
|
*/
|
|
|
|
#define UHA_LDIE 0x80 /* local doorbell int enabled */
|
|
|
|
#define UHA_SRSTE 0x40 /* soft reset enabled */
|
|
|
|
#define UHA_ABORTEN 0x10 /* abort MSCP enabled */
|
|
|
|
#define UHA_OGMINTEN 0x01 /* outgoing mail interrupt enabled */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/*
|
1995-02-10 04:37:57 +03:00
|
|
|
* UHA_LINT bits (write only)
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
1995-02-10 04:37:57 +03:00
|
|
|
#define U14_LDIP 0x80 /* local doorbell int pending */
|
|
|
|
#define U24_LDIP 0x02 /* local doorbell int pending */
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
#define U14_OGMFULL 0x01 /* outgoing mailbox is full */
|
1994-12-28 22:42:47 +03:00
|
|
|
#define U24_OGMFULL 0x02 /* outgoing mailbox is full */
|
1995-02-10 04:37:57 +03:00
|
|
|
|
|
|
|
#define UHA_ABORT 0x10 /* abort MSCP */
|
|
|
|
#define UHA_SBRST 0x40 /* scsi bus reset */
|
|
|
|
#define UHA_ADRST 0x80 /* adapter soft reset */
|
|
|
|
#define UHA_ASRST 0xc0 /* adapter and scsi reset */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/*
|
1994-12-28 22:42:47 +03:00
|
|
|
* UHA_SMASK bits (read/write)
|
1994-03-29 08:30:15 +04: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-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:30:15 +04:00
|
|
|
* UHA_SINT bits (read)
|
|
|
|
*/
|
1995-02-10 04:37:57 +03:00
|
|
|
#define U14_SDIP 0x80 /* system doorbell int pending */
|
|
|
|
#define U24_SDIP 0x02 /* system doorbell int pending */
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
#define UHA_ABORT_SUCC 0x10 /* abort MSCP successful */
|
|
|
|
#define UHA_ABORT_FAIL 0x18 /* abort MSCP failed */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* UHA_SINT bits (write)
|
|
|
|
*/
|
1994-06-08 15:16:49 +04:00
|
|
|
#define U14_ICM_ACK 0x01 /* acknowledge ICM and clear */
|
|
|
|
#define U24_ICM_ACK 0x02 /* acknowledge ICM and clear */
|
1995-02-10 04:37:57 +03:00
|
|
|
|
|
|
|
#define UHA_ABORT_ACK 0x18 /* acknowledge status and clear */
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
/*
|
1994-06-08 15:16:49 +04:00
|
|
|
* U14_CONFIG bits (read only)
|
|
|
|
*/
|
1994-07-31 23:21:40 +04:00
|
|
|
#define U14_DMA_CH5 0x0000 /* DMA channel 5 */
|
|
|
|
#define U14_DMA_CH6 0x4000 /* 6 */
|
|
|
|
#define U14_DMA_CH7 0x8000 /* 7 */
|
|
|
|
#define U14_DMA_MASK 0xc000
|
|
|
|
#define U14_IRQ15 0x0000 /* IRQ 15 */
|
|
|
|
#define U14_IRQ14 0x1000 /* 14 */
|
|
|
|
#define U14_IRQ11 0x2000 /* 11 */
|
|
|
|
#define U14_IRQ10 0x3000 /* 10 */
|
|
|
|
#define U14_IRQ_MASK 0x3000
|
|
|
|
#define U14_HOSTID_MASK 0x0007
|
1994-06-08 15:16:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* U24_CONFIG bits (read only)
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
1994-06-08 15:16:49 +04:00
|
|
|
#define U24_MAGIC1 0x08
|
|
|
|
#define U24_IRQ15 0x10
|
|
|
|
#define U24_IRQ14 0x20
|
|
|
|
#define U24_IRQ11 0x40
|
|
|
|
#define U24_IRQ10 0x80
|
|
|
|
#define U24_IRQ_MASK 0xf0
|
|
|
|
|
|
|
|
#define U24_MAGIC2 0x04
|
|
|
|
|
|
|
|
#define U24_HOSTID_MASK 0x07
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EISA registers (offset from slot base)
|
|
|
|
*/
|
1994-07-28 06:39:21 +04:00
|
|
|
#define EISA_VENDOR 0x0c80 /* vendor ID (2 ports) */
|
1994-06-08 15:16:49 +04:00
|
|
|
#define EISA_MODEL 0x0c82 /* model number (2 ports) */
|
|
|
|
#define EISA_CONTROL 0x0c84
|
1994-07-28 06:39:21 +04:00
|
|
|
#define EISA_RESET 0x04
|
|
|
|
#define EISA_ERROR 0x02
|
|
|
|
#define EISA_ENABLE 0x01
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
1994-12-28 22:42:47 +03:00
|
|
|
* host_stat error codes
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
|
|
|
#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 {
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr seg_addr;
|
|
|
|
physlen seg_len;
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
#pragma pack(1)
|
|
|
|
struct uha_mscp {
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char opcode:3;
|
1994-12-28 22:42:47 +03:00
|
|
|
#define UHA_HAC 0x01 /* host adapter command */
|
|
|
|
#define UHA_TSP 0x02 /* target scsi pass through command */
|
|
|
|
#define UHA_SDR 0x04 /* scsi device reset */
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char xdir:2; /* xfer direction */
|
1994-12-28 22:42:47 +03:00
|
|
|
#define UHA_SDET 0x00 /* determined by scsi command */
|
|
|
|
#define UHA_SDIN 0x01 /* scsi data in */
|
|
|
|
#define UHA_SDOUT 0x02 /* scsi data out */
|
|
|
|
#define UHA_NODATA 0x03 /* no data xfer */
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char dcn:1; /* disable disconnect for this command */
|
|
|
|
u_char ca:1; /* cache control */
|
|
|
|
u_char sgth:1; /* scatter gather flag */
|
|
|
|
u_char target:3;
|
|
|
|
u_char chan:2; /* scsi channel (always 0 for 14f) */
|
|
|
|
u_char lun:3;
|
1994-12-28 22:42:47 +03:00
|
|
|
physaddr data_addr;
|
|
|
|
physlen data_length;
|
|
|
|
physaddr link_addr;
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char link_id;
|
1994-12-28 22:42:47 +03:00
|
|
|
u_char sg_num; /* number of scat gath segs */
|
1994-03-29 08:30:15 +04:00
|
|
|
/*in s-g list if sg flag is */
|
|
|
|
/*set. starts at 1, 8bytes per */
|
1994-12-28 22:42:47 +03:00
|
|
|
u_char req_sense_length;
|
|
|
|
u_char scsi_cmd_length;
|
|
|
|
struct scsi_generic scsi_cmd;
|
|
|
|
u_char host_stat;
|
|
|
|
u_char target_stat;
|
|
|
|
physaddr sense_ptr; /* if 0 no auto sense */
|
1993-03-21 21:04:42 +03:00
|
|
|
/*-----------------end of hardware supported fields----------------*/
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_ENTRY(uha_mscp) chain;
|
|
|
|
struct uha_mscp *nexthash;
|
|
|
|
long hashkey;
|
1994-03-29 08:30:15 +04:00
|
|
|
struct scsi_xfer *xs; /* the scsi_xfer for this cmd */
|
|
|
|
int flags;
|
|
|
|
#define MSCP_FREE 0
|
|
|
|
#define MSCP_ACTIVE 1
|
|
|
|
#define MSCP_ABORTED 2
|
|
|
|
struct uha_dma_seg uha_dma[UHA_NSEG];
|
|
|
|
struct scsi_sense_data mscp_sense;
|
1993-03-21 21:04:42 +03:00
|
|
|
};
|
1994-12-28 22:42:47 +03:00
|
|
|
#pragma pack(4)
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct isadev sc_id;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-11-19 00:57:40 +03:00
|
|
|
int sc_iobase;
|
1994-12-28 22:42:47 +03:00
|
|
|
int sc_irq, sc_drq;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
void (*send_mbox)();
|
|
|
|
int (*abort)();
|
|
|
|
int (*poll)();
|
|
|
|
int (*intr)();
|
|
|
|
void (*init)();
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscphash[MSCP_HASH_SIZE];
|
|
|
|
TAILQ_HEAD(, uha_mscp) free_mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
int nummscps;
|
1994-12-28 22:42:47 +03:00
|
|
|
int uha_scsi_dev; /* our scsi id */
|
1994-03-29 08:30:15 +04:00
|
|
|
struct scsi_link sc_link;
|
|
|
|
};
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
void u14_start_mbox __P((struct uha_softc *, int, struct uha_mscp *));
|
|
|
|
void u14_send_mbox __P((struct uha_softc *, struct uha_mscp *));
|
|
|
|
void u24_start_mbox __P((struct uha_softc *, int, struct uha_mscp *));
|
|
|
|
void u24_send_mbox __P((struct uha_softc *, struct uha_mscp *));
|
|
|
|
int u14_abort __P((struct uha_softc *, struct uha_mscp *));
|
|
|
|
int u24_abort __P((struct uha_softc *, struct uha_mscp *));
|
|
|
|
int u14_poll __P((struct uha_softc *, struct scsi_xfer *, int));
|
|
|
|
int u24_poll __P((struct uha_softc *, struct scsi_xfer *, int));
|
1995-04-17 16:06:30 +04:00
|
|
|
int u14intr __P((void *));
|
|
|
|
int u24intr __P((void *));
|
1994-12-28 22:42:47 +03:00
|
|
|
void uha_done __P((struct uha_softc *, struct uha_mscp *));
|
|
|
|
void uha_free_mscp __P((struct uha_softc *, struct uha_mscp *, int flags));
|
|
|
|
struct uha_mscp *uha_get_mscp __P((struct uha_softc *, int));
|
|
|
|
struct uha_mscp *uha_mscp_phys_kv __P((struct uha_softc *, u_long));
|
1994-06-08 15:16:49 +04:00
|
|
|
int u14_find __P((struct uha_softc *, struct isa_attach_args *));
|
|
|
|
int u24_find __P((struct uha_softc *, struct isa_attach_args *));
|
|
|
|
void u14_init __P((struct uha_softc *));
|
|
|
|
void u24_init __P((struct uha_softc *));
|
1995-07-24 11:16:44 +04:00
|
|
|
u_int uhaminphys __P((struct buf *));
|
1994-03-29 08:30:15 +04:00
|
|
|
int uha_scsi_cmd __P((struct scsi_xfer *));
|
1994-05-05 09:35:42 +04:00
|
|
|
void uha_timeout __P((void *arg));
|
1994-03-29 08:30:15 +04:00
|
|
|
#ifdef UHADEBUG
|
1994-12-28 22:42:47 +03:00
|
|
|
void uha_print_mscp __P((struct uha_mscp *));
|
1994-03-29 08:30:15 +04:00
|
|
|
void uha_print_active_mscp __P((struct uha_softc *));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
u_long scratch;
|
1993-03-21 21:04:42 +03:00
|
|
|
#define UHA_SHOWMSCPS 0x01
|
|
|
|
#define UHA_SHOWINTS 0x02
|
|
|
|
#define UHA_SHOWCMDS 0x04
|
|
|
|
#define UHA_SHOWMISC 0x08
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
struct scsi_adapter uha_switch = {
|
|
|
|
uha_scsi_cmd,
|
|
|
|
uhaminphys,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* the below structure is so we have a default dev struct for out link struct */
|
|
|
|
struct scsi_device uha_dev = {
|
|
|
|
NULL, /* Use default error handler */
|
|
|
|
NULL, /* have a queue, served by this */
|
|
|
|
NULL, /* have no async handler */
|
|
|
|
NULL, /* Use default 'done' routine */
|
|
|
|
};
|
|
|
|
|
1994-11-04 02:08:27 +03:00
|
|
|
int uhaprobe __P((struct device *, void *, void *));
|
|
|
|
void uhaattach __P((struct device *, struct device *, void *));
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
struct cfdriver uhacd = {
|
|
|
|
NULL, "uha", uhaprobe, uhaattach, DV_DULL, sizeof(struct uha_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to send a command out through a mailbox
|
|
|
|
*/
|
|
|
|
void
|
1994-12-28 22:42:47 +03:00
|
|
|
u14_start_mbox(uha, opcode, mscp)
|
1994-06-08 15:16:49 +04:00
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
int opcode;
|
|
|
|
struct uha_mscp *mscp;
|
1994-06-08 15:16:49 +04:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
int spincount = 100000; /* 1s should be enough */
|
|
|
|
|
|
|
|
while (--spincount) {
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U14_LINT) & U14_LDIP) == 0)
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
if (!spincount) {
|
|
|
|
printf("%s: uha_send_mbox, board not responding\n",
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_dev.dv_xname);
|
1994-06-08 15:16:49 +04:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
|
|
|
|
outl(iobase + U14_OGMPTR, KVTOPHYS(mscp));
|
1994-12-28 22:42:47 +03:00
|
|
|
outb(iobase + U14_LINT, opcode);
|
|
|
|
}
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
void
|
|
|
|
u14_send_mbox(uha, mscp)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
struct uha_mscp *mscp;
|
|
|
|
{
|
|
|
|
|
|
|
|
u14_start_mbox(uha, U14_OGMFULL, mscp);
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-12-28 22:42:47 +03:00
|
|
|
u24_start_mbox(uha, opcode, mscp)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
int opcode;
|
|
|
|
struct uha_mscp *mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-03-29 08:30:15 +04:00
|
|
|
int spincount = 100000; /* 1s should be enough */
|
|
|
|
|
|
|
|
while (--spincount) {
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U24_LINT) & U24_LDIP) == 0)
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
if (!spincount) {
|
|
|
|
printf("%s: uha_send_mbox, board not responding\n",
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_dev.dv_xname);
|
1993-03-21 21:04:42 +03:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
outl(iobase + U24_OGMPTR, KVTOPHYS(mscp));
|
|
|
|
outb(iobase + U24_OGMCMD, 1);
|
1994-12-28 22:42:47 +03:00
|
|
|
outb(iobase + U24_LINT, opcode);
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
void
|
|
|
|
u24_send_mbox(uha, mscp)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
struct uha_mscp *mscp;
|
|
|
|
{
|
|
|
|
|
|
|
|
u24_start_mbox(uha, U24_OGMFULL, mscp);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
1994-06-08 15:16:49 +04:00
|
|
|
* Function to send abort
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
|
|
|
int
|
1994-06-08 15:16:49 +04:00
|
|
|
u14_abort(uha, mscp)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
int abortcount = 200000; /* 2 secs */
|
1994-03-29 08:30:15 +04:00
|
|
|
int s = splbio();
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
u14_start_mbox(uha, UHA_ABORT, mscp);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
while (--abortcount) {
|
1995-02-10 04:37:57 +03:00
|
|
|
if (inb(iobase + U14_SINT) & UHA_ABORT_FAIL)
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
if (!abortcount) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: u14_abort, board not responding\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
1994-03-29 08:30:15 +04:00
|
|
|
Debugger();
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U14_SINT) & (UHA_ABORT_FAIL | UHA_ABORT_SUCC)) ==
|
|
|
|
UHA_ABORT_SUCC) {
|
|
|
|
outb(iobase + U14_SINT, UHA_ABORT_ACK);
|
1994-03-29 08:30:15 +04:00
|
|
|
splx(s);
|
|
|
|
return 1;
|
|
|
|
} else {
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(iobase + U14_SINT, UHA_ABORT_ACK);
|
1994-06-08 15:16:49 +04:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
u24_abort(uha, mscp)
|
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-06-08 15:16:49 +04:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
int abortcount = 200000; /* 2 secs */
|
|
|
|
int s = splbio();
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
u24_start_mbox(uha, UHA_ABORT, mscp);
|
1994-06-08 15:16:49 +04:00
|
|
|
|
|
|
|
while (--abortcount) {
|
1995-02-10 04:37:57 +03:00
|
|
|
if (inb(iobase + U24_SINT) & UHA_ABORT_FAIL)
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
if (!abortcount) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: u24_abort, board not responding\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
1994-06-08 15:16:49 +04:00
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U24_SINT) & (UHA_ABORT_FAIL | UHA_ABORT_SUCC)) ==
|
|
|
|
UHA_ABORT_SUCC) {
|
|
|
|
outb(iobase + U24_SINT, UHA_ABORT_ACK);
|
1994-06-08 15:16:49 +04:00
|
|
|
splx(s);
|
|
|
|
return 1;
|
|
|
|
} else {
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(iobase + U24_SINT, UHA_ABORT_ACK);
|
1994-03-29 08:30:15 +04:00
|
|
|
splx(s);
|
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Function to poll for command completion when in poll mode.
|
|
|
|
*
|
|
|
|
* wait = timeout in msec
|
|
|
|
*/
|
|
|
|
int
|
1994-12-28 22:42:47 +03:00
|
|
|
u14_poll(uha, xs, count)
|
1994-06-08 15:16:49 +04:00
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
int count;
|
1994-06-08 15:16:49 +04:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
while (count) {
|
|
|
|
/*
|
|
|
|
* If we had interrupts enabled, would we
|
|
|
|
* have got an interrupt?
|
|
|
|
*/
|
1995-02-10 04:37:57 +03:00
|
|
|
if (inb(iobase + U14_SINT) & U14_SDIP)
|
1994-12-28 22:42:47 +03:00
|
|
|
u14intr(uha);
|
|
|
|
if (xs->flags & ITSDONE)
|
|
|
|
return 0;
|
|
|
|
delay(1000);
|
|
|
|
count--;
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-12-28 22:42:47 +03:00
|
|
|
u24_poll(uha, xs, count)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct scsi_xfer *xs;
|
|
|
|
int count;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-03-10 23:52:09 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
while (count) {
|
|
|
|
/*
|
|
|
|
* If we had interrupts enabled, would we
|
|
|
|
* have got an interrupt?
|
|
|
|
*/
|
1995-02-10 04:37:57 +03:00
|
|
|
if (inb(iobase + U24_SINT) & U24_SDIP)
|
1994-12-28 22:42:47 +03:00
|
|
|
u24intr(uha);
|
|
|
|
if (xs->flags & ITSDONE)
|
|
|
|
return 0;
|
|
|
|
delay(1000);
|
|
|
|
count--;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04: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
|
1994-11-04 02:08:27 +03:00
|
|
|
uhaprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-11-04 02:08:27 +03:00
|
|
|
struct uha_softc *uha = match;
|
1994-03-29 08:30:15 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
|
|
|
|
uha->sc_iobase = ia->ia_iobase;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try initialise a unit at this location
|
1994-12-28 22:42:47 +03:00
|
|
|
* sets up dma and bus speed, loads uha->sc_irq
|
1994-03-29 08:30:15 +04:00
|
|
|
*/
|
1994-06-08 15:16:49 +04:00
|
|
|
if (u24_find(uha, ia) != 0 && u14_find(uha, ia) != 0)
|
1994-03-29 08:30:15 +04:00
|
|
|
return 0;
|
|
|
|
|
1994-07-27 05:50:57 +04:00
|
|
|
if (ia->ia_irq != IRQUNK) {
|
1994-12-28 22:42:47 +03:00
|
|
|
if (ia->ia_irq != uha->sc_irq) {
|
|
|
|
printf("%s: irq mismatch; kernel configured %d != board configured %d\n",
|
|
|
|
uha->sc_dev.dv_xname, ia->ia_irq, uha->sc_irq);
|
1994-03-29 08:30:15 +04:00
|
|
|
return 0;
|
1993-12-21 02:27:28 +03:00
|
|
|
}
|
1994-07-27 05:50:57 +04:00
|
|
|
} else
|
1994-12-28 22:42:47 +03:00
|
|
|
ia->ia_irq = uha->sc_irq;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-07-27 05:50:57 +04:00
|
|
|
if (ia->ia_drq != DRQUNK) {
|
1994-12-28 22:42:47 +03:00
|
|
|
if (ia->ia_drq != uha->sc_drq) {
|
|
|
|
printf("%s: drq mismatch; kernel configured %d != board configured %d\n",
|
|
|
|
uha->sc_dev.dv_xname, ia->ia_drq, uha->sc_drq);
|
1994-03-29 08:30:15 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1994-07-27 05:50:57 +04:00
|
|
|
} else
|
1994-12-28 22:42:47 +03:00
|
|
|
ia->ia_drq = uha->sc_drq;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
ia->ia_msize = 0;
|
1994-08-03 13:17:12 +04:00
|
|
|
ia->ia_iosize = 16;
|
1994-03-29 08:30:15 +04:00
|
|
|
return 1;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
uhaprint()
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uhaattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct uha_softc *uha = (void *)self;
|
|
|
|
|
1994-07-27 17:10:33 +04:00
|
|
|
if (ia->ia_drq != DRQUNK)
|
|
|
|
isa_dmacascade(ia->ia_drq);
|
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
(uha->init)(uha);
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_INIT(&uha->free_mscp);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in the prototype scsi_link.
|
|
|
|
*/
|
|
|
|
uha->sc_link.adapter_softc = uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_link.adapter_target = uha->uha_scsi_dev;
|
1994-03-29 08:30:15 +04:00
|
|
|
uha->sc_link.adapter = &uha_switch;
|
|
|
|
uha->sc_link.device = &uha_dev;
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_link.openings = 2;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
#ifdef NEWCONFIG
|
|
|
|
isa_establish(&uha->sc_id, &uha->sc_dev);
|
1994-04-07 10:48:19 +04:00
|
|
|
#endif
|
1995-04-17 16:06:30 +04:00
|
|
|
uha->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE, ISA_IPL_BIO,
|
|
|
|
uha->intr, uha);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ask the adapter what subunits are present
|
|
|
|
*/
|
|
|
|
config_found(self, &uha->sc_link, uhaprint);
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Catch an interrupt from the adaptor
|
|
|
|
*/
|
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
u14intr(arg)
|
|
|
|
void *arg;
|
1994-03-29 08:30:15 +04:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct uha_softc *uha = arg;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
u_char uhastat;
|
|
|
|
u_long mboxval;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
#ifdef UHADEBUG
|
|
|
|
printf("%s: uhaintr ", uha->sc_dev.dv_xname);
|
|
|
|
#endif /*UHADEBUG */
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U14_SINT) & U14_SDIP) == 0)
|
1994-03-29 08:30:15 +04:00
|
|
|
return 0;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
for (;;) {
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* First get all the information and then
|
|
|
|
* acknowledge the interrupt
|
|
|
|
*/
|
1994-06-08 15:16:49 +04:00
|
|
|
uhastat = inb(iobase + U14_SINT);
|
|
|
|
mboxval = inl(iobase + U14_ICMPTR);
|
|
|
|
outb(iobase + U14_SINT, U14_ICM_ACK);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
#ifdef UHADEBUG
|
|
|
|
printf("status = 0x%x ", uhastat);
|
|
|
|
#endif /*UHADEBUG*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the completed operation
|
|
|
|
*/
|
|
|
|
mscp = uha_mscp_phys_kv(uha, mboxval);
|
|
|
|
if (!mscp) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: BAD MSCP RETURNED!\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
|
|
|
continue; /* whatever it was, it'll timeout */
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-05-05 09:35:42 +04:00
|
|
|
untimeout(uha_timeout, mscp);
|
1994-03-29 08:30:15 +04:00
|
|
|
uha_done(uha, mscp);
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U14_SINT) & U14_SDIP) == 0)
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
u24intr(arg)
|
|
|
|
void *arg;
|
1994-06-08 15:16:49 +04:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct uha_softc *uha = arg;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-06-08 15:16:49 +04:00
|
|
|
u_char uhastat;
|
|
|
|
u_long mboxval;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
|
|
|
|
#ifdef UHADEBUG
|
|
|
|
printf("%s: uhaintr ", uha->sc_dev.dv_xname);
|
|
|
|
#endif /*UHADEBUG */
|
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U24_SINT) & U24_SDIP) == 0)
|
1994-06-08 15:16:49 +04:00
|
|
|
return 0;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
for (;;) {
|
1994-06-08 15:16:49 +04:00
|
|
|
/*
|
|
|
|
* First get all the information and then
|
|
|
|
* acknowledge the interrupt
|
|
|
|
*/
|
|
|
|
uhastat = inb(iobase + U24_SINT);
|
|
|
|
mboxval = inl(iobase + U24_ICMPTR);
|
|
|
|
outb(iobase + U24_SINT, U24_ICM_ACK);
|
|
|
|
outb(iobase + U24_ICMCMD, 0);
|
|
|
|
|
|
|
|
#ifdef UHADEBUG
|
|
|
|
printf("status = 0x%x ", uhastat);
|
|
|
|
#endif /*UHADEBUG*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the completed operation
|
|
|
|
*/
|
|
|
|
mscp = uha_mscp_phys_kv(uha, mboxval);
|
|
|
|
if (!mscp) {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: BAD MSCP RETURNED!\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
|
|
|
continue; /* whatever it was, it'll timeout */
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
|
|
|
untimeout(uha_timeout, mscp);
|
|
|
|
uha_done(uha, mscp);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
if ((inb(iobase + U24_SINT) & U24_SDIP) == 0)
|
1994-12-28 22:42:47 +03:00
|
|
|
return 1;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* We have a mscp which has been processed by the adaptor, now we look to see
|
|
|
|
* how the operation went.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uha_done(uha, mscp)
|
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04: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
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((xs->flags & INUSE) == 0) {
|
|
|
|
printf("%s: exiting but not in use!\n", uha->sc_dev.dv_xname);
|
|
|
|
Debugger();
|
|
|
|
}
|
|
|
|
if (xs->error == XS_NOERROR) {
|
|
|
|
if (mscp->host_stat != UHA_NO_ERR) {
|
|
|
|
switch (mscp->host_stat) {
|
1994-03-29 08:30:15 +04:00
|
|
|
case UHA_SBUS_TIMEOUT: /* No response */
|
1994-12-28 22:42:47 +03:00
|
|
|
xs->error = XS_SELTIMEOUT;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
case UHA_SBUS_OVER_UNDER:
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3,
|
|
|
|
("scsi bus xfer over/underrun\n"));
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
case UHA_BAD_SG_LIST:
|
|
|
|
SC_DEBUG(xs->sc_link, SDEV_DB3,
|
|
|
|
("bad sg list reported back\n"));
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
default: /* Other scsi protocol messes */
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: host_stat %x\n",
|
|
|
|
uha->sc_dev.dv_xname, mscp->host_stat);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
} else if (mscp->target_stat != SCSI_OK) {
|
|
|
|
switch (mscp->target_stat) {
|
|
|
|
case SCSI_CHECK:
|
|
|
|
s1 = &mscp->mscp_sense;
|
|
|
|
s2 = &xs->sense;
|
|
|
|
*s2 = *s1;
|
|
|
|
xs->error = XS_SENSE;
|
|
|
|
break;
|
|
|
|
case SCSI_BUSY:
|
|
|
|
xs->error = XS_BUSY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: target_stat %x\n",
|
|
|
|
uha->sc_dev.dv_xname, mscp->target_stat);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
} else
|
|
|
|
xs->resid = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
xs->flags |= ITSDONE;
|
|
|
|
uha_free_mscp(uha, mscp, xs->flags);
|
|
|
|
scsi_done(xs);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* A mscp (and hence a mbx-out) is put onto the free list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uha_free_mscp(uha, mscp, flags)
|
|
|
|
struct uha_softc *uha;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
int opri;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
opri = splbio();
|
1993-03-21 21:04:42 +03:00
|
|
|
|
|
|
|
mscp->flags = MSCP_FREE;
|
1994-12-28 22:42:47 +03:00
|
|
|
TAILQ_INSERT_HEAD(&uha->free_mscp, mscp, chain);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there were none, wake abybody waiting for
|
|
|
|
* one to come free, starting with queued entries
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if (!mscp->chain.tqe_next)
|
|
|
|
wakeup(&uha->free_mscp);
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
splx(opri);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04: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.
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *
|
1994-03-29 08:30:15 +04:00
|
|
|
uha_get_mscp(uha, flags)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
int flags;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
int opri;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
int hashnum;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
opri = splbio();
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we can and have to, sleep waiting for one to come free
|
|
|
|
* but only if we can't allocate a new one
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
for (;;) {
|
|
|
|
mscp = uha->free_mscp.tqh_first;
|
|
|
|
if (mscp) {
|
|
|
|
TAILQ_REMOVE(&uha->free_mscp, mscp, chain);
|
|
|
|
break;
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
if (uha->nummscps < UHA_MSCP_MAX) {
|
1994-12-28 22:42:47 +03:00
|
|
|
if (mscp = (struct uha_mscp *) malloc(sizeof(struct uha_mscp),
|
1994-03-29 08:30:15 +04:00
|
|
|
M_TEMP, M_NOWAIT)) {
|
1994-12-28 22:42:47 +03:00
|
|
|
bzero(mscp, sizeof(struct uha_mscp));
|
1994-03-29 08:30:15 +04:00
|
|
|
uha->nummscps++;
|
|
|
|
/*
|
|
|
|
* put in the phystokv hash table
|
|
|
|
* Never gets taken out.
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->hashkey = KVTOPHYS(mscp);
|
|
|
|
hashnum = MSCP_HASH(mscp->hashkey);
|
|
|
|
mscp->nexthash = uha->mscphash[hashnum];
|
|
|
|
uha->mscphash[hashnum] = mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
} else {
|
1994-12-28 22:42:47 +03:00
|
|
|
printf("%s: can't malloc mscp\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
break;
|
1994-03-29 08:30:15 +04:00
|
|
|
} else {
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((flags & SCSI_NOSLEEP) == 0)
|
|
|
|
tsleep(&uha->free_mscp, PRIBIO, "uhamsc", 0);
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
splx(opri);
|
|
|
|
return mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* given a physical address, find the mscp that it corresponds to.
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *
|
1994-03-29 08:30:15 +04:00
|
|
|
uha_mscp_phys_kv(uha, mscp_phys)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
u_long mscp_phys;
|
|
|
|
{
|
|
|
|
int hashnum = MSCP_HASH(mscp_phys);
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp = uha->mscphash[hashnum];
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
while (mscp) {
|
|
|
|
if (mscp->hashkey == mscp_phys)
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp = mscp->nexthash;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
return mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the board, ready for normal operation
|
|
|
|
*/
|
|
|
|
int
|
1994-06-08 15:16:49 +04:00
|
|
|
u14_find(uha, ia)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc *uha;
|
1994-06-08 15:16:49 +04:00
|
|
|
struct isa_attach_args *ia;
|
1994-03-29 08:30:15 +04:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-07-31 23:21:40 +04:00
|
|
|
u_short model, config;
|
1994-03-29 08:30:15 +04:00
|
|
|
int resetcount = 4000; /* 4 secs? */
|
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
if (ia->ia_iobase == IOBASEUNK)
|
|
|
|
return ENXIO;
|
|
|
|
|
1994-07-31 23:21:40 +04:00
|
|
|
model = htons(inw(iobase + U14_ID));
|
|
|
|
if ((model & 0xfff0) != 0x5640)
|
1994-03-29 08:30:15 +04:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-07-31 23:21:40 +04:00
|
|
|
config = htons(inw(iobase + U14_CONFIG));
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-07-31 23:21:40 +04:00
|
|
|
switch (model & 0x000f) {
|
|
|
|
case 0x0001:
|
|
|
|
/* This is a 34f, and doens't need an ISA DMA channel. */
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_drq = DRQUNK;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
default:
|
1994-07-31 23:21:40 +04:00
|
|
|
switch (config & U14_DMA_MASK) {
|
|
|
|
case U14_DMA_CH5:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_drq = 5;
|
1994-07-31 23:21:40 +04:00
|
|
|
break;
|
|
|
|
case U14_DMA_CH6:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_drq = 6;
|
1994-07-31 23:21:40 +04:00
|
|
|
break;
|
|
|
|
case U14_DMA_CH7:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_drq = 7;
|
1994-07-31 23:21:40 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("illegal dma setting %x\n", config & U14_DMA_MASK);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
break;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-07-31 23:21:40 +04:00
|
|
|
switch (config & U14_IRQ_MASK) {
|
1994-06-08 15:16:49 +04:00
|
|
|
case U14_IRQ10:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 10;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-06-08 15:16:49 +04:00
|
|
|
case U14_IRQ11:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 11;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-06-08 15:16:49 +04:00
|
|
|
case U14_IRQ14:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 14;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
1994-06-08 15:16:49 +04:00
|
|
|
case U14_IRQ15:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 15;
|
1993-03-21 21:04:42 +03:00
|
|
|
break;
|
|
|
|
default:
|
1994-07-31 23:21:40 +04:00
|
|
|
printf("illegal int setting %x\n", config & U14_IRQ_MASK);
|
1994-03-29 08:30:15 +04:00
|
|
|
return EIO;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* who are we on the scsi bus */
|
1994-07-31 23:21:40 +04:00
|
|
|
uha->uha_scsi_dev = config & U14_HOSTID_MASK;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(iobase + U14_LINT, UHA_ASRST);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
while (--resetcount) {
|
1994-06-08 15:16:49 +04:00
|
|
|
if (inb(iobase + U14_LINT))
|
1994-03-29 08:30:15 +04:00
|
|
|
break;
|
|
|
|
delay(1000); /* 1 mSec per loop */
|
|
|
|
}
|
|
|
|
if (!resetcount) {
|
|
|
|
printf("%s: board timed out during reset\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
|
|
|
return ENXIO;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
/* Save function pointers for later use. */
|
|
|
|
uha->send_mbox = u14_send_mbox;
|
|
|
|
uha->abort = u14_abort;
|
|
|
|
uha->poll = u14_poll;
|
|
|
|
uha->intr = u14intr;
|
|
|
|
uha->init = u14_init;
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
return 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
int
|
|
|
|
u24_find(uha, ia)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
struct isa_attach_args *ia;
|
|
|
|
{
|
|
|
|
static int uha_slot = 0;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
u_short vendor, model;
|
|
|
|
u_char config0, config1, config2;
|
|
|
|
u_char irq_ch, uha_id;
|
|
|
|
int resetcount = 4000; /* 4 secs? */
|
|
|
|
|
|
|
|
if (ia->ia_iobase != IOBASEUNK)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
while (uha_slot < 15) {
|
|
|
|
uha_slot++;
|
|
|
|
iobase = 0x1000 * uha_slot;
|
|
|
|
|
|
|
|
vendor = htons(inw(iobase + EISA_VENDOR));
|
|
|
|
if (vendor != 0x5663) /* `USC' */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
model = htons(inw(iobase + EISA_MODEL));
|
|
|
|
if ((model & 0xfff0) != 0x0240) {
|
|
|
|
#ifndef trusted
|
|
|
|
printf("u24_find: ignoring model %04x\n", model);
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1994-08-23 01:53:23 +04:00
|
|
|
#if 0
|
1994-07-28 06:39:21 +04:00
|
|
|
outb(iobase + EISA_CONTROL, EISA_ENABLE | EISA_RESET);
|
|
|
|
delay(10);
|
|
|
|
outb(iobase + EISA_CONTROL, EISA_ENABLE);
|
|
|
|
/* Wait for reset? */
|
|
|
|
delay(1000);
|
1994-08-23 01:53:23 +04:00
|
|
|
#endif
|
1994-06-08 15:16:49 +04:00
|
|
|
|
|
|
|
config0 = inb(iobase + U24_CONFIG);
|
|
|
|
config1 = inb(iobase + U24_CONFIG + 1);
|
|
|
|
config2 = inb(iobase + U24_CONFIG + 2);
|
|
|
|
if ((config0 & U24_MAGIC1) == 0 ||
|
|
|
|
(config1 & U24_MAGIC2) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
irq_ch = config0 & U24_IRQ_MASK;
|
|
|
|
uha_id = config2 & U24_HOSTID_MASK;
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_drq = DRQUNK;
|
1994-07-27 17:10:33 +04:00
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
switch (irq_ch) {
|
|
|
|
case U24_IRQ10:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 10;
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
case U24_IRQ11:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 11;
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
case U24_IRQ14:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 14;
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
case U24_IRQ15:
|
1994-12-28 22:42:47 +03:00
|
|
|
uha->sc_irq = 15;
|
1994-06-08 15:16:49 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("illegal int setting %x\n", irq_ch);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* who are we on the scsi bus */
|
1994-07-27 17:24:17 +04:00
|
|
|
uha->uha_scsi_dev = uha_id;
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(iobase + U24_LINT, UHA_ASRST);
|
1994-06-08 15:16:49 +04:00
|
|
|
|
|
|
|
while (--resetcount) {
|
|
|
|
if (inb(iobase + U24_LINT))
|
|
|
|
break;
|
|
|
|
delay(1000); /* 1 mSec per loop */
|
|
|
|
}
|
|
|
|
if (!resetcount) {
|
|
|
|
printf("%s: board timed out during reset\n",
|
|
|
|
uha->sc_dev.dv_xname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save function pointers for later use. */
|
|
|
|
uha->send_mbox = u24_send_mbox;
|
|
|
|
uha->abort = u24_abort;
|
|
|
|
uha->poll = u24_poll;
|
|
|
|
uha->intr = u24intr;
|
|
|
|
uha->init = u24_init;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
void
|
1994-06-08 15:16:49 +04:00
|
|
|
u14_init(uha)
|
1994-03-29 08:30:15 +04:00
|
|
|
struct uha_softc *uha;
|
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
/* make sure interrupts are enabled */
|
1995-03-14 05:35:11 +03:00
|
|
|
#ifdef UHADEBUG
|
1995-02-10 04:37:57 +03:00
|
|
|
printf("u14_init: lmask=%02x, smask=%02x\n",
|
|
|
|
inb(iobase + U14_LMASK), inb(iobase + U14_SMASK));
|
1995-03-14 05:35:11 +03:00
|
|
|
#endif
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(0xd1, iobase + U14_LMASK); /* XXX */
|
|
|
|
outb(0x91, iobase + U14_SMASK); /* XXX */
|
1994-06-08 15:16:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
u24_init(uha)
|
|
|
|
struct uha_softc *uha;
|
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = uha->sc_iobase;
|
1994-06-08 15:16:49 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
/* free OGM and ICM */
|
|
|
|
outb(iobase + U24_OGMCMD, 0);
|
|
|
|
outb(iobase + U24_ICMCMD, 0);
|
1994-06-08 15:16:49 +04:00
|
|
|
/* make sure interrupts are enabled */
|
1995-03-14 05:35:11 +03:00
|
|
|
#ifdef UHADEBUG
|
1995-02-10 04:37:57 +03:00
|
|
|
printf("u24_init: lmask=%02x, smask=%02x\n",
|
|
|
|
inb(iobase + U24_LMASK), inb(iobase + U24_SMASK));
|
1995-03-14 05:35:11 +03:00
|
|
|
#endif
|
1995-02-10 04:37:57 +03:00
|
|
|
outb(0xd2, iobase + U24_LMASK); /* XXX */
|
|
|
|
outb(0x92, iobase + U24_SMASK); /* XXX */
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1995-07-24 11:16:44 +04:00
|
|
|
u_int
|
1994-03-29 08:30:15 +04:00
|
|
|
uhaminphys(bp)
|
|
|
|
struct buf *bp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
if (bp->b_bcount > ((UHA_NSEG - 1) << PGSHIFT))
|
|
|
|
bp->b_bcount = ((UHA_NSEG - 1) << PGSHIFT);
|
1995-07-24 11:16:44 +04:00
|
|
|
return (minphys(bp));
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* start a scsi operation given the command and the data address. Also
|
|
|
|
* needs the unit, target and lu.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
uha_scsi_cmd(xs)
|
|
|
|
struct scsi_xfer *xs;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct uha_softc *uha = sc_link->adapter_softc;
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
struct uha_dma_seg *sg;
|
1994-03-29 08:30:15 +04:00
|
|
|
int seg; /* scatter gather seg being worked on */
|
|
|
|
u_long thiskv, thisphys, nextphys;
|
|
|
|
int bytes_this_seg, bytes_this_page, datalen, flags;
|
|
|
|
struct iovec *iovp;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
SC_DEBUG(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-03-21 21:04:42 +03:00
|
|
|
flags = xs->flags;
|
1995-01-13 17:46:44 +03:00
|
|
|
if ((flags & (ITSDONE|INUSE)) != INUSE) {
|
|
|
|
printf("%s: done or not in use?\n", uha->sc_dev.dv_xname);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->flags &= ~ITSDONE;
|
|
|
|
xs->flags |= INUSE;
|
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((mscp = uha_get_mscp(uha, flags)) == NULL) {
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1994-03-29 08:30:15 +04:00
|
|
|
return TRY_AGAIN_LATER;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->flags = MSCP_ACTIVE;
|
1993-03-21 21:04:42 +03:00
|
|
|
mscp->xs = xs;
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Put all the arguments for the xfer in the mscp
|
|
|
|
*/
|
|
|
|
if (flags & SCSI_RESET) {
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->opcode = UHA_SDR;
|
1993-03-21 21:04:42 +03:00
|
|
|
mscp->ca = 0x01;
|
1994-03-29 08:30:15 +04:00
|
|
|
} else {
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->opcode = UHA_TSP;
|
|
|
|
/* XXX Not for tapes. */
|
1993-03-21 21:04:42 +03:00
|
|
|
mscp->ca = 0x01;
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->xdir = UHA_SDET;
|
1994-03-29 08:30:15 +04:00
|
|
|
mscp->dcn = 0x00;
|
|
|
|
mscp->chan = 0x00;
|
|
|
|
mscp->target = sc_link->target;
|
|
|
|
mscp->lun = sc_link->lun;
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->scsi_cmd_length = xs->cmdlen;
|
|
|
|
mscp->sense_ptr = KVTOPHYS(&mscp->mscp_sense);
|
|
|
|
mscp->req_sense_length = sizeof(mscp->mscp_sense);
|
|
|
|
mscp->host_stat = 0x00;
|
|
|
|
mscp->target_stat = 0x00;
|
|
|
|
|
|
|
|
if (xs->datalen && (flags & SCSI_RESET) == 0) {
|
|
|
|
mscp->data_addr = KVTOPHYS(mscp->uha_dma);
|
1994-03-29 08:30:15 +04:00
|
|
|
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-03-21 21:04:42 +03:00
|
|
|
xs->datalen = 0;
|
1994-03-29 08:30:15 +04:00
|
|
|
while (datalen && seg < UHA_NSEG) {
|
1994-12-28 22:42:47 +03:00
|
|
|
sg->seg_addr = (physaddr)iovp->iov_base;
|
|
|
|
sg->seg_len = iovp->iov_len;
|
|
|
|
xs->datalen += iovp->iov_len;
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("(0x%x@0x%x)",
|
1994-12-28 22:42:47 +03:00
|
|
|
iovp->iov_len, iovp->iov_base));
|
1993-03-21 21:04:42 +03:00
|
|
|
sg++;
|
|
|
|
iovp++;
|
|
|
|
seg++;
|
|
|
|
datalen--;
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
} else
|
|
|
|
#endif /*TFS */
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Set up the scatter gather block
|
|
|
|
*/
|
|
|
|
SC_DEBUG(sc_link, SDEV_DB4,
|
1994-12-28 22:42:47 +03:00
|
|
|
("%d @0x%x:- ", xs->datalen, xs->data));
|
1994-03-29 08:30:15 +04:00
|
|
|
datalen = xs->datalen;
|
|
|
|
thiskv = (int) xs->data;
|
|
|
|
thisphys = KVTOPHYS(thiskv);
|
|
|
|
|
|
|
|
while (datalen && seg < UHA_NSEG) {
|
|
|
|
bytes_this_seg = 0;
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* put in the base address */
|
1994-12-28 22:42:47 +03:00
|
|
|
sg->seg_addr = thisphys;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("0x%x", thisphys));
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* do it at least once */
|
1994-03-29 08:30:15 +04:00
|
|
|
nextphys = thisphys;
|
|
|
|
while (datalen && thisphys == nextphys) {
|
|
|
|
/*
|
|
|
|
* This page is contiguous (physically)
|
|
|
|
* with the the last, just extend the
|
|
|
|
* length
|
|
|
|
*/
|
1993-03-21 21:04:42 +03:00
|
|
|
/* how far to the end of the page */
|
1994-03-29 08:30:15 +04:00
|
|
|
nextphys = (thisphys & ~PGOFSET) + NBPG;
|
1993-03-21 21:04:42 +03:00
|
|
|
bytes_this_page = nextphys - thisphys;
|
|
|
|
/**** or the data ****/
|
1994-03-29 08:30:15 +04:00
|
|
|
bytes_this_page = min(bytes_this_page,
|
|
|
|
datalen);
|
|
|
|
bytes_this_seg += bytes_this_page;
|
|
|
|
datalen -= bytes_this_page;
|
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
/* get more ready for the next page */
|
1994-03-29 08:30:15 +04:00
|
|
|
thiskv = (thiskv & ~PGOFSET) + NBPG;
|
|
|
|
if (datalen)
|
1993-03-21 21:04:42 +03:00
|
|
|
thisphys = KVTOPHYS(thiskv);
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* next page isn't contiguous, finish the seg
|
|
|
|
*/
|
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4,
|
1994-12-28 22:42:47 +03:00
|
|
|
("(0x%x)", bytes_this_seg));
|
|
|
|
sg->seg_len = bytes_this_seg;
|
1993-03-21 21:04:42 +03:00
|
|
|
sg++;
|
|
|
|
seg++;
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
}
|
|
|
|
/* end of iov/kv decision */
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->data_length = xs->datalen;
|
1993-03-21 21:04:42 +03:00
|
|
|
mscp->sg_num = seg;
|
1994-03-29 08:30:15 +04:00
|
|
|
SC_DEBUGN(sc_link, SDEV_DB4, ("\n"));
|
1994-12-28 22:42:47 +03:00
|
|
|
if (datalen) {
|
|
|
|
/*
|
|
|
|
* there's still data, must have run out of segs!
|
|
|
|
*/
|
|
|
|
printf("%s: uha_scsi_cmd, more than %d dma segs\n",
|
|
|
|
uha->sc_dev.dv_xname, UHA_NSEG);
|
1993-03-21 21:04:42 +03:00
|
|
|
xs->error = XS_DRIVER_STUFFUP;
|
1994-03-29 08:30:15 +04:00
|
|
|
uha_free_mscp(uha, mscp, flags);
|
1994-12-28 22:42:47 +03:00
|
|
|
return COMPLETE;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
} else { /* No data xfer, use non S/G values */
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->data_addr = (physaddr)0;
|
|
|
|
mscp->data_length = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
mscp->sgth = 0x00;
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->sg_num = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->link_id = 0;
|
|
|
|
mscp->link_addr = (physaddr)0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Put the scsi command in the mscp and start it
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((flags & SCSI_RESET) == 0)
|
|
|
|
bcopy(xs->cmd, &mscp->scsi_cmd, mscp->scsi_cmd_length);
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
(uha->send_mbox)(uha, mscp);
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* Usually return SUCCESSFULLY QUEUED
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((flags & SCSI_POLL) == 0) {
|
1994-05-11 06:28:42 +04:00
|
|
|
timeout(uha_timeout, mscp, (xs->timeout * hz) / 1000);
|
1993-03-21 21:04:42 +03:00
|
|
|
splx(s);
|
1994-03-29 08:30:15 +04:00
|
|
|
return SUCCESSFULLY_QUEUED;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
splx(s);
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
/*
|
|
|
|
* If we can't use interrupts, poll on completion
|
|
|
|
*/
|
1994-12-28 22:42:47 +03:00
|
|
|
if ((uha->poll)(uha, xs, xs->timeout)) {
|
|
|
|
uha_timeout(mscp);
|
|
|
|
if (!(uha->abort)(uha, mscp))
|
|
|
|
uha_timeout(mscp);
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
return COMPLETE;
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
void
|
1993-03-21 21:04:42 +03:00
|
|
|
uha_timeout(arg)
|
1994-05-05 09:35:42 +04:00
|
|
|
void *arg;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp = arg;
|
|
|
|
struct scsi_xfer *xs = mscp->xs;
|
|
|
|
struct scsi_link *sc_link = xs->sc_link;
|
|
|
|
struct uha_softc *uha = sc_link->adapter_softc;
|
|
|
|
int s;
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
sc_print_addr(sc_link);
|
1994-03-29 08:30:15 +04:00
|
|
|
printf("timed out");
|
|
|
|
|
1994-12-28 22:42:47 +03:00
|
|
|
s = splbio();
|
1994-03-29 08:30:15 +04:00
|
|
|
|
1994-06-08 15:16:49 +04:00
|
|
|
if (!(uha->abort)(uha, mscp) || (mscp->flags == MSCP_ABORTED)) {
|
1994-12-28 22:42:47 +03:00
|
|
|
/* abort timed out */
|
1994-03-29 08:30:15 +04:00
|
|
|
printf(" AGAIN\n");
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->xs->retries = 0; /* I MEAN IT ! */
|
|
|
|
mscp->host_stat = UHA_SBUS_TIMEOUT;
|
1994-03-29 08:30:15 +04:00
|
|
|
uha_done(uha, mscp);
|
1994-12-28 22:42:47 +03:00
|
|
|
} else {
|
|
|
|
/* abort the operation that has timed out */
|
1994-03-29 08:30:15 +04:00
|
|
|
printf("\n");
|
|
|
|
mscp->flags = MSCP_ABORTED;
|
1994-12-28 22:42:47 +03:00
|
|
|
/* 2 secs for the abort */
|
|
|
|
if ((xs->flags & SCSI_POLL) == 0)
|
|
|
|
timeout(uha_timeout, mscp, 2 * hz);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
1994-12-28 22:42:47 +03:00
|
|
|
|
1993-03-21 21:04:42 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
#ifdef UHADEBUG
|
|
|
|
void
|
1993-03-21 21:04:42 +03:00
|
|
|
uha_print_mscp(mscp)
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-03-29 08:30:15 +04:00
|
|
|
|
|
|
|
printf("mscp:%x op:%x cmdlen:%d senlen:%d\n",
|
|
|
|
mscp, mscp->opcode, mscp->cdblen, mscp->senselen);
|
|
|
|
printf(" sg:%d sgnum:%x datlen:%d hstat:%x tstat:%x flags:%x\n",
|
1994-12-28 22:42:47 +03:00
|
|
|
mscp->sgth, mscp->sg_num, mscp->datalen, mscp->host_stat,
|
|
|
|
mscp->target_stat, mscp->flags);
|
1994-03-29 08:30:15 +04:00
|
|
|
show_scsi_cmd(mscp->xs);
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
void
|
|
|
|
uha_print_active_mscp(uha)
|
|
|
|
struct uha_softc *uha;
|
1993-03-21 21:04:42 +03:00
|
|
|
{
|
1994-12-28 22:42:47 +03:00
|
|
|
struct uha_mscp *mscp;
|
1994-03-29 08:30:15 +04:00
|
|
|
int i = 0;
|
1993-03-21 21:04:42 +03:00
|
|
|
|
1994-03-29 08:30:15 +04:00
|
|
|
while (i++ < MSCP_HASH_SIZE) {
|
|
|
|
mscp = uha->mscphash[i];
|
|
|
|
while (mscp) {
|
|
|
|
if (mscp->flags != MSCP_FREE)
|
|
|
|
uha_print_mscp(mscp);
|
|
|
|
mscp = mscp->nexthash;
|
|
|
|
}
|
1993-03-21 21:04:42 +03:00
|
|
|
}
|
|
|
|
}
|
1994-03-29 08:30:15 +04:00
|
|
|
#endif /*UHADEBUG */
|