1995-06-26 09:20:40 +04:00
|
|
|
/* $NetBSD: fd.c,v 1.75 1995/06/26 05:20:40 cgd Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-01-13 10:57:01 +03:00
|
|
|
* Copyright (c) 1993, 1994, 1995 Charles Hannum.
|
1993-03-21 12:45:37 +03:00
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Don Ahn.
|
|
|
|
*
|
|
|
|
* 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 the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
1994-10-27 07:14:23 +03:00
|
|
|
* @(#)fd.c 7.4 (Berkeley) 5/25/91
|
1993-06-18 10:19:16 +04:00
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-03-29 08:32:39 +04:00
|
|
|
#include <sys/kernel.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-03-29 08:32:39 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/disk.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/uio.h>
|
1994-03-29 08:32:39 +04:00
|
|
|
#include <sys/syslog.h>
|
1994-04-20 11:23:52 +04:00
|
|
|
#include <sys/queue.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1994-03-08 15:21:10 +03:00
|
|
|
#include <machine/cpu.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>
|
1994-03-29 08:32:39 +04:00
|
|
|
#include <i386/isa/fdreg.h>
|
1995-05-04 23:39:08 +04:00
|
|
|
|
|
|
|
#include <dev/ic/mc146818.h> /* for NVRAM access */
|
1994-03-29 08:32:39 +04:00
|
|
|
#include <i386/isa/nvram.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-07-26 23:36:06 +04:00
|
|
|
#define FDUNIT(dev) (minor(dev) / 8)
|
|
|
|
#define FDTYPE(dev) (minor(dev) % 8)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define b_cylin b_resid
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
enum fdc_state {
|
|
|
|
DEVIDLE = 0,
|
|
|
|
MOTORWAIT,
|
|
|
|
DOSEEK,
|
|
|
|
SEEKWAIT,
|
|
|
|
SEEKTIMEDOUT,
|
|
|
|
SEEKCOMPLETE,
|
|
|
|
DOIO,
|
|
|
|
IOCOMPLETE,
|
|
|
|
IOTIMEDOUT,
|
|
|
|
DORESET,
|
|
|
|
RESETCOMPLETE,
|
|
|
|
RESETTIMEDOUT,
|
|
|
|
DORECAL,
|
|
|
|
RECALWAIT,
|
|
|
|
RECALTIMEDOUT,
|
|
|
|
RECALCOMPLETE,
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* software state, per controller */
|
|
|
|
struct fdc_softc {
|
|
|
|
struct device sc_dev; /* boilerplate */
|
|
|
|
struct isadev sc_id;
|
1995-04-17 16:06:30 +04:00
|
|
|
void *sc_ih;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1994-11-19 00:57:40 +03:00
|
|
|
int sc_iobase;
|
|
|
|
int sc_drq;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
struct fd_softc *sc_fd[4]; /* pointers to children */
|
1994-04-20 11:23:52 +04:00
|
|
|
TAILQ_HEAD(drivehead, fd_softc) sc_drives;
|
1994-03-29 08:32:39 +04:00
|
|
|
enum fdc_state sc_state;
|
1994-10-20 07:46:17 +03:00
|
|
|
int sc_errors; /* number of retries so far */
|
1994-03-29 08:32:39 +04:00
|
|
|
u_char sc_status[7]; /* copy of registers */
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* controller driver configuration */
|
1994-11-04 01:55:58 +03:00
|
|
|
int fdcprobe __P((struct device *, void *, void *));
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef NEWCONFIG
|
|
|
|
void fdcforceintr __P((void *));
|
|
|
|
#endif
|
1994-11-04 01:55:58 +03:00
|
|
|
void fdcattach __P((struct device *, struct device *, void *));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
struct cfdriver fdccd = {
|
1994-11-05 01:51:59 +03:00
|
|
|
NULL, "fdc", fdcprobe, fdcattach, DV_DULL, sizeof(struct fdc_softc)
|
1994-03-29 08:32:39 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/*
|
|
|
|
* Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how
|
|
|
|
* we tell them apart.
|
|
|
|
*/
|
|
|
|
struct fd_type {
|
|
|
|
int sectrac; /* sectors per track */
|
1995-01-13 10:57:01 +03:00
|
|
|
int heads; /* number of heads */
|
|
|
|
int seccyl; /* sectors per cylinder */
|
1994-03-29 08:32:39 +04:00
|
|
|
int secsize; /* size code for sectors */
|
|
|
|
int datalen; /* data len when secsize = 0 */
|
|
|
|
int steprate; /* step rate and head unload time */
|
|
|
|
int gap1; /* gap len between sectors */
|
|
|
|
int gap2; /* formatting gap */
|
|
|
|
int tracks; /* total num of tracks */
|
|
|
|
int size; /* size of disk in sectors */
|
|
|
|
int step; /* steps per cylinder */
|
|
|
|
int rate; /* transfer speed code */
|
|
|
|
char *name;
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* The order of entries in the following table is important -- BEWARE! */
|
|
|
|
struct fd_type fd_types[] = {
|
1995-01-13 10:57:01 +03:00
|
|
|
{ 18,2,36,2,0xff,0xcf,0x1b,0x6c,80,2880,1,FDC_500KBPS,"1.44MB" }, /* 1.44MB diskette */
|
|
|
|
{ 15,2,30,2,0xff,0xdf,0x1b,0x54,80,2400,1,FDC_500KBPS, "1.2MB" }, /* 1.2 MB AT-diskettes */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x23,0x50,40, 720,2,FDC_300KBPS, "360KB/AT" }, /* 360kB in 1.2MB drive */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,1,FDC_250KBPS, "360KB/PC" }, /* 360kB PC diskettes */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,80,1440,1,FDC_250KBPS, "720KB" }, /* 3.5" 720kB diskette */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x23,0x50,80,1440,1,FDC_300KBPS, "720KB/x" }, /* 720kB in 1.2MB drive */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,2,FDC_250KBPS, "360KB/x" }, /* 360kB in 720kB drive */
|
1994-03-29 08:32:39 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* software state, per disk (with up to 4 disks per ctlr) */
|
|
|
|
struct fd_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct dkdevice sc_dk;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fd_type *sc_deftype; /* default type descriptor */
|
1995-01-13 11:29:25 +03:00
|
|
|
struct fd_type *sc_type; /* current type descriptor */
|
1995-01-13 13:35:58 +03:00
|
|
|
|
|
|
|
daddr_t sc_blkno; /* starting block number */
|
|
|
|
int sc_bcount; /* byte count left */
|
|
|
|
int sc_skip; /* bytes already transferred */
|
|
|
|
int sc_nblks; /* number of blocks currently tranferring */
|
1995-01-13 14:14:27 +03:00
|
|
|
int sc_nbytes; /* number of bytes currently tranferring */
|
1995-01-13 13:35:58 +03:00
|
|
|
|
|
|
|
int sc_drive; /* physical unit number */
|
1994-03-29 08:32:39 +04:00
|
|
|
int sc_flags;
|
|
|
|
#define FD_OPEN 0x01 /* it's open */
|
|
|
|
#define FD_MOTOR 0x02 /* motor should be on */
|
|
|
|
#define FD_MOTOR_WAIT 0x04 /* motor coming up */
|
1995-01-13 13:35:58 +03:00
|
|
|
int sc_cylin; /* where we think the head is */
|
|
|
|
|
|
|
|
TAILQ_ENTRY(fd_softc) sc_drivechain;
|
|
|
|
int sc_ops; /* I/O ops since last switch */
|
|
|
|
struct buf sc_q; /* head of buf chain */
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* floppy driver configuration */
|
1994-11-04 01:55:58 +03:00
|
|
|
int fdprobe __P((struct device *, void *, void *));
|
|
|
|
void fdattach __P((struct device *, struct device *, void *));
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
struct cfdriver fdcd = {
|
|
|
|
NULL, "fd", fdprobe, fdattach, DV_DISK, sizeof(struct fd_softc)
|
1994-03-10 22:57:20 +03:00
|
|
|
};
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
void fdgetdisklabel __P((struct fd_softc *));
|
1995-01-13 11:37:25 +03:00
|
|
|
int fd_get_parms __P((struct fd_softc *));
|
1995-01-13 10:57:01 +03:00
|
|
|
void fdstrategy __P((struct buf *));
|
|
|
|
void fdstart __P((struct fd_softc *));
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
struct dkdriver fddkdriver = { fdstrategy };
|
|
|
|
|
|
|
|
struct fd_type *fd_nvtotype __P((char *, int, int));
|
|
|
|
void fd_set_motor __P((struct fdc_softc *fdc, int reset));
|
1994-05-05 09:35:42 +04:00
|
|
|
void fd_motor_off __P((void *arg));
|
|
|
|
void fd_motor_on __P((void *arg));
|
1994-03-29 08:32:39 +04:00
|
|
|
int fdcresult __P((struct fdc_softc *fdc));
|
1994-11-19 00:57:40 +03:00
|
|
|
int out_fdc __P((int iobase, u_char x));
|
1994-03-29 08:32:39 +04:00
|
|
|
void fdcstart __P((struct fdc_softc *fdc));
|
|
|
|
void fdcstatus __P((struct device *dv, int n, char *s));
|
1994-05-05 09:35:42 +04:00
|
|
|
void fdctimeout __P((void *arg));
|
|
|
|
void fdcpseudointr __P((void *arg));
|
1995-04-17 16:06:30 +04:00
|
|
|
int fdcintr __P((void *));
|
1994-04-08 22:51:19 +04:00
|
|
|
void fdcretry __P((struct fdc_softc *fdc));
|
1994-04-20 11:23:52 +04:00
|
|
|
void fdfinish __P((struct fd_softc *fd, struct buf *bp));
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
int
|
1994-11-04 01:55:58 +03:00
|
|
|
fdcprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1994-03-29 08:32:39 +04:00
|
|
|
{
|
|
|
|
register struct isa_attach_args *ia = aux;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* reset */
|
|
|
|
outb(iobase + fdout, 0);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(100);
|
1994-03-29 08:32:39 +04:00
|
|
|
outb(iobase + fdout, FDO_FRST);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/* see if it can handle a command */
|
1994-03-29 08:32:39 +04:00
|
|
|
if (out_fdc(iobase, NE7CMD_SPECIFY) < 0)
|
|
|
|
return 0;
|
|
|
|
out_fdc(iobase, 0xdf);
|
|
|
|
out_fdc(iobase, 2);
|
|
|
|
|
|
|
|
#ifdef NEWCONFIG
|
|
|
|
if (iobase == IOBASEUNK || ia->ia_drq == DRQUNK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ia->ia_irq == IRQUNK) {
|
|
|
|
ia->ia_irq = isa_discoverintr(fdcforceintr, aux);
|
|
|
|
if (ia->ia_irq == IRQNONE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* reset it again */
|
|
|
|
outb(iobase + fdout, 0);
|
|
|
|
delay(100);
|
|
|
|
outb(iobase + fdout, FDO_FRST);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
1993-04-15 11:57:50 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
ia->ia_iosize = FDC_NPORT;
|
|
|
|
ia->ia_msize = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef NEWCONFIG
|
|
|
|
void
|
|
|
|
fdcforceintr(aux)
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = ia->ia_iobase;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
/* the motor is off; this should generate an error with or
|
|
|
|
without a disk drive present */
|
|
|
|
out_fdc(iobase, NE7CMD_SEEK);
|
|
|
|
out_fdc(iobase, 0);
|
|
|
|
out_fdc(iobase, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments passed between fdcattach and fdprobe.
|
|
|
|
*/
|
|
|
|
struct fdc_attach_args {
|
|
|
|
int fa_drive;
|
|
|
|
struct fd_type *fa_deftype;
|
|
|
|
};
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/*
|
|
|
|
* Print the location of a disk drive (called just before attaching the
|
|
|
|
* the drive). If `fdc' is not NULL, the drive was found but was not
|
|
|
|
* in the system config file; print the drive name as well.
|
|
|
|
* Return QUIET (config_find ignores this if the device was configured) to
|
|
|
|
* avoid printing `fdN not configured' messages.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fdprint(aux, fdc)
|
|
|
|
void *aux;
|
|
|
|
char *fdc;
|
|
|
|
{
|
|
|
|
register struct fdc_attach_args *fa = aux;
|
|
|
|
|
|
|
|
if (!fdc)
|
|
|
|
printf(" drive %d", fa->fa_drive);
|
|
|
|
return QUIET;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
|
|
|
fdcattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1994-03-10 23:05:30 +03:00
|
|
|
{
|
1994-11-04 01:55:58 +03:00
|
|
|
struct fdc_softc *fdc = (void *)self;
|
1994-03-29 08:32:39 +04:00
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
struct fdc_attach_args fa;
|
1994-11-04 01:55:58 +03:00
|
|
|
int type;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
fdc->sc_iobase = ia->ia_iobase;
|
|
|
|
fdc->sc_drq = ia->ia_drq;
|
|
|
|
fdc->sc_state = DEVIDLE;
|
1994-04-20 11:23:52 +04:00
|
|
|
TAILQ_INIT(&fdc->sc_drives);
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
#ifdef NEWCONFIG
|
1994-04-07 10:48:19 +04:00
|
|
|
at_setup_dmachan(fdc->sc_drq, FDC_MAXIOSIZE);
|
1994-03-29 08:32:39 +04:00
|
|
|
isa_establish(&fdc->sc_id, &fdc->sc_dev);
|
1994-04-07 10:48:19 +04:00
|
|
|
#endif
|
1995-04-17 16:06:30 +04:00
|
|
|
fdc->sc_ih = isa_intr_establish(ia->ia_irq, ISA_IST_EDGE, ISA_IPL_BIO,
|
|
|
|
fdcintr, fdc);
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The NVRAM info only tells us about the first two disks on the
|
|
|
|
* `primary' floppy controller.
|
|
|
|
*/
|
|
|
|
if (fdc->sc_dev.dv_unit == 0)
|
1995-05-04 23:39:08 +04:00
|
|
|
type = mc146818_read(NULL, NVRAM_DISKETTE); /* XXX softc */
|
1994-03-29 08:32:39 +04:00
|
|
|
else
|
|
|
|
type = -1;
|
1994-03-11 01:30:06 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* physical limit: four drives per controller. */
|
|
|
|
for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
|
1994-10-18 21:24:35 +03:00
|
|
|
if (type >= 0 && fa.fa_drive < 2)
|
1994-03-29 08:32:39 +04:00
|
|
|
fa.fa_deftype = fd_nvtotype(fdc->sc_dev.dv_xname,
|
|
|
|
type, fa.fa_drive);
|
1994-10-18 21:24:35 +03:00
|
|
|
else
|
1994-03-29 08:32:39 +04:00
|
|
|
fa.fa_deftype = NULL; /* unknown */
|
|
|
|
(void)config_found(self, (void *)&fa, fdprint);
|
|
|
|
}
|
1994-03-10 23:05:30 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
1994-11-04 01:55:58 +03:00
|
|
|
fdprobe(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
void *match, *aux;
|
1994-03-10 23:05:30 +03:00
|
|
|
{
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fdc_softc *fdc = (void *)parent;
|
1994-11-05 01:51:59 +03:00
|
|
|
struct cfdata *cf = match;
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fdc_attach_args *fa = aux;
|
1994-11-04 01:55:58 +03:00
|
|
|
int drive = fa->fa_drive;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = fdc->sc_iobase;
|
1994-03-29 08:32:39 +04:00
|
|
|
int n;
|
|
|
|
|
1994-11-04 01:55:58 +03:00
|
|
|
if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != drive)
|
1994-03-29 08:32:39 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* select drive and turn on motor */
|
|
|
|
outb(iobase + fdout, drive | FDO_FRST | FDO_MOEN(drive));
|
|
|
|
/* wait for motor to spin up */
|
|
|
|
delay(250000);
|
|
|
|
out_fdc(iobase, NE7CMD_RECAL);
|
|
|
|
out_fdc(iobase, drive);
|
|
|
|
/* wait for recalibrate */
|
|
|
|
delay(2000000);
|
|
|
|
out_fdc(iobase, NE7CMD_SENSEI);
|
|
|
|
n = fdcresult(fdc);
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("fdprobe: status");
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
printf(" %x", fdc->sc_status[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (n != 2 || (fdc->sc_status[0] & 0xf8) != 0x20)
|
|
|
|
return 0;
|
|
|
|
/* turn off motor */
|
|
|
|
outb(iobase + fdout, FDO_FRST);
|
1994-03-11 00:52:07 +03:00
|
|
|
|
|
|
|
return 1;
|
1994-03-10 23:05:30 +03:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-03-29 08:32:39 +04:00
|
|
|
* Controller is working, and drive responded. Attach it.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
|
|
|
fdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fdc_softc *fdc = (void *)parent;
|
|
|
|
struct fd_softc *fd = (void *)self;
|
|
|
|
struct fdc_attach_args *fa = aux;
|
|
|
|
struct fd_type *type = fa->fa_deftype;
|
|
|
|
int drive = fa->fa_drive;
|
1993-04-06 14:06:28 +04:00
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
/* XXX Allow `flags' to override device type? */
|
1993-04-15 11:57:50 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
if (type)
|
|
|
|
printf(": %s %d cyl, %d head, %d sec\n", type->name,
|
1994-10-18 21:24:35 +03:00
|
|
|
type->tracks, type->heads, type->sectrac);
|
1994-03-29 08:32:39 +04:00
|
|
|
else
|
|
|
|
printf(": density unknown\n");
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
fd->sc_cylin = -1;
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_drive = drive;
|
|
|
|
fd->sc_deftype = type;
|
|
|
|
fdc->sc_fd[drive] = fd;
|
|
|
|
fd->sc_dk.dk_driver = &fddkdriver;
|
1994-11-04 01:55:58 +03:00
|
|
|
#ifdef NEWCONFIG
|
1995-01-13 10:57:01 +03:00
|
|
|
/* XXX Need to do some more fiddling with sc_dk. */
|
1994-03-29 08:32:39 +04:00
|
|
|
dk_establish(&fd->sc_dk, &fd->sc_dev);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate nvram type into internal data structure. Return NULL for
|
|
|
|
* none/unknown/unusable.
|
|
|
|
*/
|
|
|
|
struct fd_type *
|
|
|
|
fd_nvtotype(fdc, nvraminfo, drive)
|
|
|
|
char *fdc;
|
|
|
|
int nvraminfo, drive;
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
type = (drive == 0 ? nvraminfo : nvraminfo << 4) & 0xf0;
|
|
|
|
switch (type) {
|
|
|
|
case NVRAM_DISKETTE_NONE:
|
|
|
|
return NULL;
|
|
|
|
case NVRAM_DISKETTE_12M:
|
|
|
|
return &fd_types[1];
|
1995-05-04 23:39:08 +04:00
|
|
|
case NVRAM_DISKETTE_TYPE5:
|
|
|
|
case NVRAM_DISKETTE_TYPE6:
|
|
|
|
/* XXX We really ought to handle 2.88MB format. */
|
1994-03-29 08:32:39 +04:00
|
|
|
case NVRAM_DISKETTE_144M:
|
|
|
|
return &fd_types[0];
|
|
|
|
case NVRAM_DISKETTE_360K:
|
|
|
|
return &fd_types[3];
|
|
|
|
case NVRAM_DISKETTE_720K:
|
|
|
|
return &fd_types[4];
|
1993-05-10 10:45:16 +04:00
|
|
|
default:
|
1994-03-29 08:32:39 +04:00
|
|
|
printf("%s: drive %d: unknown device type 0x%x\n",
|
|
|
|
fdc, drive, type);
|
|
|
|
return NULL;
|
1993-04-15 11:57:50 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
inline struct fd_type *
|
|
|
|
fd_dev_to_type(fd, dev)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
dev_t dev;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:39 +04:00
|
|
|
int type = FDTYPE(dev);
|
|
|
|
|
1995-01-13 11:29:25 +03:00
|
|
|
if (type > (sizeof(fd_types) / sizeof(fd_types[0])))
|
|
|
|
return NULL;
|
1994-03-29 08:32:39 +04:00
|
|
|
return type ? &fd_types[type - 1] : fd->sc_deftype;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
fdstrategy(bp)
|
|
|
|
register struct buf *bp; /* IO operation to perform */
|
|
|
|
{
|
1995-01-13 10:57:01 +03:00
|
|
|
struct fd_softc *fd;
|
|
|
|
int unit = FDUNIT(bp->b_dev);
|
1995-01-13 13:35:58 +03:00
|
|
|
int sz;
|
1994-03-29 08:32:39 +04:00
|
|
|
int s;
|
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
/* Valid unit, controller, and request? */
|
|
|
|
if (unit >= fdcd.cd_ndevs ||
|
|
|
|
(fd = fdcd.cd_devs[unit]) == 0 ||
|
|
|
|
bp->b_blkno < 0 ||
|
1995-01-13 13:35:58 +03:00
|
|
|
(bp->b_bcount % FDC_BSIZE) != 0) {
|
1995-01-13 10:57:01 +03:00
|
|
|
bp->b_error = EINVAL;
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
/* If it's a null transfer, return immediately. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1995-01-13 13:35:58 +03:00
|
|
|
sz = howmany(bp->b_bcount, FDC_BSIZE);
|
|
|
|
|
|
|
|
if (bp->b_blkno + sz > fd->sc_type->size) {
|
|
|
|
sz = fd->sc_type->size - bp->b_blkno;
|
|
|
|
if (sz == 0) {
|
1995-01-13 10:57:01 +03:00
|
|
|
/* If exactly at end of disk, return EOF. */
|
1993-03-21 12:45:37 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1995-01-13 10:57:01 +03:00
|
|
|
goto done;
|
1995-01-13 13:35:58 +03:00
|
|
|
}
|
|
|
|
if (sz < 0) {
|
1995-01-13 10:57:01 +03:00
|
|
|
/* If past end of disk, return EINVAL. */
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
/* Otherwise, truncate request. */
|
1995-01-13 13:35:58 +03:00
|
|
|
bp->b_bcount = sz << DEV_BSHIFT;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
|
1995-01-13 13:35:58 +03:00
|
|
|
bp->b_cylin = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE) / fd->sc_type->seccyl;
|
1995-01-13 10:57:01 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DEBUG
|
1995-06-26 09:20:40 +04:00
|
|
|
printf("fdstrategy: b_blkno %d b_bcount %d blkno %d cylin %d sz %d\n",
|
|
|
|
bp->b_blkno, bp->b_bcount, fd->sc_blkno, bp->b_cylin, sz);
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
/* Queue transfer on drive, activate drive and controller if idle. */
|
1993-03-21 12:45:37 +03:00
|
|
|
s = splbio();
|
1994-04-20 11:23:52 +04:00
|
|
|
disksort(&fd->sc_q, bp);
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fd_motor_off, fd); /* a good idea */
|
1994-04-20 11:23:52 +04:00
|
|
|
if (!fd->sc_q.b_active)
|
|
|
|
fdstart(fd);
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1995-01-13 10:57:01 +03:00
|
|
|
else {
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
if (fdc->sc_state == DEVIDLE) {
|
|
|
|
printf("fdstrategy: controller inactive\n");
|
|
|
|
fdcstart(fdc);
|
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
}
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
1994-04-20 11:23:52 +04:00
|
|
|
bad:
|
1995-01-13 10:57:01 +03:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
/* Toss transfer; we're done early. */
|
1993-03-21 12:45:37 +03:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
1994-04-20 11:23:52 +04:00
|
|
|
void
|
|
|
|
fdstart(fd)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
int active = fdc->sc_drives.tqh_first != 0;
|
|
|
|
|
|
|
|
/* Link into controller queue. */
|
|
|
|
fd->sc_q.b_active = 1;
|
|
|
|
TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
|
|
|
|
/* If controller not already active, start it. */
|
|
|
|
if (!active)
|
|
|
|
fdcstart(fdc);
|
|
|
|
}
|
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
void
|
|
|
|
fdfinish(fd, bp)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move this drive to the end of the queue to give others a `fair'
|
|
|
|
* chance. We only force a switch if N operations are completed while
|
|
|
|
* another drive is waiting to be serviced, since there is a long motor
|
|
|
|
* startup delay whenever we switch.
|
|
|
|
*/
|
|
|
|
if (fd->sc_drivechain.tqe_next && ++fd->sc_ops >= 8) {
|
|
|
|
fd->sc_ops = 0;
|
|
|
|
TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
if (bp->b_actf) {
|
|
|
|
TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
} else
|
|
|
|
fd->sc_q.b_active = 0;
|
|
|
|
}
|
1995-01-13 13:35:58 +03:00
|
|
|
bp->b_resid = fd->sc_bcount;
|
1995-01-13 10:57:01 +03:00
|
|
|
fd->sc_skip = 0;
|
|
|
|
fd->sc_q.b_actf = bp->b_actf;
|
|
|
|
biodone(bp);
|
|
|
|
/* turn off motor 5s from now */
|
|
|
|
timeout(fd_motor_off, fd, 5 * hz);
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
|
|
|
fd_set_motor(fdc, reset)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
int reset;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fd_softc *fd;
|
|
|
|
u_char status;
|
|
|
|
int n;
|
|
|
|
|
1994-04-20 11:23:52 +04:00
|
|
|
if (fd = fdc->sc_drives.tqh_first)
|
1994-03-29 08:32:39 +04:00
|
|
|
status = fd->sc_drive;
|
1993-06-18 10:19:16 +04:00
|
|
|
else
|
1994-03-29 08:32:39 +04:00
|
|
|
status = 0;
|
|
|
|
if (!reset)
|
|
|
|
status |= FDO_FRST | FDO_FDMAEN;
|
|
|
|
for (n = 0; n < 4; n++)
|
|
|
|
if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
|
|
|
|
status |= FDO_MOEN(n);
|
|
|
|
outb(fdc->sc_iobase + fdout, status);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
1994-05-05 09:35:42 +04:00
|
|
|
fd_motor_off(arg)
|
|
|
|
void *arg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-01-13 10:57:01 +03:00
|
|
|
struct fd_softc *fd = arg;
|
1994-05-05 09:35:42 +04:00
|
|
|
int s;
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-05-05 09:35:42 +04:00
|
|
|
s = splbio();
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
|
|
|
fd_set_motor((struct fdc_softc *)fd->sc_dev.dv_parent, 0);
|
|
|
|
splx(s);
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
1994-05-05 09:35:42 +04:00
|
|
|
fd_motor_on(arg)
|
|
|
|
void *arg;
|
1993-06-18 10:19:16 +04:00
|
|
|
{
|
1995-01-13 10:57:01 +03:00
|
|
|
struct fd_softc *fd = arg;
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
1994-05-05 09:35:42 +04:00
|
|
|
int s;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-05 09:35:42 +04:00
|
|
|
s = splbio();
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_flags &= ~FD_MOTOR_WAIT;
|
1994-04-20 11:23:52 +04:00
|
|
|
if ((fdc->sc_drives.tqh_first == fd) && (fdc->sc_state == MOTORWAIT))
|
1994-03-29 08:32:39 +04:00
|
|
|
(void) fdcintr(fdc);
|
|
|
|
splx(s);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcresult(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = fdc->sc_iobase;
|
1994-03-29 08:32:39 +04:00
|
|
|
u_char i;
|
|
|
|
int j = 100000,
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
for (; j; j--) {
|
|
|
|
i = inb(iobase + fdsts) & (NE7_DIO | NE7_RQM | NE7_CB);
|
|
|
|
if (i == NE7_RQM)
|
|
|
|
return n;
|
|
|
|
if (i == (NE7_DIO | NE7_RQM | NE7_CB)) {
|
|
|
|
if (n >= sizeof(fdc->sc_status)) {
|
|
|
|
log(LOG_ERR, "fdcresult: overrun\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fdc->sc_status[n++] = inb(iobase + fddata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log(LOG_ERR, "fdcresult: timeout\n");
|
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
|
|
|
out_fdc(iobase, x)
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase;
|
1994-03-29 08:32:39 +04:00
|
|
|
u_char x;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int i = 100000;
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
while ((inb(iobase + fdsts) & NE7_DIO) && i-- > 0);
|
|
|
|
if (i <= 0)
|
|
|
|
return -1;
|
|
|
|
while ((inb(iobase + fdsts) & NE7_RQM) == 0 && i-- > 0);
|
|
|
|
if (i <= 0)
|
|
|
|
return -1;
|
|
|
|
outb(iobase + fddata, x);
|
|
|
|
return 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
Fdopen(dev, flags)
|
1994-03-29 08:32:39 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flags;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-01-13 11:37:25 +03:00
|
|
|
int unit;
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fd_softc *fd;
|
1995-01-13 11:37:25 +03:00
|
|
|
struct fd_type *type;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
unit = FDUNIT(dev);
|
|
|
|
if (unit >= fdcd.cd_ndevs)
|
1994-03-29 08:32:39 +04:00
|
|
|
return ENXIO;
|
1995-01-13 10:57:01 +03:00
|
|
|
fd = fdcd.cd_devs[unit];
|
|
|
|
if (fd == 0)
|
1994-03-29 08:32:39 +04:00
|
|
|
return ENXIO;
|
1995-01-13 11:37:25 +03:00
|
|
|
type = fd_dev_to_type(fd, dev);
|
1995-01-13 11:29:25 +03:00
|
|
|
if (type == NULL)
|
|
|
|
return ENXIO;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-01-13 11:29:25 +03:00
|
|
|
if ((fd->sc_flags & FD_OPEN) != 0 &&
|
|
|
|
fd->sc_type != type)
|
|
|
|
return EBUSY;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1995-01-13 11:29:25 +03:00
|
|
|
fd->sc_type = type;
|
1995-01-13 10:57:01 +03:00
|
|
|
fd->sc_cylin = -1;
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_flags |= FD_OPEN;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
1995-04-10 08:18:14 +04:00
|
|
|
fdclose(dev, flags)
|
1993-06-18 10:19:16 +04:00
|
|
|
dev_t dev;
|
1994-03-29 08:32:39 +04:00
|
|
|
int flags;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-01-13 10:57:01 +03:00
|
|
|
struct fd_softc *fd = fdcd.cd_devs[FDUNIT(dev)];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_flags &= ~FD_OPEN;
|
|
|
|
return 0;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
|
|
|
fdcstart(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* only got here if controller's drive queue was inactive; should
|
|
|
|
be in idle state */
|
|
|
|
if (fdc->sc_state != DEVIDLE) {
|
|
|
|
printf("fdcstart: not idle\n");
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
|
|
|
(void) fdcintr(fdc);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
|
|
|
fdcstatus(dv, n, s)
|
|
|
|
struct device *dv;
|
|
|
|
int n;
|
|
|
|
char *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fdc_softc *fdc = (void *)dv->dv_parent;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = fdc->sc_iobase;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
if (n == 0) {
|
|
|
|
out_fdc(fdc->sc_iobase, NE7CMD_SENSEI);
|
|
|
|
(void) fdcresult(fdc);
|
|
|
|
n = 2;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1994-10-18 21:24:35 +03:00
|
|
|
printf("%s: %s", dv->dv_xname, s);
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
|
|
|
printf("\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf(" (st0 %b cyl %d)\n",
|
|
|
|
fdc->sc_status[0], NE7_ST0BITS,
|
|
|
|
fdc->sc_status[1]);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
printf(" (st0 %b st1 %b st2 %b cyl %d head %d sec %d)\n",
|
|
|
|
fdc->sc_status[0], NE7_ST0BITS,
|
|
|
|
fdc->sc_status[1], NE7_ST1BITS,
|
|
|
|
fdc->sc_status[2], NE7_ST2BITS,
|
|
|
|
fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
|
|
|
|
break;
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1994-10-18 21:24:35 +03:00
|
|
|
default:
|
1994-03-29 08:32:39 +04:00
|
|
|
printf("\nfdcstatus: weird size");
|
1994-10-18 21:24:35 +03:00
|
|
|
break;
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
1994-10-18 21:24:35 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-05-05 09:35:42 +04:00
|
|
|
fdctimeout(arg)
|
|
|
|
void *arg;
|
1994-03-29 08:32:39 +04:00
|
|
|
{
|
1995-01-13 10:57:01 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
1995-01-13 11:37:25 +03:00
|
|
|
struct fd_softc *fd = fdc->sc_drives.tqh_first;
|
1994-05-05 09:35:42 +04:00
|
|
|
int s;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1994-05-05 09:35:42 +04:00
|
|
|
s = splbio();
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcstatus(&fd->sc_dev, 0, "timeout");
|
|
|
|
|
1994-04-20 11:23:52 +04:00
|
|
|
if (fd->sc_q.b_actf)
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state++;
|
1994-04-20 11:23:52 +04:00
|
|
|
else
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
|
|
|
|
(void) fdcintr(fdc);
|
|
|
|
splx(s);
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
void
|
1994-05-05 09:35:42 +04:00
|
|
|
fdcpseudointr(arg)
|
|
|
|
void *arg;
|
1993-06-18 10:19:16 +04:00
|
|
|
{
|
1994-05-05 09:35:42 +04:00
|
|
|
int s;
|
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
/* Just ensure it has the right spl. */
|
1994-05-05 09:35:42 +04:00
|
|
|
s = splbio();
|
1995-04-17 16:06:30 +04:00
|
|
|
(void) fdcintr(arg);
|
1993-06-18 10:19:16 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
1995-04-17 16:06:30 +04:00
|
|
|
fdcintr(arg)
|
|
|
|
void *arg;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-04-17 16:06:30 +04:00
|
|
|
struct fdc_softc *fdc = arg;
|
1994-03-29 08:32:39 +04:00
|
|
|
#define st0 fdc->sc_status[0]
|
|
|
|
#define cyl fdc->sc_status[1]
|
|
|
|
struct fd_softc *fd;
|
1994-04-20 11:23:52 +04:00
|
|
|
struct buf *bp;
|
1994-11-19 00:57:40 +03:00
|
|
|
int iobase = fdc->sc_iobase;
|
1995-01-13 13:35:58 +03:00
|
|
|
int read, head, trac, sec, i, s, nblks;
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fd_type *type;
|
|
|
|
|
1995-01-13 10:57:01 +03:00
|
|
|
loop:
|
1995-01-13 11:37:25 +03:00
|
|
|
/* Is there a drive for the controller to do a transfer with? */
|
1994-04-20 11:23:52 +04:00
|
|
|
fd = fdc->sc_drives.tqh_first;
|
1995-01-13 10:57:01 +03:00
|
|
|
if (fd == NULL) {
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = DEVIDLE;
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
/* Is there a transfer to this drive? If not, deactivate drive. */
|
1994-04-20 11:23:52 +04:00
|
|
|
bp = fd->sc_q.b_actf;
|
1995-01-13 10:57:01 +03:00
|
|
|
if (bp == NULL) {
|
1994-04-20 11:55:38 +04:00
|
|
|
fd->sc_ops = 0;
|
1994-04-20 11:23:52 +04:00
|
|
|
TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
fd->sc_q.b_active = 0;
|
1995-01-13 10:57:01 +03:00
|
|
|
goto loop;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
switch (fdc->sc_state) {
|
1993-06-18 10:19:16 +04:00
|
|
|
case DEVIDLE:
|
1994-10-20 07:46:17 +03:00
|
|
|
fdc->sc_errors = 0;
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_skip = 0;
|
1995-01-13 13:35:58 +03:00
|
|
|
fd->sc_bcount = bp->b_bcount;
|
|
|
|
fd->sc_blkno = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE);
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fd_motor_off, fd);
|
1995-01-13 10:57:01 +03:00
|
|
|
if ((fd->sc_flags & FD_MOTOR_WAIT) != 0) {
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = MOTORWAIT;
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
if ((fd->sc_flags & FD_MOTOR) == 0) {
|
|
|
|
/* Turn on the motor, being careful about pairing. */
|
1994-03-29 08:32:39 +04:00
|
|
|
struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
|
|
|
|
if (ofd && ofd->sc_flags & FD_MOTOR) {
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fd_motor_off, ofd);
|
1994-03-29 08:32:39 +04:00
|
|
|
ofd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
fd->sc_flags |= FD_MOTOR | FD_MOTOR_WAIT;
|
|
|
|
fd_set_motor(fdc, 0);
|
|
|
|
fdc->sc_state = MOTORWAIT;
|
1995-01-13 10:57:01 +03:00
|
|
|
/* Allow .25s for motor to stabilize. */
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fd_motor_on, fd, hz / 4);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
/* Make sure the right drive is selected. */
|
1994-03-29 08:32:39 +04:00
|
|
|
fd_set_motor(fdc, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
/* fall through */
|
|
|
|
case DOSEEK:
|
|
|
|
doseek:
|
1995-01-13 10:57:01 +03:00
|
|
|
if (fd->sc_cylin == bp->b_cylin)
|
1994-03-29 08:32:39 +04:00
|
|
|
goto doio;
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, NE7CMD_SPECIFY);/* specify command */
|
1995-01-13 17:05:17 +03:00
|
|
|
out_fdc(iobase, fd->sc_type->steprate);
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, 6); /* XXX head load time == 6ms */
|
|
|
|
|
|
|
|
out_fdc(iobase, NE7CMD_SEEK); /* seek function */
|
|
|
|
out_fdc(iobase, fd->sc_drive); /* drive number */
|
1995-01-13 11:29:25 +03:00
|
|
|
out_fdc(iobase, bp->b_cylin * fd->sc_type->step);
|
1995-01-13 10:57:01 +03:00
|
|
|
|
|
|
|
fd->sc_cylin = -1;
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = SEEKWAIT;
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdctimeout, fdc, 4 * hz);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case DOIO:
|
|
|
|
doio:
|
1995-01-13 11:29:25 +03:00
|
|
|
type = fd->sc_type;
|
1995-01-13 10:57:01 +03:00
|
|
|
sec = fd->sc_blkno % type->seccyl;
|
|
|
|
nblks = type->seccyl - sec;
|
1995-01-13 13:35:58 +03:00
|
|
|
nblks = min(nblks, fd->sc_bcount / FDC_BSIZE);
|
1994-03-29 08:32:39 +04:00
|
|
|
nblks = min(nblks, FDC_MAXIOSIZE / FDC_BSIZE);
|
|
|
|
fd->sc_nblks = nblks;
|
1995-01-13 14:14:27 +03:00
|
|
|
fd->sc_nbytes = nblks * FDC_BSIZE;
|
1995-01-13 10:57:01 +03:00
|
|
|
head = sec / type->sectrac;
|
|
|
|
sec -= head * type->sectrac;
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
{int block;
|
1995-01-13 10:57:01 +03:00
|
|
|
block = (fd->sc_cylin * type->heads + head) * type->sectrac + sec;
|
1994-03-29 08:32:39 +04:00
|
|
|
if (block != fd->sc_blkno) {
|
1994-04-08 22:51:19 +04:00
|
|
|
printf("fdcintr: block %d != blkno %d\n", block, fd->sc_blkno);
|
1994-05-27 17:00:27 +04:00
|
|
|
#ifdef DDB
|
1994-03-29 08:32:39 +04:00
|
|
|
Debugger();
|
1994-05-27 17:00:27 +04:00
|
|
|
#endif
|
1994-03-29 08:32:39 +04:00
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
read = bp->b_flags & B_READ;
|
|
|
|
#ifdef NEWCONFIG
|
1995-01-13 14:14:27 +03:00
|
|
|
at_dma(read, bp->b_data + fd->sc_skip, fd->sc_nbytes,
|
1994-10-18 21:24:35 +03:00
|
|
|
fdc->sc_drq);
|
1994-03-29 08:32:39 +04:00
|
|
|
#else
|
1995-01-13 14:14:27 +03:00
|
|
|
isa_dmastart(read, bp->b_data + fd->sc_skip, fd->sc_nbytes,
|
1994-10-18 21:24:35 +03:00
|
|
|
fdc->sc_drq);
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
|
|
|
outb(iobase + fdctl, type->rate);
|
|
|
|
#ifdef DEBUG
|
1994-04-08 22:51:19 +04:00
|
|
|
printf("fdcintr: %s drive %d track %d head %d sec %d nblks %d\n",
|
1995-01-13 10:57:01 +03:00
|
|
|
read ? "read" : "write", fd->sc_drive, fd->sc_cylin, head,
|
1994-10-18 21:24:35 +03:00
|
|
|
sec, nblks);
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
1993-06-18 10:19:16 +04:00
|
|
|
if (read)
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, NE7CMD_READ); /* READ */
|
1993-06-18 10:19:16 +04:00
|
|
|
else
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, NE7CMD_WRITE); /* WRITE */
|
|
|
|
out_fdc(iobase, (head << 2) | fd->sc_drive);
|
1995-01-13 10:57:01 +03:00
|
|
|
out_fdc(iobase, fd->sc_cylin); /* track */
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, head);
|
|
|
|
out_fdc(iobase, sec + 1); /* sector +1 */
|
|
|
|
out_fdc(iobase, type->secsize); /* sector size */
|
1995-01-13 10:57:01 +03:00
|
|
|
out_fdc(iobase, type->sectrac); /* sectors/track */
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, type->gap1); /* gap1 size */
|
|
|
|
out_fdc(iobase, type->datalen); /* data length */
|
|
|
|
fdc->sc_state = IOCOMPLETE;
|
|
|
|
/* allow 2 seconds for operation */
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdctimeout, fdc, 2 * hz);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1; /* will return later */
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case SEEKWAIT:
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fdctimeout, fdc);
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = SEEKCOMPLETE;
|
|
|
|
/* allow 1/50 second for heads to settle */
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdcpseudointr, fdc, hz / 50);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case SEEKCOMPLETE:
|
1995-01-13 11:29:25 +03:00
|
|
|
/* Make sure seek really happened. */
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, NE7CMD_SENSEI);
|
1995-01-13 10:57:01 +03:00
|
|
|
if (fdcresult(fdc) != 2 || (st0 & 0xf8) != 0x20 ||
|
1995-01-13 11:29:25 +03:00
|
|
|
cyl != bp->b_cylin * fd->sc_type->step) {
|
1994-10-20 03:52:23 +03:00
|
|
|
#ifdef FD_DEBUG
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcstatus(&fd->sc_dev, 2, "seek failed");
|
1994-10-20 03:52:23 +03:00
|
|
|
#endif
|
1994-04-08 22:51:19 +04:00
|
|
|
fdcretry(fdc);
|
1995-01-13 10:57:01 +03:00
|
|
|
goto loop;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
fd->sc_cylin = bp->b_cylin;
|
1994-03-29 08:32:39 +04:00
|
|
|
goto doio;
|
|
|
|
|
|
|
|
case IOTIMEDOUT:
|
|
|
|
#ifdef NEWCONFIG
|
|
|
|
at_dma_abort(fdc->sc_drq);
|
|
|
|
#else
|
|
|
|
isa_dmaabort(fdc->sc_drq);
|
|
|
|
#endif
|
|
|
|
case SEEKTIMEDOUT:
|
|
|
|
case RECALTIMEDOUT:
|
|
|
|
case RESETTIMEDOUT:
|
1994-04-08 22:51:19 +04:00
|
|
|
fdcretry(fdc);
|
1995-01-13 10:57:01 +03:00
|
|
|
goto loop;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1993-06-18 10:19:16 +04:00
|
|
|
case IOCOMPLETE: /* IO DONE, post-analyze */
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fdctimeout, fdc);
|
1994-03-29 08:32:39 +04:00
|
|
|
if (fdcresult(fdc) != 7 || (st0 & 0xf8) != 0) {
|
|
|
|
#ifdef NEWCONFIG
|
|
|
|
at_dma_abort(fdc->sc_drq);
|
|
|
|
#else
|
|
|
|
isa_dmaabort(fdc->sc_drq);
|
|
|
|
#endif
|
1994-10-20 03:52:23 +03:00
|
|
|
#ifdef FD_DEBUG
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcstatus(&fd->sc_dev, 7, bp->b_flags & B_READ ?
|
1994-10-18 21:24:35 +03:00
|
|
|
"read failed" : "write failed");
|
1994-10-20 06:38:13 +03:00
|
|
|
printf("blkno %d nblks %d\n",
|
|
|
|
fd->sc_blkno, fd->sc_nblks);
|
1994-10-20 03:52:23 +03:00
|
|
|
#endif
|
1994-04-08 22:51:19 +04:00
|
|
|
fdcretry(fdc);
|
1995-01-13 10:57:01 +03:00
|
|
|
goto loop;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef NEWCONFIG
|
|
|
|
at_dma_terminate(fdc->sc_drq);
|
|
|
|
#else
|
1995-01-13 14:14:27 +03:00
|
|
|
read = bp->b_flags & B_READ;
|
|
|
|
isa_dmadone(read, bp->b_data + fd->sc_skip, fd->sc_nbytes,
|
|
|
|
fdc->sc_drq);
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
1994-10-20 07:46:17 +03:00
|
|
|
if (fdc->sc_errors) {
|
|
|
|
diskerr(bp, "fd", "soft error", LOG_PRINTF,
|
|
|
|
fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
|
|
|
|
printf("\n");
|
|
|
|
fdc->sc_errors = 0;
|
|
|
|
}
|
1995-01-13 14:14:27 +03:00
|
|
|
fd->sc_blkno += fd->sc_nblks;
|
|
|
|
fd->sc_skip += fd->sc_nbytes;
|
|
|
|
fd->sc_bcount -= fd->sc_nbytes;
|
1995-01-13 13:35:58 +03:00
|
|
|
if (fd->sc_bcount > 0) {
|
|
|
|
bp->b_cylin = fd->sc_blkno / fd->sc_type->seccyl;
|
1994-03-29 08:32:39 +04:00
|
|
|
goto doseek;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-01-13 13:35:58 +03:00
|
|
|
fdfinish(fd, bp);
|
|
|
|
goto loop;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case DORESET:
|
|
|
|
/* try a reset, keep motor on */
|
|
|
|
fd_set_motor(fdc, 1);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(100);
|
1994-03-29 08:32:39 +04:00
|
|
|
fd_set_motor(fdc, 0);
|
|
|
|
fdc->sc_state = RESETCOMPLETE;
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdctimeout, fdc, hz / 2);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1; /* will return later */
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case RESETCOMPLETE:
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fdctimeout, fdc);
|
1994-03-29 08:32:39 +04:00
|
|
|
/* clear the controller output buffer */
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
out_fdc(iobase, NE7CMD_SENSEI);
|
|
|
|
(void) fdcresult(fdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
case DORECAL:
|
|
|
|
out_fdc(iobase, NE7CMD_RECAL); /* recalibrate function */
|
|
|
|
out_fdc(iobase, fd->sc_drive);
|
|
|
|
fdc->sc_state = RECALWAIT;
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdctimeout, fdc, 5 * hz);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1; /* will return later */
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1993-06-18 10:19:16 +04:00
|
|
|
case RECALWAIT:
|
1994-05-05 11:48:20 +04:00
|
|
|
untimeout(fdctimeout, fdc);
|
1994-03-29 08:32:39 +04:00
|
|
|
fdc->sc_state = RECALCOMPLETE;
|
|
|
|
/* allow 1/30 second for heads to settle */
|
1994-05-05 11:48:20 +04:00
|
|
|
timeout(fdcpseudointr, fdc, hz / 30);
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1; /* will return later */
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1993-06-18 10:19:16 +04:00
|
|
|
case RECALCOMPLETE:
|
1994-03-29 08:32:39 +04:00
|
|
|
out_fdc(iobase, NE7CMD_SENSEI);
|
|
|
|
if (fdcresult(fdc) != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
|
1994-10-20 03:52:23 +03:00
|
|
|
#ifdef FD_DEBUG
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcstatus(&fd->sc_dev, 2, "recalibrate failed");
|
1994-10-20 03:52:23 +03:00
|
|
|
#endif
|
1994-04-08 22:51:19 +04:00
|
|
|
fdcretry(fdc);
|
1995-01-13 10:57:01 +03:00
|
|
|
goto loop;
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
1995-01-13 10:57:01 +03:00
|
|
|
fd->sc_cylin = 0;
|
1994-03-29 08:32:39 +04:00
|
|
|
goto doseek;
|
|
|
|
|
|
|
|
case MOTORWAIT:
|
|
|
|
if (fd->sc_flags & FD_MOTOR_WAIT)
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1; /* time's not up yet */
|
1994-03-29 08:32:39 +04:00
|
|
|
goto doseek;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcstatus(&fd->sc_dev, 0, "stray interrupt");
|
1994-04-08 22:51:19 +04:00
|
|
|
return 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1994-04-08 22:51:19 +04:00
|
|
|
panic("fdcintr: impossible");
|
1994-03-29 08:32:39 +04:00
|
|
|
#endif
|
|
|
|
#undef st0
|
|
|
|
#undef cyl
|
1993-06-18 10:19:16 +04:00
|
|
|
}
|
|
|
|
|
1994-04-08 22:51:19 +04:00
|
|
|
void
|
1994-03-29 08:32:39 +04:00
|
|
|
fdcretry(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
1993-06-18 10:19:16 +04:00
|
|
|
{
|
1994-04-20 11:23:52 +04:00
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-04-20 11:23:52 +04:00
|
|
|
fd = fdc->sc_drives.tqh_first;
|
1994-03-29 08:32:39 +04:00
|
|
|
bp = fd->sc_q.b_actf;
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-10-20 07:46:17 +03:00
|
|
|
switch (fdc->sc_errors) {
|
1994-03-29 08:32:39 +04:00
|
|
|
case 0:
|
|
|
|
/* try again */
|
|
|
|
fdc->sc_state = SEEKCOMPLETE;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case 1: case 2: case 3:
|
|
|
|
/* didn't work; try recalibrating */
|
|
|
|
fdc->sc_state = DORECAL;
|
1993-06-18 10:19:16 +04:00
|
|
|
break;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
|
|
|
case 4:
|
|
|
|
/* still no go; reset the bastard */
|
|
|
|
fdc->sc_state = DORESET;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1994-03-29 08:32:39 +04:00
|
|
|
diskerr(bp, "fd", "hard error", LOG_PRINTF,
|
1994-10-20 07:46:17 +03:00
|
|
|
fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
|
1994-10-18 21:24:35 +03:00
|
|
|
printf(" (st0 %b st1 %b st2 %b cyl %d head %d sec %d)\n",
|
|
|
|
fdc->sc_status[0], NE7_ST0BITS,
|
|
|
|
fdc->sc_status[1], NE7_ST1BITS,
|
|
|
|
fdc->sc_status[2], NE7_ST2BITS,
|
|
|
|
fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
|
1994-03-29 08:32:39 +04:00
|
|
|
|
1993-06-18 10:19:16 +04:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
1994-04-20 11:23:52 +04:00
|
|
|
fdfinish(fd, bp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-10-20 07:46:17 +03:00
|
|
|
fdc->sc_errors++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-11 13:31:42 +04:00
|
|
|
int
|
|
|
|
fdsize(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Swapping to floppies would not make sense. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-05-11 13:49:17 +04:00
|
|
|
int
|
1995-06-26 09:20:40 +04:00
|
|
|
fddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1994-05-11 13:49:17 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
1995-06-26 09:20:40 +04:00
|
|
|
return ENXIO;
|
1994-05-11 13:49:17 +04:00
|
|
|
}
|
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
int
|
|
|
|
fdioctl(dev, cmd, addr, flag)
|
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-03-29 08:32:39 +04:00
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd = fdcd.cd_devs[FDUNIT(dev)];
|
|
|
|
struct disklabel buffer;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
|
|
|
bzero(&buffer, sizeof(buffer));
|
|
|
|
|
1995-01-13 11:37:25 +03:00
|
|
|
buffer.d_secpercyl = fd->sc_type->seccyl;
|
1994-03-29 08:32:39 +04:00
|
|
|
buffer.d_type = DTYPE_FLOPPY;
|
|
|
|
buffer.d_secsize = FDC_BSIZE;
|
|
|
|
|
|
|
|
if (readdisklabel(dev, fdstrategy, &buffer, NULL) != NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
*(struct disklabel *)addr = buffer;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
/* XXX do something */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
|
|
|
error = setdisklabel(&buffer, (struct disklabel *)addr, 0, NULL);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = writedisklabel(dev, fdstrategy, &buffer, NULL);
|
|
|
|
return error;
|
1993-06-18 10:19:16 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
default:
|
1994-07-31 04:47:52 +04:00
|
|
|
return ENOTTY;
|
1994-03-29 08:32:39 +04:00
|
|
|
}
|
1994-07-31 04:47:52 +04:00
|
|
|
|
1994-03-29 08:32:39 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("fdioctl: impossible");
|
|
|
|
#endif
|
|
|
|
}
|