1997-10-20 22:43:03 +04:00
|
|
|
/* $NetBSD: wt.c,v 1.41 1997/10/20 18:43:22 thorpej Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Streamer tape driver.
|
|
|
|
* Supports Archive and Wangtek compatible QIC-02/QIC-36 boards.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993 by:
|
|
|
|
* Sergey Ryzhkov <sir@kiae.su>
|
|
|
|
* Serge Vakulenko <vak@zebub.msk.su>
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1994-03-29 08:32:12 +04:00
|
|
|
* This software is distributed with NO WARRANTIES, not even the implied
|
|
|
|
* warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Authors grant any other persons or organisations permission to use
|
|
|
|
* or modify this software as long as this message is kept with the software,
|
|
|
|
* all derivative works or modified versions.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1994-03-29 08:32:12 +04:00
|
|
|
* This driver is derived from the old 386bsd Wangtek streamer tape driver,
|
|
|
|
* made by Robert Baron at CMU, based on Intel sources.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1989 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Authors: Robert Baron
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1988, 1989 by Intel Corporation
|
|
|
|
*/
|
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
1994-03-29 08:32:12 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/buf.h>
|
1994-03-29 08:32:12 +04:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mtio.h>
|
|
|
|
#include <sys/device.h>
|
1996-04-29 23:45:32 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/conf.h>
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
#include <vm/vm_param.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1996-05-13 03:51:23 +04:00
|
|
|
#include <machine/intr.h>
|
1997-06-07 03:43:45 +04:00
|
|
|
#include <machine/bus.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
1995-04-17 16:06:30 +04:00
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
1995-01-29 10:36:54 +03:00
|
|
|
#include <dev/isa/wtreg.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Uncomment this to enable internal device tracing.
|
|
|
|
*/
|
1996-10-13 05:37:04 +04:00
|
|
|
#define WTDBPRINT(x) /* printf x */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
#define WTPRI (PZERO+10) /* sleep priority */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Wangtek controller ports
|
|
|
|
*/
|
1997-08-08 13:38:18 +04:00
|
|
|
#define WT_CTLPORT (ia->ia_iobase + 0 ) /* control, write only */
|
|
|
|
#define WT_STATPORT (ia->ia_iobase + 0 ) /* status, read only */
|
|
|
|
#define WT_CMDPORT (ia->ia_iobase + 1 ) /* command, write only */
|
|
|
|
#define WT_DATAPORT (ia->ia_iobase + 1 ) /* data, read only */
|
1994-03-29 08:32:12 +04:00
|
|
|
#define WT_NPORT 2 /* 2 i/o ports */
|
|
|
|
|
|
|
|
/* status port bits */
|
|
|
|
#define WT_BUSY 0x01 /* not ready bit define */
|
|
|
|
#define WT_NOEXCEP 0x02 /* no exception bit define */
|
|
|
|
#define WT_RESETMASK 0x07 /* to check after reset */
|
|
|
|
#define WT_RESETVAL 0x05 /* state after reset */
|
|
|
|
|
|
|
|
/* control port bits */
|
|
|
|
#define WT_ONLINE 0x01 /* device selected */
|
|
|
|
#define WT_RESET 0x02 /* reset command */
|
|
|
|
#define WT_REQUEST 0x04 /* request command */
|
|
|
|
#define WT_IEN 0x08 /* enable dma */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Archive controller ports
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1997-08-08 13:38:18 +04:00
|
|
|
#define AV_DATAPORT (ia->ia_iobase + 0) /* data, read only */
|
|
|
|
#define AV_CMDPORT (ia->ia_iobase + 0) /* command, write only */
|
|
|
|
#define AV_STATPORT (ia->ia_iobase + 1) /* status, read only */
|
|
|
|
#define AV_CTLPORT (ia->ia_iobase + 1) /* control, write only */
|
|
|
|
#define AV_SDMAPORT (ia->ia_iobase + 2) /* start dma */
|
|
|
|
#define AV_RDMAPORT (ia->ia_iobase + 3) /* reset dma */
|
1994-03-29 08:32:12 +04:00
|
|
|
#define AV_NPORT 4 /* 4 i/o ports */
|
|
|
|
|
|
|
|
/* status port bits */
|
|
|
|
#define AV_BUSY 0x40 /* not ready bit define */
|
|
|
|
#define AV_NOEXCEP 0x20 /* no exception bit define */
|
|
|
|
#define AV_RESETMASK 0xf8 /* to check after reset */
|
|
|
|
#define AV_RESETVAL 0x50 /* state after reset */
|
|
|
|
|
|
|
|
/* control port bits */
|
|
|
|
#define AV_RESET 0x80 /* reset command */
|
|
|
|
#define AV_REQUEST 0x40 /* request command */
|
|
|
|
#define AV_IEN 0x20 /* enable interrupts */
|
|
|
|
|
|
|
|
enum wttype {
|
|
|
|
UNKNOWN = 0, /* unknown type, driver disabled */
|
|
|
|
ARCHIVE, /* Archive Viper SC499, SC402 etc */
|
|
|
|
WANGTEK, /* Wangtek */
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
struct wt_softc {
|
|
|
|
struct device sc_dev;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_space_handle_t sc_ioh;
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
enum wttype type; /* type of controller */
|
1994-11-19 00:57:40 +03:00
|
|
|
int chan; /* dma channel number, 1..3 */
|
1994-03-29 08:32:12 +04:00
|
|
|
int flags; /* state of tape drive */
|
|
|
|
unsigned dens; /* tape density */
|
|
|
|
int bsize; /* tape block size */
|
|
|
|
void *buf; /* internal i/o buffer */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
void *dmavaddr; /* virtual address of dma i/o buffer */
|
|
|
|
size_t dmatotal; /* size of i/o buffer */
|
1996-03-01 07:08:13 +03:00
|
|
|
int dmaflags; /* i/o direction */
|
1994-03-29 08:32:12 +04:00
|
|
|
size_t dmacount; /* resulting length of dma i/o */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
u_short error; /* code for error encountered */
|
|
|
|
u_short ercnt; /* number of error blocks */
|
|
|
|
u_short urcnt; /* number of underruns */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-11-19 00:57:40 +03:00
|
|
|
int DATAPORT, CMDPORT, STATPORT, CTLPORT, SDMAPORT, RDMAPORT;
|
1994-03-29 08:32:12 +04:00
|
|
|
u_char BUSY, NOEXCEP, RESETMASK, RESETVAL, ONLINE, RESET, REQUEST, IEN;
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-04-29 23:45:32 +04:00
|
|
|
/* XXX: These don't belong here really */
|
|
|
|
cdev_decl(wt);
|
|
|
|
bdev_decl(wt);
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
int wtwait __P((struct wt_softc *sc, int catch, char *msg));
|
|
|
|
int wtcmd __P((struct wt_softc *sc, int cmd));
|
|
|
|
int wtstart __P((struct wt_softc *sc, int flag, void *vaddr, size_t len));
|
|
|
|
void wtdma __P((struct wt_softc *sc));
|
1994-05-05 09:35:42 +04:00
|
|
|
void wttimer __P((void *arg));
|
1994-03-29 08:32:12 +04:00
|
|
|
void wtclock __P((struct wt_softc *sc));
|
|
|
|
int wtreset __P((struct wt_softc *sc));
|
|
|
|
int wtsense __P((struct wt_softc *sc, int verbose, int ignore));
|
|
|
|
int wtstatus __P((struct wt_softc *sc));
|
|
|
|
void wtrewind __P((struct wt_softc *sc));
|
|
|
|
int wtreadfm __P((struct wt_softc *sc));
|
|
|
|
int wtwritefm __P((struct wt_softc *sc));
|
1996-09-05 19:37:18 +04:00
|
|
|
u_char wtsoft __P((struct wt_softc *sc, int mask, int bits));
|
1994-03-29 08:32:12 +04:00
|
|
|
|
1994-11-04 02:21:24 +03:00
|
|
|
int wtprobe __P((struct device *, void *, void *));
|
|
|
|
void wtattach __P((struct device *, struct device *, void *));
|
1995-04-17 16:06:30 +04:00
|
|
|
int wtintr __P((void *sc));
|
1994-03-29 08:32:12 +04:00
|
|
|
|
1996-03-17 03:53:54 +03:00
|
|
|
struct cfattach wt_ca = {
|
|
|
|
sizeof(struct wt_softc), wtprobe, wtattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver wt_cd = {
|
|
|
|
NULL, "wt", DV_TAPE
|
1994-03-29 08:32:12 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Probe for the presence of the device.
|
|
|
|
*/
|
|
|
|
int
|
1994-11-04 02:21:24 +03:00
|
|
|
wtprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1994-03-29 08:32:12 +04:00
|
|
|
{
|
1994-11-04 02:21:24 +03:00
|
|
|
struct wt_softc *sc = match;
|
1994-03-29 08:32:12 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
1997-10-19 22:56:39 +04:00
|
|
|
/* Disallow wildcarded i/o address. */
|
|
|
|
if (ia->ia_iobase == ISACF_PORT_DEFAULT)
|
|
|
|
return (0);
|
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* Map i/o space */
|
|
|
|
if (bus_space_map(iot, ia->ia_iobase, AV_NPORT, 0, &ioh))
|
|
|
|
return 0;
|
1994-03-29 08:32:12 +04:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* XXX broken_indirect_config */
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->chan = ia->ia_drq;
|
|
|
|
if (sc->chan < 1 || sc->chan > 3) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: Bad drq=%d, should be 1..3\n", sc->sc_dev.dv_xname,
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->chan);
|
1997-08-05 05:13:50 +04:00
|
|
|
rv = 0;
|
|
|
|
goto done;
|
1994-03-29 08:32:12 +04:00
|
|
|
}
|
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* Try Wangtek. */
|
|
|
|
sc->type = WANGTEK;
|
1997-08-05 05:13:50 +04:00
|
|
|
sc->CTLPORT = WT_CTLPORT;
|
|
|
|
sc->STATPORT = WT_STATPORT;
|
|
|
|
sc->CMDPORT = WT_CMDPORT;
|
|
|
|
sc->DATAPORT = WT_DATAPORT;
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->SDMAPORT = sc->RDMAPORT = 0;
|
|
|
|
sc->BUSY = WT_BUSY; sc->NOEXCEP = WT_NOEXCEP;
|
|
|
|
sc->RESETMASK = WT_RESETMASK; sc->RESETVAL = WT_RESETVAL;
|
|
|
|
sc->ONLINE = WT_ONLINE; sc->RESET = WT_RESET;
|
|
|
|
sc->REQUEST = WT_REQUEST; sc->IEN = WT_IEN;
|
1994-04-21 04:41:52 +04:00
|
|
|
if (wtreset(sc)) {
|
|
|
|
ia->ia_iosize = WT_NPORT;
|
1997-08-05 05:13:50 +04:00
|
|
|
rv = 1;
|
|
|
|
goto done;
|
1994-04-21 04:41:52 +04:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/* Try Archive. */
|
|
|
|
sc->type = ARCHIVE;
|
1997-08-05 05:13:50 +04:00
|
|
|
sc->CTLPORT = AV_CTLPORT;
|
|
|
|
sc->STATPORT = AV_STATPORT;
|
|
|
|
sc->CMDPORT = AV_CMDPORT;
|
|
|
|
sc->DATAPORT = AV_DATAPORT;
|
|
|
|
sc->SDMAPORT = AV_SDMAPORT;
|
|
|
|
sc->RDMAPORT = AV_RDMAPORT;
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->BUSY = AV_BUSY; sc->NOEXCEP = AV_NOEXCEP;
|
|
|
|
sc->RESETMASK = AV_RESETMASK; sc->RESETVAL = AV_RESETVAL;
|
|
|
|
sc->ONLINE = 0; sc->RESET = AV_RESET;
|
|
|
|
sc->REQUEST = AV_REQUEST; sc->IEN = AV_IEN;
|
1994-04-21 04:41:52 +04:00
|
|
|
if (wtreset(sc)) {
|
|
|
|
ia->ia_iosize = AV_NPORT;
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_unmap(iot, ioh, AV_NPORT);
|
|
|
|
rv = 1;
|
|
|
|
goto done;
|
1994-04-21 04:41:52 +04:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/* Tape controller not found. */
|
|
|
|
sc->type = UNKNOWN;
|
1997-08-05 05:13:50 +04:00
|
|
|
|
|
|
|
done:
|
|
|
|
bus_space_unmap(iot, ioh, AV_NPORT);
|
|
|
|
return rv;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Device is found, configure it.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-29 08:32:12 +04:00
|
|
|
void
|
|
|
|
wtattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
struct wt_softc *sc = (void *)self;
|
1994-04-07 10:48:19 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = ia->ia_iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
|
|
|
|
/* Map i/o space */
|
1997-10-20 22:43:03 +04:00
|
|
|
if (bus_space_map(iot, ia->ia_iobase, AV_NPORT, 0, &ioh)) {
|
|
|
|
printf(": can't map i/o space\n");
|
|
|
|
return;
|
|
|
|
}
|
1997-08-05 05:13:50 +04:00
|
|
|
|
|
|
|
sc->sc_iot = iot;
|
|
|
|
sc->sc_ioh = ioh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* XXX broken_indirect_config */
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->type == ARCHIVE) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(": type <Archive>\n");
|
1994-03-29 08:32:12 +04:00
|
|
|
/* Reset DMA. */
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_write_1(iot, ioh, sc->RDMAPORT, 0);
|
1994-03-29 08:32:12 +04:00
|
|
|
} else
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(": type <Wangtek>\n");
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags = TPSTART; /* tape is rewound */
|
|
|
|
sc->dens = -1; /* unknown density */
|
1994-04-07 10:48:19 +04:00
|
|
|
|
1997-06-07 03:43:45 +04:00
|
|
|
if (isa_dmamap_create(parent, sc->chan, MAXPHYS,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
|
|
|
|
printf("%s: can't set up ISA DMA map\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-04-12 02:27:59 +04:00
|
|
|
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
|
|
|
|
IPL_BIO, wtintr, sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
int
|
1995-06-26 09:34:44 +04:00
|
|
|
wtdump(dev, blkno, va, size)
|
1994-03-29 08:32:12 +04:00
|
|
|
dev_t dev;
|
1995-06-26 09:34:44 +04:00
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/* Not implemented. */
|
1995-06-26 09:34:44 +04:00
|
|
|
return ENXIO;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
int
|
|
|
|
wtsize(dev)
|
|
|
|
dev_t dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Open routine, called on every device open.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-29 08:32:12 +04:00
|
|
|
int
|
1996-04-29 23:45:32 +04:00
|
|
|
wtopen(dev, flag, mode, p)
|
1994-03-29 08:32:12 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
1996-04-29 23:45:32 +04:00
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1994-03-29 08:32:12 +04:00
|
|
|
{
|
|
|
|
int unit = minor(dev) & T_UNIT;
|
|
|
|
struct wt_softc *sc;
|
|
|
|
int error;
|
|
|
|
|
1996-03-17 03:53:54 +03:00
|
|
|
if (unit >= wt_cd.cd_ndevs)
|
1994-03-29 08:32:12 +04:00
|
|
|
return ENXIO;
|
1996-03-17 03:53:54 +03:00
|
|
|
sc = wt_cd.cd_devs[unit];
|
1994-03-29 08:32:12 +04:00
|
|
|
if (!sc)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
/* Check that device is not in use */
|
|
|
|
if (sc->flags & TPINUSE)
|
|
|
|
return EBUSY;
|
|
|
|
|
|
|
|
/* If the tape is in rewound state, check the status and set density. */
|
|
|
|
if (sc->flags & TPSTART) {
|
|
|
|
/* If rewind is going on, wait */
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wtrew")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Check the controller status */
|
|
|
|
if (!wtsense(sc, 0, (flag & FWRITE) ? 0 : TP_WRP)) {
|
|
|
|
/* Bad status, reset the controller. */
|
|
|
|
if (!wtreset(sc))
|
|
|
|
return EIO;
|
|
|
|
if (!wtsense(sc, 1, (flag & FWRITE) ? 0 : TP_WRP))
|
|
|
|
return EIO;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/* Set up tape density. */
|
|
|
|
if (sc->dens != (minor(dev) & WT_DENSEL)) {
|
|
|
|
int d = 0;
|
|
|
|
|
|
|
|
switch (minor(dev) & WT_DENSEL) {
|
|
|
|
case WT_DENSDFLT:
|
|
|
|
default:
|
|
|
|
break; /* default density */
|
|
|
|
case WT_QIC11:
|
|
|
|
d = QIC_FMT11; break; /* minor 010 */
|
|
|
|
case WT_QIC24:
|
|
|
|
d = QIC_FMT24; break; /* minor 020 */
|
|
|
|
case WT_QIC120:
|
|
|
|
d = QIC_FMT120; break; /* minor 030 */
|
|
|
|
case WT_QIC150:
|
|
|
|
d = QIC_FMT150; break; /* minor 040 */
|
|
|
|
case WT_QIC300:
|
|
|
|
d = QIC_FMT300; break; /* minor 050 */
|
|
|
|
case WT_QIC600:
|
|
|
|
d = QIC_FMT600; break; /* minor 060 */
|
|
|
|
}
|
|
|
|
if (d) {
|
|
|
|
/* Change tape density. */
|
|
|
|
if (!wtcmd(sc, d))
|
|
|
|
return EIO;
|
|
|
|
if (!wtsense(sc, 1, TP_WRP | TP_ILL))
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
/* Check the status of the controller. */
|
|
|
|
if (sc->error & TP_ILL) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: invalid tape density\n",
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sc->dens = minor(dev) & WT_DENSEL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags &= ~TPSTART;
|
|
|
|
} else if (sc->dens != (minor(dev) & WT_DENSEL))
|
|
|
|
return ENXIO;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->bsize = (minor(dev) & WT_BSIZE) ? 1024 : 512;
|
|
|
|
sc->buf = malloc(sc->bsize, M_TEMP, M_WAITOK);
|
|
|
|
|
|
|
|
sc->flags = TPINUSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (flag & FREAD)
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags |= TPREAD;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (flag & FWRITE)
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags |= TPWRITE;
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-03-29 08:32:12 +04:00
|
|
|
* Close routine, called on last device close.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-29 08:32:12 +04:00
|
|
|
int
|
1996-04-29 23:45:32 +04:00
|
|
|
wtclose(dev, flags, mode, p)
|
1994-03-29 08:32:12 +04:00
|
|
|
dev_t dev;
|
1996-04-29 23:45:32 +04:00
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
int unit = minor(dev) & T_UNIT;
|
1996-03-17 03:53:54 +03:00
|
|
|
struct wt_softc *sc = wt_cd.cd_devs[unit];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* If rewind is pending, do nothing */
|
|
|
|
if (sc->flags & TPREW)
|
|
|
|
goto done;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* If seek forward is pending and no rewind on close, do nothing */
|
|
|
|
if (sc->flags & TPRMARK) {
|
|
|
|
if (minor(dev) & T_NOREWIND)
|
|
|
|
goto done;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* If read file mark is going on, wait */
|
|
|
|
wtwait(sc, 0, "wtrfm");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->flags & TPWANY) {
|
|
|
|
/* Tape was written. Write file mark. */
|
|
|
|
wtwritefm(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if ((minor(dev) & T_NOREWIND) == 0) {
|
|
|
|
/* Rewind to beginning of tape. */
|
|
|
|
/* Don't wait until rewind, though. */
|
|
|
|
wtrewind(sc);
|
|
|
|
goto done;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
if ((sc->flags & TPRANY) && (sc->flags & (TPVOL | TPWANY)) == 0) {
|
|
|
|
/* Space forward to after next file mark if no writing done. */
|
|
|
|
/* Don't wait for completion. */
|
|
|
|
wtreadfm(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
done:
|
|
|
|
sc->flags &= TPREW | TPRMARK | TPSTART | TPTIMER;
|
|
|
|
free(sc->buf, M_TEMP);
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Ioctl routine. Compatible with BSD ioctls.
|
|
|
|
* Direct QIC-02 commands ERASE and RETENSION added.
|
|
|
|
* There are three possible ioctls:
|
|
|
|
* ioctl(int fd, MTIOCGET, struct mtget *buf) -- get status
|
|
|
|
* ioctl(int fd, MTIOCTOP, struct mtop *buf) -- do BSD-like op
|
|
|
|
* ioctl(int fd, WTQICMD, int qicop) -- do QIC op
|
|
|
|
*/
|
|
|
|
int
|
1996-04-29 23:45:32 +04:00
|
|
|
wtioctl(dev, cmd, addr, flag, p)
|
1994-03-29 08:32:12 +04:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1996-04-29 23:45:32 +04:00
|
|
|
caddr_t addr;
|
1994-03-29 08:32:12 +04:00
|
|
|
int flag;
|
1996-04-29 23:45:32 +04:00
|
|
|
struct proc *p;
|
1994-03-29 08:32:12 +04:00
|
|
|
{
|
|
|
|
int unit = minor(dev) & T_UNIT;
|
1996-03-17 03:53:54 +03:00
|
|
|
struct wt_softc *sc = wt_cd.cd_devs[unit];
|
1994-03-29 08:32:12 +04:00
|
|
|
int error, count, op;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
case WTQICMD: /* direct QIC command */
|
|
|
|
op = *(int *)addr;
|
|
|
|
switch (op) {
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
case QIC_ERASE: /* erase the whole tape */
|
|
|
|
if ((sc->flags & TPWRITE) == 0 || (sc->flags & TPWP))
|
|
|
|
return EACCES;
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wterase")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-29 08:32:12 +04:00
|
|
|
case QIC_RETENS: /* retension the tape */
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wtretens")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-29 08:32:12 +04:00
|
|
|
}
|
|
|
|
/* Both ERASE and RETENS operations work like REWIND. */
|
|
|
|
/* Simulate the rewind operation here. */
|
|
|
|
sc->flags &= ~(TPRO | TPWO | TPVOL);
|
|
|
|
if (!wtcmd(sc, op))
|
|
|
|
return EIO;
|
|
|
|
sc->flags |= TPSTART | TPREW;
|
|
|
|
if (op == QIC_ERASE)
|
|
|
|
sc->flags |= TPWANY;
|
|
|
|
wtclock(sc);
|
|
|
|
return 0;
|
|
|
|
case MTIOCIEOT: /* ignore EOT errors */
|
|
|
|
case MTIOCEEOT: /* enable EOT errors */
|
|
|
|
return 0;
|
|
|
|
case MTIOCGET:
|
|
|
|
((struct mtget*)addr)->mt_type =
|
|
|
|
sc->type == ARCHIVE ? MT_ISVIPER1 : 0x11;
|
|
|
|
((struct mtget*)addr)->mt_dsreg = sc->flags; /* status */
|
|
|
|
((struct mtget*)addr)->mt_erreg = sc->error; /* errors */
|
|
|
|
((struct mtget*)addr)->mt_resid = 0;
|
|
|
|
((struct mtget*)addr)->mt_fileno = 0; /* file */
|
|
|
|
((struct mtget*)addr)->mt_blkno = 0; /* block */
|
|
|
|
return 0;
|
|
|
|
case MTIOCTOP:
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
switch ((short)((struct mtop*)addr)->mt_op) {
|
|
|
|
default:
|
|
|
|
#if 0
|
|
|
|
case MTFSR: /* forward space record */
|
|
|
|
case MTBSR: /* backward space record */
|
|
|
|
case MTBSF: /* backward space file */
|
|
|
|
#endif
|
|
|
|
return EINVAL;
|
|
|
|
case MTNOP: /* no operation, sets status only */
|
|
|
|
case MTCACHE: /* enable controller cache */
|
|
|
|
case MTNOCACHE: /* disable controller cache */
|
|
|
|
return 0;
|
|
|
|
case MTREW: /* rewind */
|
|
|
|
case MTOFFL: /* rewind and put the drive offline */
|
|
|
|
if (sc->flags & TPREW) /* rewind is running */
|
|
|
|
return 0;
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wtorew")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
|
|
|
wtrewind(sc);
|
|
|
|
return 0;
|
|
|
|
case MTFSF: /* forward space file */
|
|
|
|
for (count = ((struct mtop*)addr)->mt_count; count > 0;
|
|
|
|
--count) {
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wtorfm")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtreadfm(sc)) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
|
|
|
case MTWEOF: /* write an end-of-file record */
|
|
|
|
if ((sc->flags & TPWRITE) == 0 || (sc->flags & TPWP))
|
|
|
|
return EACCES;
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwait(sc, PCATCH, "wtowfm")) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = wtwritefm(sc)) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("wtioctl: impossible");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Strategy routine.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wtstrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
int unit = minor(bp->b_dev) & T_UNIT;
|
1996-03-17 03:53:54 +03:00
|
|
|
struct wt_softc *sc = wt_cd.cd_devs[unit];
|
1994-03-29 08:32:12 +04:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* at file marks and end of tape, we just return '0 bytes available' */
|
|
|
|
if (sc->flags & TPVOL)
|
|
|
|
goto xit;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (bp->b_flags & B_READ) {
|
|
|
|
/* Check read access and no previous write to this tape. */
|
|
|
|
if ((sc->flags & TPREAD) == 0 || (sc->flags & TPWANY))
|
|
|
|
goto errxit;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* For now, we assume that all data will be copied out */
|
|
|
|
/* If read command outstanding, just skip down */
|
|
|
|
if ((sc->flags & TPRO) == 0) {
|
|
|
|
if (!wtsense(sc, 1, TP_WRP)) {
|
|
|
|
/* Clear status. */
|
|
|
|
goto errxit;
|
|
|
|
}
|
|
|
|
if (!wtcmd(sc, QIC_RDDATA)) {
|
|
|
|
/* Set read mode. */
|
|
|
|
wtsense(sc, 1, TP_WRP);
|
|
|
|
goto errxit;
|
|
|
|
}
|
|
|
|
sc->flags |= TPRO | TPRANY;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Check write access and write protection. */
|
|
|
|
/* No previous read from this tape allowed. */
|
|
|
|
if ((sc->flags & TPWRITE) == 0 || (sc->flags & (TPWP | TPRANY)))
|
|
|
|
goto errxit;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* If write command outstanding, just skip down */
|
|
|
|
if ((sc->flags & TPWO) == 0) {
|
|
|
|
if (!wtsense(sc, 1, 0)) {
|
|
|
|
/* Clear status. */
|
|
|
|
goto errxit;
|
|
|
|
}
|
|
|
|
if (!wtcmd(sc, QIC_WRTDATA)) {
|
|
|
|
/* Set write mode. */
|
|
|
|
wtsense(sc, 1, 0);
|
|
|
|
goto errxit;
|
|
|
|
}
|
|
|
|
sc->flags |= TPWO | TPWANY;
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto xit;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags &= ~TPEXCEP;
|
|
|
|
s = splbio();
|
1994-06-16 05:07:30 +04:00
|
|
|
if (wtstart(sc, bp->b_flags, bp->b_data, bp->b_bcount)) {
|
1994-03-29 08:32:12 +04:00
|
|
|
wtwait(sc, 0, (bp->b_flags & B_READ) ? "wtread" : "wtwrite");
|
|
|
|
bp->b_resid -= sc->dmacount;
|
|
|
|
}
|
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->flags & TPEXCEP) {
|
|
|
|
errxit:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
}
|
|
|
|
xit:
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1996-04-29 23:45:32 +04:00
|
|
|
wtread(dev, uio, flags)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-04-29 23:45:32 +04:00
|
|
|
int flags;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(wtstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-04-29 23:45:32 +04:00
|
|
|
wtwrite(dev, uio, flags)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-04-29 23:45:32 +04:00
|
|
|
int flags;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(wtstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Interrupt routine.
|
|
|
|
*/
|
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
wtintr(arg)
|
|
|
|
void *arg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct wt_softc *sc = arg;
|
1994-07-25 08:29:56 +04:00
|
|
|
u_char x;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* get status */
|
|
|
|
x = bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->STATPORT);
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wtintr() status=0x%x -- ", x));
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & (sc->BUSY | sc->NOEXCEP)) == (sc->BUSY | sc->NOEXCEP)) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("busy\n"));
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0; /* device is busy */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Check if rewind finished.
|
|
|
|
*/
|
|
|
|
if (sc->flags & TPREW) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(((x & (sc->BUSY | sc->NOEXCEP)) == (sc->BUSY | sc->NOEXCEP) ?
|
1994-03-29 08:32:12 +04:00
|
|
|
"rewind busy?\n" : "rewind finished\n"));
|
|
|
|
sc->flags &= ~TPREW; /* rewind finished */
|
|
|
|
wtsense(sc, 1, TP_WRP);
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
return 1;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Check if writing/reading of file mark finished.
|
|
|
|
*/
|
|
|
|
if (sc->flags & (TPRMARK | TPWMARK)) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(((x & (sc->BUSY | sc->NOEXCEP)) == (sc->BUSY | sc->NOEXCEP) ?
|
1994-03-29 08:32:12 +04:00
|
|
|
"marker r/w busy?\n" : "marker r/w finished\n"));
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->NOEXCEP) == 0) /* operation failed */
|
1994-03-29 08:32:12 +04:00
|
|
|
wtsense(sc, 1, (sc->flags & TPRMARK) ? TP_WRP : 0);
|
|
|
|
sc->flags &= ~(TPRMARK | TPWMARK); /* operation finished */
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we started any i/o? If no, just return.
|
|
|
|
*/
|
|
|
|
if ((sc->flags & TPACTIVE) == 0) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("unexpected interrupt\n"));
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
sc->flags &= ~TPACTIVE;
|
|
|
|
sc->dmacount += sc->bsize; /* increment counter */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Clean up dma.
|
|
|
|
*/
|
1996-03-01 07:08:13 +03:00
|
|
|
if ((sc->dmaflags & DMAMODE_READ) &&
|
1994-03-29 08:32:12 +04:00
|
|
|
(sc->dmatotal - sc->dmacount) < sc->bsize) {
|
|
|
|
/* If reading short block, copy the internal buffer
|
|
|
|
* to the user memory. */
|
1997-06-07 03:43:45 +04:00
|
|
|
isa_dmadone(sc->sc_dev.dv_parent, sc->chan);
|
1994-03-29 08:32:12 +04:00
|
|
|
bcopy(sc->buf, sc->dmavaddr, sc->dmatotal - sc->dmacount);
|
|
|
|
} else
|
1997-06-07 03:43:45 +04:00
|
|
|
isa_dmadone(sc->sc_dev.dv_parent, sc->chan);
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* On exception, check for end of file and end of volume.
|
|
|
|
*/
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->NOEXCEP) == 0) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("i/o exception\n"));
|
1996-03-01 07:08:13 +03:00
|
|
|
wtsense(sc, 1, (sc->dmaflags & DMAMODE_READ) ? TP_WRP : 0);
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->error & (TP_EOM | TP_FIL))
|
|
|
|
sc->flags |= TPVOL; /* end of file */
|
|
|
|
else
|
|
|
|
sc->flags |= TPEXCEP; /* i/o error */
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->dmacount < sc->dmatotal) {
|
|
|
|
/* Continue I/O. */
|
|
|
|
sc->dmavaddr += sc->bsize;
|
|
|
|
wtdma(sc);
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("continue i/o, %d\n", sc->dmacount));
|
1994-03-29 08:32:12 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (sc->dmacount > sc->dmatotal) /* short last block */
|
|
|
|
sc->dmacount = sc->dmatotal;
|
|
|
|
/* Wake up user level. */
|
|
|
|
wakeup((caddr_t)sc);
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("i/o finished, %d\n", sc->dmacount));
|
1994-03-29 08:32:12 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start the rewind operation */
|
|
|
|
void
|
|
|
|
wtrewind(sc)
|
|
|
|
struct wt_softc *sc;
|
|
|
|
{
|
|
|
|
int rwmode = sc->flags & (TPRO | TPWO);
|
|
|
|
|
|
|
|
sc->flags &= ~(TPRO | TPWO | TPVOL);
|
|
|
|
/*
|
|
|
|
* Wangtek strictly follows QIC-02 standard:
|
|
|
|
* clearing ONLINE in read/write modes causes rewind.
|
|
|
|
* REWIND command is not allowed in read/write mode
|
|
|
|
* and gives `illegal command' error.
|
|
|
|
*/
|
|
|
|
if (sc->type == WANGTEK && rwmode) {
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->CTLPORT, 0);
|
1994-03-29 08:32:12 +04:00
|
|
|
} else if (!wtcmd(sc, QIC_REWIND))
|
|
|
|
return;
|
|
|
|
sc->flags |= TPSTART | TPREW;
|
|
|
|
wtclock(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Start the `read marker' operation.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtreadfm(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
sc->flags &= ~(TPRO | TPWO | TPVOL);
|
|
|
|
if (!wtcmd(sc, QIC_READFM)) {
|
|
|
|
wtsense(sc, 1, TP_WRP);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
sc->flags |= TPRMARK | TPRANY;
|
|
|
|
wtclock(sc);
|
|
|
|
/* Don't wait for completion here. */
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Write marker to the tape.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtwritefm(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
|
|
|
|
tsleep((caddr_t)wtwritefm, WTPRI, "wtwfm", hz);
|
|
|
|
sc->flags &= ~(TPRO | TPWO);
|
|
|
|
if (!wtcmd(sc, QIC_WRITEFM)) {
|
|
|
|
wtsense(sc, 1, 0);
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
sc->flags |= TPWMARK | TPWANY;
|
|
|
|
wtclock(sc);
|
|
|
|
return wtwait(sc, 0, "wtwfm");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* While controller status & mask == bits continue waiting.
|
|
|
|
*/
|
|
|
|
u_char
|
1996-09-05 19:37:18 +04:00
|
|
|
wtsoft(sc, mask, bits)
|
1994-03-29 08:32:12 +04:00
|
|
|
struct wt_softc *sc;
|
|
|
|
int mask, bits;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-07-25 08:29:56 +04:00
|
|
|
u_char x;
|
1994-03-29 08:32:12 +04:00
|
|
|
int i;
|
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* Poll status port, waiting for specified bits. */
|
|
|
|
for (i = 0; i < 1000; ++i) { /* up to 1 msec */
|
1997-08-05 05:13:50 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, sc->STATPORT);
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & mask) != bits)
|
|
|
|
return x;
|
1994-03-29 08:32:12 +04:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 100; ++i) { /* up to 10 msec */
|
1997-08-05 05:13:50 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, sc->STATPORT);
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & mask) != bits)
|
|
|
|
return x;
|
1994-03-29 08:32:12 +04:00
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
for (;;) { /* forever */
|
1997-08-05 05:13:50 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, sc->STATPORT);
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & mask) != bits)
|
|
|
|
return x;
|
1996-09-05 19:37:18 +04:00
|
|
|
tsleep((caddr_t)wtsoft, WTPRI, "wtsoft", 1);
|
1994-03-29 08:32:12 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Execute QIC command.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtcmd(sc, cmd)
|
|
|
|
struct wt_softc *sc;
|
|
|
|
int cmd;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-07-25 08:29:56 +04:00
|
|
|
u_char x;
|
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wtcmd() cmd=0x%x\n", cmd));
|
1994-07-25 08:29:56 +04:00
|
|
|
s = splbio();
|
1996-09-05 19:37:18 +04:00
|
|
|
x = wtsoft(sc, sc->BUSY | sc->NOEXCEP, sc->BUSY | sc->NOEXCEP); /* ready? */
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->NOEXCEP) == 0) { /* error */
|
|
|
|
splx(s);
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
1994-07-25 08:29:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* output the command */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CMDPORT, cmd);
|
|
|
|
|
|
|
|
/* set request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->REQUEST | sc->ONLINE);
|
|
|
|
|
|
|
|
/* wait for ready */
|
|
|
|
wtsoft(sc, sc->BUSY, sc->BUSY);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* reset request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->IEN | sc->ONLINE);
|
|
|
|
|
|
|
|
/* wait for not ready */
|
|
|
|
wtsoft(sc, sc->BUSY, 0);
|
1994-07-25 08:29:56 +04:00
|
|
|
splx(s);
|
1994-03-29 08:32:12 +04:00
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* wait for the end of i/o, seeking marker or rewind operation */
|
|
|
|
int
|
|
|
|
wtwait(sc, catch, msg)
|
|
|
|
struct wt_softc *sc;
|
|
|
|
int catch;
|
|
|
|
char *msg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:12 +04:00
|
|
|
int error;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wtwait() `%s'\n", msg));
|
1994-03-29 08:32:12 +04:00
|
|
|
while (sc->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK))
|
1996-04-29 23:45:32 +04:00
|
|
|
if ((error = tsleep((caddr_t)sc, WTPRI | catch, msg, 0)) != 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
return error;
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* initialize dma for the i/o operation */
|
|
|
|
void
|
|
|
|
wtdma(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags |= TPACTIVE;
|
|
|
|
wtclock(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->type == ARCHIVE) {
|
|
|
|
/* Set DMA. */
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_write_1(iot, ioh, sc->SDMAPORT, 0);
|
1994-03-29 08:32:12 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-03-01 07:08:13 +03:00
|
|
|
if ((sc->dmaflags & DMAMODE_READ) &&
|
1994-03-29 08:32:12 +04:00
|
|
|
(sc->dmatotal - sc->dmacount) < sc->bsize) {
|
|
|
|
/* Reading short block; do it through the internal buffer. */
|
1997-06-07 03:43:45 +04:00
|
|
|
isa_dmastart(sc->sc_dev.dv_parent, sc->chan, sc->buf,
|
|
|
|
sc->bsize, NULL, sc->dmaflags, BUS_DMA_NOWAIT);
|
1994-03-29 08:32:12 +04:00
|
|
|
} else
|
1997-06-07 03:43:45 +04:00
|
|
|
isa_dmastart(sc->sc_dev.dv_parent, sc->chan, sc->dmavaddr,
|
|
|
|
sc->bsize, NULL, sc->dmaflags, BUS_DMA_NOWAIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* start i/o operation */
|
|
|
|
int
|
|
|
|
wtstart(sc, flag, vaddr, len)
|
|
|
|
struct wt_softc *sc;
|
|
|
|
int flag;
|
|
|
|
void *vaddr;
|
|
|
|
size_t len;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-07-25 08:29:56 +04:00
|
|
|
u_char x;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wtstart()\n"));
|
1996-09-05 19:37:18 +04:00
|
|
|
x = wtsoft(sc, sc->BUSY | sc->NOEXCEP, sc->BUSY | sc->NOEXCEP); /* ready? */
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->NOEXCEP) == 0) {
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags |= TPEXCEP; /* error */
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags &= ~TPEXCEP; /* clear exception flag */
|
|
|
|
sc->dmavaddr = vaddr;
|
|
|
|
sc->dmatotal = len;
|
|
|
|
sc->dmacount = 0;
|
1996-03-01 07:08:13 +03:00
|
|
|
sc->dmaflags = flag & B_READ ? DMAMODE_READ : DMAMODE_WRITE;
|
1994-03-29 08:32:12 +04:00
|
|
|
wtdma(sc);
|
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Start timer.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wtclock(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
if (sc->flags & TPTIMER)
|
|
|
|
return;
|
|
|
|
sc->flags |= TPTIMER;
|
|
|
|
/*
|
|
|
|
* Some controllers seem to lose dma interrupts too often. To make the
|
|
|
|
* tape stream we need 1 tick timeout.
|
|
|
|
*/
|
1994-05-05 12:31:44 +04:00
|
|
|
timeout(wttimer, sc, (sc->flags & TPACTIVE) ? 1 : hz);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Simulate an interrupt periodically while i/o is going.
|
|
|
|
* This is necessary in case interrupts get eaten due to
|
|
|
|
* multiple devices on a single IRQ line.
|
|
|
|
*/
|
|
|
|
void
|
1994-05-05 09:35:42 +04:00
|
|
|
wttimer(arg)
|
|
|
|
void *arg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
register struct wt_softc *sc = (struct wt_softc *)arg;
|
1994-03-29 08:32:12 +04:00
|
|
|
int s;
|
1997-08-05 05:13:50 +04:00
|
|
|
u_char status;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags &= ~TPTIMER;
|
|
|
|
if ((sc->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK)) == 0)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* If i/o going, simulate interrupt. */
|
|
|
|
s = splbio();
|
1997-08-05 05:13:50 +04:00
|
|
|
status = bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->STATPORT);
|
|
|
|
if ((status & (sc->BUSY | sc->NOEXCEP)) != (sc->BUSY | sc->NOEXCEP)) {
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wttimer() -- "));
|
1994-04-07 10:48:19 +04:00
|
|
|
wtintr(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:12 +04:00
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* Restart timer if i/o pending. */
|
|
|
|
if (sc->flags & (TPACTIVE | TPREW | TPRMARK | TPWMARK))
|
|
|
|
wtclock(sc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Perform QIC-02 and QIC-36 compatible reset sequence.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtreset(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-07-25 08:29:56 +04:00
|
|
|
u_char x;
|
1994-03-29 08:32:12 +04:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* send reset */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->RESET | sc->ONLINE);
|
1994-03-29 08:32:12 +04:00
|
|
|
delay(30);
|
1997-08-05 05:13:50 +04:00
|
|
|
/* turn off reset */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->ONLINE);
|
1994-03-29 08:32:12 +04:00
|
|
|
delay(30);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/* Read the controller status. */
|
1997-08-05 05:13:50 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, sc->STATPORT);
|
1994-07-25 08:29:56 +04:00
|
|
|
if (x == 0xff) /* no port at this address? */
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Wait 3 sec for reset to complete. Needed for QIC-36 boards? */
|
|
|
|
for (i = 0; i < 3000; ++i) {
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->BUSY) == 0 || (x & sc->NOEXCEP) == 0)
|
1994-03-29 08:32:12 +04:00
|
|
|
break;
|
|
|
|
delay(1000);
|
1997-08-05 05:13:50 +04:00
|
|
|
x = bus_space_read_1(iot, ioh, sc->STATPORT);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-07-25 08:29:56 +04:00
|
|
|
return (x & sc->RESETMASK) == sc->RESETVAL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Get controller status information. Return 0 if user i/o request should
|
|
|
|
* receive an i/o error code.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtsense(sc, verbose, ignore)
|
|
|
|
struct wt_softc *sc;
|
|
|
|
int verbose, ignore;
|
|
|
|
{
|
|
|
|
char *msg = 0;
|
|
|
|
int error;
|
|
|
|
|
1996-01-12 03:54:23 +03:00
|
|
|
WTDBPRINT(("wtsense() ignore=0x%x\n", ignore));
|
1994-03-29 08:32:12 +04:00
|
|
|
sc->flags &= ~(TPRO | TPWO);
|
|
|
|
if (!wtstatus(sc))
|
|
|
|
return 0;
|
|
|
|
if ((sc->error & TP_ST0) == 0)
|
|
|
|
sc->error &= ~TP_ST0MASK;
|
|
|
|
if ((sc->error & TP_ST1) == 0)
|
|
|
|
sc->error &= ~TP_ST1MASK;
|
|
|
|
sc->error &= ~ignore; /* ignore certain errors */
|
|
|
|
error = sc->error & (TP_FIL | TP_BNL | TP_UDA | TP_EOM | TP_WRP |
|
|
|
|
TP_USL | TP_CNI | TP_MBD | TP_NDT | TP_ILL);
|
|
|
|
if (!error)
|
|
|
|
return 1;
|
|
|
|
if (!verbose)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* lifted from tdriver.c from Wangtek */
|
|
|
|
if (error & TP_USL)
|
|
|
|
msg = "Drive not online";
|
|
|
|
else if (error & TP_CNI)
|
|
|
|
msg = "No cartridge";
|
|
|
|
else if ((error & TP_WRP) && (sc->flags & TPWP) == 0) {
|
|
|
|
msg = "Tape is write protected";
|
|
|
|
sc->flags |= TPWP;
|
|
|
|
} else if (error & TP_FIL)
|
|
|
|
msg = 0 /*"Filemark detected"*/;
|
|
|
|
else if (error & TP_EOM)
|
|
|
|
msg = 0 /*"End of tape"*/;
|
|
|
|
else if (error & TP_BNL)
|
|
|
|
msg = "Block not located";
|
|
|
|
else if (error & TP_UDA)
|
|
|
|
msg = "Unrecoverable data error";
|
|
|
|
else if (error & TP_NDT)
|
|
|
|
msg = "No data detected";
|
|
|
|
else if (error & TP_ILL)
|
|
|
|
msg = "Illegal command";
|
|
|
|
if (msg)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: %s\n", sc->sc_dev.dv_xname, msg);
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
/*
|
|
|
|
* Get controller status information.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
wtstatus(sc)
|
|
|
|
struct wt_softc *sc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-08-05 05:13:50 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
1994-03-29 08:32:12 +04:00
|
|
|
char *p;
|
1994-07-25 08:29:56 +04:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-07-25 08:29:56 +04:00
|
|
|
s = splbio();
|
1996-09-05 19:37:18 +04:00
|
|
|
wtsoft(sc, sc->BUSY | sc->NOEXCEP, sc->BUSY | sc->NOEXCEP); /* ready? */
|
1997-08-05 05:13:50 +04:00
|
|
|
/* send `read status' command */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CMDPORT, QIC_RDSTAT);
|
|
|
|
|
|
|
|
/* set request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->REQUEST | sc->ONLINE);
|
|
|
|
|
|
|
|
/* wait for ready */
|
|
|
|
wtsoft(sc, sc->BUSY, sc->BUSY);
|
|
|
|
/* reset request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->ONLINE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* wait for not ready */
|
|
|
|
wtsoft(sc, sc->BUSY, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:12 +04:00
|
|
|
p = (char *)&sc->error;
|
|
|
|
while (p < (char *)&sc->error + 6) {
|
1997-08-05 05:13:50 +04:00
|
|
|
u_char x = wtsoft(sc, sc->BUSY | sc->NOEXCEP,
|
|
|
|
sc->BUSY | sc->NOEXCEP);
|
|
|
|
|
1994-07-25 08:29:56 +04:00
|
|
|
if ((x & sc->NOEXCEP) == 0) { /* error */
|
|
|
|
splx(s);
|
1994-03-29 08:32:12 +04:00
|
|
|
return 0;
|
1994-07-25 08:29:56 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* read status byte */
|
|
|
|
*p++ = bus_space_read_1(iot, ioh, sc->DATAPORT);
|
|
|
|
|
|
|
|
/* set request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT,
|
|
|
|
sc->REQUEST | sc->ONLINE);
|
|
|
|
|
|
|
|
/* wait for not ready */
|
|
|
|
wtsoft(sc, sc->BUSY, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-08-05 05:13:50 +04:00
|
|
|
/* unset request */
|
|
|
|
bus_space_write_1(iot, ioh, sc->CTLPORT, sc->ONLINE);
|
1994-03-29 08:32:12 +04:00
|
|
|
}
|
1994-07-25 08:29:56 +04:00
|
|
|
splx(s);
|
1994-03-29 08:32:12 +04:00
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|