1999-03-24 08:50:49 +03:00
|
|
|
/* $NetBSD: fd.c,v 1.67 1999/03/24 05:51:10 mrg Exp $ */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
/*-
|
1998-08-15 07:02:31 +04:00
|
|
|
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum.
|
1995-02-17 23:28:32 +03:00
|
|
|
* Copyright (c) 1995 Paul Kranenburg.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @(#)fd.c 7.4 (Berkeley) 5/25/91
|
|
|
|
*/
|
|
|
|
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
1999-02-07 12:34:58 +03:00
|
|
|
#include "opt_md.h"
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/disk.h>
|
1996-12-09 02:40:32 +03:00
|
|
|
#include <sys/fdio.h>
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <sys/buf.h>
|
1996-12-09 02:40:32 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <sys/uio.h>
|
1996-01-15 03:14:42 +03:00
|
|
|
#include <sys/stat.h>
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/queue.h>
|
1996-04-01 21:33:10 +04:00
|
|
|
#include <sys/conf.h>
|
1996-03-14 22:44:30 +03:00
|
|
|
|
|
|
|
#include <dev/cons.h>
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1998-02-05 10:57:48 +03:00
|
|
|
#include <vm/vm.h>
|
1999-03-24 08:50:49 +03:00
|
|
|
|
1998-02-05 10:57:48 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/autoconf.h>
|
1996-04-01 21:33:10 +04:00
|
|
|
#include <machine/conf.h>
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
#include <sparc/sparc/auxreg.h>
|
1995-02-23 00:37:15 +03:00
|
|
|
#include <sparc/dev/fdreg.h>
|
|
|
|
#include <sparc/dev/fdvar.h>
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
#define FDUNIT(dev) (minor(dev) / 8)
|
|
|
|
#define FDTYPE(dev) (minor(dev) % 8)
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
/* XXX misuse a flag to identify format operation */
|
|
|
|
#define B_FORMAT B_XXX
|
1995-02-17 23:28:32 +03:00
|
|
|
#define b_cylin b_resid
|
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
#define FD_DEBUG
|
|
|
|
#ifdef FD_DEBUG
|
|
|
|
int fdc_debug = 0;
|
|
|
|
#endif
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
enum fdc_state {
|
|
|
|
DEVIDLE = 0,
|
|
|
|
MOTORWAIT,
|
|
|
|
DOSEEK,
|
|
|
|
SEEKWAIT,
|
|
|
|
SEEKTIMEDOUT,
|
|
|
|
SEEKCOMPLETE,
|
|
|
|
DOIO,
|
|
|
|
IOCOMPLETE,
|
1995-02-23 00:37:15 +03:00
|
|
|
IOTIMEDOUT,
|
1995-02-17 23:28:32 +03:00
|
|
|
DORESET,
|
|
|
|
RESETCOMPLETE,
|
|
|
|
RESETTIMEDOUT,
|
|
|
|
DORECAL,
|
|
|
|
RECALWAIT,
|
|
|
|
RECALTIMEDOUT,
|
|
|
|
RECALCOMPLETE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* software state, per controller */
|
|
|
|
struct fdc_softc {
|
1995-11-12 00:12:50 +03:00
|
|
|
struct device sc_dev; /* boilerplate */
|
1998-03-21 23:11:30 +03:00
|
|
|
bus_space_tag_t sc_bustag;
|
1995-02-17 23:28:32 +03:00
|
|
|
caddr_t sc_reg;
|
|
|
|
struct fd_softc *sc_fd[4]; /* pointers to children */
|
|
|
|
TAILQ_HEAD(drivehead, fd_softc) sc_drives;
|
|
|
|
enum fdc_state sc_state;
|
1995-02-23 00:37:15 +03:00
|
|
|
int sc_flags;
|
|
|
|
#define FDC_82077 0x01
|
|
|
|
#define FDC_NEEDHEADSETTLE 0x02
|
|
|
|
#define FDC_EIS 0x04
|
|
|
|
int sc_errors; /* number of retries so far */
|
1995-04-25 18:44:44 +04:00
|
|
|
int sc_overruns; /* number of DMA overruns */
|
1995-02-23 00:37:15 +03:00
|
|
|
int sc_cfg; /* current configuration */
|
|
|
|
struct fdcio sc_io;
|
|
|
|
#define sc_reg_msr sc_io.fdcio_reg_msr
|
|
|
|
#define sc_reg_fifo sc_io.fdcio_reg_fifo
|
|
|
|
#define sc_reg_dor sc_io.fdcio_reg_dor
|
|
|
|
#define sc_reg_drs sc_io.fdcio_reg_msr
|
|
|
|
#define sc_istate sc_io.fdcio_istate
|
|
|
|
#define sc_data sc_io.fdcio_data
|
|
|
|
#define sc_tc sc_io.fdcio_tc
|
|
|
|
#define sc_nstat sc_io.fdcio_nstat
|
|
|
|
#define sc_status sc_io.fdcio_status
|
1995-04-07 23:46:13 +04:00
|
|
|
#define sc_intrcnt sc_io.fdcio_intrcnt
|
1995-02-17 23:28:32 +03:00
|
|
|
};
|
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
#ifndef FDC_C_HANDLER
|
|
|
|
extern struct fdcio *fdciop;
|
|
|
|
#endif
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* controller driver configuration */
|
1998-03-21 23:11:30 +03:00
|
|
|
int fdcmatch_mainbus __P((struct device *, struct cfdata *, void *));
|
|
|
|
int fdcmatch_obio __P((struct device *, struct cfdata *, void *));
|
|
|
|
void fdcattach_mainbus __P((struct device *, struct device *, void *));
|
|
|
|
void fdcattach_obio __P((struct device *, struct device *, void *));
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
void fdcattach __P((struct fdc_softc *, int, struct bootpath *));
|
|
|
|
|
|
|
|
struct cfattach fdc_mainbus_ca = {
|
|
|
|
sizeof(struct fdc_softc), fdcmatch_mainbus, fdcattach_mainbus
|
|
|
|
};
|
|
|
|
struct cfattach fdc_obio_ca = {
|
|
|
|
sizeof(struct fdc_softc), fdcmatch_obio, fdcattach_obio
|
1996-03-17 05:00:30 +03:00
|
|
|
};
|
1996-03-14 22:44:30 +03:00
|
|
|
|
|
|
|
__inline struct fd_type *fd_dev_to_type __P((struct fd_softc *, dev_t));
|
|
|
|
|
1995-02-17 23:28:32 +03: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 */
|
|
|
|
int heads; /* number of heads */
|
|
|
|
int seccyl; /* sectors per cylinder */
|
|
|
|
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 */
|
1997-04-08 01:00:34 +04:00
|
|
|
int cylinders; /* total num of cylinders */
|
1995-02-17 23:28:32 +03:00
|
|
|
int size; /* size of disk in sectors */
|
|
|
|
int step; /* steps per cylinder */
|
|
|
|
int rate; /* transfer speed code */
|
1996-12-09 02:40:32 +03:00
|
|
|
int fillbyte; /* format fill byte */
|
|
|
|
int interleave; /* interleave factor (formatting) */
|
1995-02-17 23:28:32 +03:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The order of entries in the following table is important -- BEWARE! */
|
|
|
|
struct fd_type fd_types[] = {
|
1996-12-09 02:40:32 +03:00
|
|
|
{ 18,2,36,2,0xff,0xcf,0x1b,0x6c,80,2880,1,FDC_500KBPS,0xf6,1, "1.44MB" }, /* 1.44MB diskette */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,80,1440,1,FDC_250KBPS,0xf6,1, "720KB" }, /* 3.5" 720kB diskette */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,2,FDC_250KBPS,0xf6,1, "360KB/x" }, /* 360kB in 720kB drive */
|
1997-10-20 02:29:21 +04:00
|
|
|
{ 8,2,16,3,0xff,0xdf,0x35,0x74,77,1232,1,FDC_500KBPS,0xf6,1, "1.2MB/NEC" } /* 1.2 MB japanese format */
|
1995-02-17 23:28:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* software state, per disk (with up to 4 disks per ctlr) */
|
|
|
|
struct fd_softc {
|
1996-01-08 01:01:38 +03:00
|
|
|
struct device sc_dv; /* generic device info */
|
|
|
|
struct disk sc_dk; /* generic disk info */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
struct fd_type *sc_deftype; /* default type descriptor */
|
|
|
|
struct fd_type *sc_type; /* current type descriptor */
|
|
|
|
|
|
|
|
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 */
|
|
|
|
int sc_nbytes; /* number of bytes currently tranferring */
|
|
|
|
|
|
|
|
int sc_drive; /* physical unit number */
|
|
|
|
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 */
|
|
|
|
int sc_cylin; /* where we think the head is */
|
1996-12-09 02:40:32 +03:00
|
|
|
int sc_opts; /* user-set options */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-01-16 22:35:06 +03:00
|
|
|
void *sc_sdhook; /* shutdownhook cookie */
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
TAILQ_ENTRY(fd_softc) sc_drivechain;
|
|
|
|
int sc_ops; /* I/O ops since last switch */
|
|
|
|
struct buf sc_q; /* head of buf chain */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* floppy driver configuration */
|
1996-12-11 01:54:46 +03:00
|
|
|
int fdmatch __P((struct device *, struct cfdata *, void *));
|
1995-02-17 23:28:32 +03:00
|
|
|
void fdattach __P((struct device *, struct device *, void *));
|
|
|
|
|
1996-03-17 05:00:30 +03:00
|
|
|
struct cfattach fd_ca = {
|
|
|
|
sizeof(struct fd_softc), fdmatch, fdattach
|
|
|
|
};
|
|
|
|
|
1998-01-12 23:23:38 +03:00
|
|
|
extern struct cfdriver fd_cd;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-01-15 03:14:42 +03:00
|
|
|
void fdgetdisklabel __P((dev_t));
|
1995-02-17 23:28:32 +03:00
|
|
|
int fd_get_parms __P((struct fd_softc *));
|
|
|
|
void fdstrategy __P((struct buf *));
|
|
|
|
void fdstart __P((struct fd_softc *));
|
1996-08-28 01:53:46 +04:00
|
|
|
int fdprint __P((void *, const char *));
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
struct dkdriver fddkdriver = { fdstrategy };
|
|
|
|
|
|
|
|
struct fd_type *fd_nvtotype __P((char *, int, int));
|
1995-10-03 20:32:12 +03:00
|
|
|
void fd_set_motor __P((struct fdc_softc *fdc));
|
1995-02-17 23:28:32 +03:00
|
|
|
void fd_motor_off __P((void *arg));
|
|
|
|
void fd_motor_on __P((void *arg));
|
|
|
|
int fdcresult __P((struct fdc_softc *fdc));
|
|
|
|
int out_fdc __P((struct fdc_softc *fdc, u_char x));
|
|
|
|
void fdcstart __P((struct fdc_softc *fdc));
|
|
|
|
void fdcstatus __P((struct device *dv, int n, char *s));
|
1995-10-03 20:32:12 +03:00
|
|
|
void fdc_reset __P((struct fdc_softc *fdc));
|
1995-02-17 23:28:32 +03:00
|
|
|
void fdctimeout __P((void *arg));
|
|
|
|
void fdcpseudointr __P((void *arg));
|
1995-02-23 00:37:15 +03:00
|
|
|
#ifdef FDC_C_HANDLER
|
1998-03-21 23:11:30 +03:00
|
|
|
int fdchwintr __P((void *));
|
1995-02-23 00:37:15 +03:00
|
|
|
#else
|
|
|
|
void fdchwintr __P((void));
|
|
|
|
#endif
|
1998-03-21 23:11:30 +03:00
|
|
|
int fdcswintr __P((void *));
|
1996-12-09 02:40:32 +03:00
|
|
|
int fdcstate __P((struct fdc_softc *));
|
1995-02-17 23:28:32 +03:00
|
|
|
void fdcretry __P((struct fdc_softc *fdc));
|
|
|
|
void fdfinish __P((struct fd_softc *fd, struct buf *bp));
|
1996-12-09 02:40:32 +03:00
|
|
|
int fdformat __P((dev_t, struct ne7_fd_formb *, struct proc *));
|
1997-05-02 17:03:44 +04:00
|
|
|
void fd_do_eject __P((struct fd_softc *));
|
1996-01-15 03:14:42 +03:00
|
|
|
void fd_mountroot_hook __P((struct device *));
|
1996-03-14 22:44:30 +03:00
|
|
|
static void fdconf __P((struct fdc_softc *));
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
#if PIL_FDSOFT == 4
|
1995-02-17 23:28:32 +03:00
|
|
|
#define IE_FDSOFT IE_L4
|
1995-02-23 00:37:15 +03:00
|
|
|
#else
|
|
|
|
#error 4
|
|
|
|
#endif
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
#ifdef FDC_C_HANDLER
|
|
|
|
#if defined(SUN4M)
|
|
|
|
#define FD_SET_SWINTR do { \
|
|
|
|
if (CPU_ISSUN4M) \
|
|
|
|
raise(0, PIL_FDSOFT); \
|
|
|
|
else \
|
|
|
|
ienab_bis(IE_L4); \
|
|
|
|
} while(0)
|
|
|
|
#else
|
|
|
|
#define AUDIO_SET_SWINTR ienab_bis(IE_FDSOFT)
|
|
|
|
#endif /* defined(SUN4M) */
|
|
|
|
#endif /* FDC_C_HANDLER */
|
|
|
|
|
1996-02-26 00:45:53 +03:00
|
|
|
#define OBP_FDNAME (CPU_ISSUN4M ? "SUNW,fdtwo" : "fd")
|
1995-08-18 14:30:16 +04:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
int
|
1998-03-21 23:11:30 +03:00
|
|
|
fdcmatch_mainbus(parent, match, aux)
|
1995-02-17 23:28:32 +03:00
|
|
|
struct device *parent;
|
1996-12-11 01:54:46 +03:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
1998-03-21 23:11:30 +03:00
|
|
|
struct mainbus_attach_args *ma = aux;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-02-26 00:45:53 +03:00
|
|
|
/*
|
1998-03-21 23:11:30 +03:00
|
|
|
* Floppy controller is on mainbus on sun4c.
|
1996-02-26 00:45:53 +03:00
|
|
|
*/
|
1998-03-21 23:11:30 +03:00
|
|
|
if (!CPU_ISSUN4C)
|
1996-02-26 00:45:53 +03:00
|
|
|
return (0);
|
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
/* sun4c PROMs call the controller "fd" */
|
|
|
|
if (strcmp("fd", ma->ma_name) != 0)
|
1996-02-26 00:45:53 +03:00
|
|
|
return (0);
|
|
|
|
|
1998-03-30 18:21:38 +04:00
|
|
|
return (bus_space_probe(ma->ma_bustag,
|
|
|
|
ma->ma_iospace,
|
|
|
|
ma->ma_paddr,
|
|
|
|
1, /* probe size */
|
|
|
|
0, /* offset */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL));
|
1998-03-21 23:11:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdcmatch_obio(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
union obio_attach_args *uoba = aux;
|
|
|
|
struct sbus_attach_args *sa;
|
|
|
|
|
1996-02-26 00:45:53 +03:00
|
|
|
/*
|
|
|
|
* Floppy controller is on obio on sun4m.
|
|
|
|
*/
|
1998-03-21 23:11:30 +03:00
|
|
|
if (uoba->uoba_isobio4 != 0)
|
1996-02-26 00:45:53 +03:00
|
|
|
return (0);
|
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
sa = &uoba->uoba_sbus;
|
|
|
|
|
|
|
|
/* sun4m PROMs call the controller "SUNW,fdtwo" */
|
|
|
|
if (strcmp("SUNW,fdtwo", sa->sa_name) != 0)
|
1995-02-17 23:28:32 +03:00
|
|
|
return (0);
|
1996-02-26 00:45:53 +03:00
|
|
|
|
1998-03-30 18:21:38 +04:00
|
|
|
return (bus_space_probe(sa->sa_bustag, sa->sa_slot, sa->sa_offset,
|
|
|
|
1, /* probe size */
|
|
|
|
0, /* offset */
|
|
|
|
0, /* flags */
|
|
|
|
NULL, NULL));
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments passed between fdcattach and fdprobe.
|
|
|
|
*/
|
|
|
|
struct fdc_attach_args {
|
|
|
|
int fa_drive;
|
1996-04-11 00:46:05 +04:00
|
|
|
struct bootpath *fa_bootpath;
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fd_type *fa_deftype;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *fdc;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
|
|
|
register struct fdc_attach_args *fa = aux;
|
|
|
|
|
|
|
|
if (!fdc)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" drive %d", fa->fa_drive);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (QUIET);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fdconf(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
int vroom;
|
|
|
|
|
|
|
|
if (out_fdc(fdc, NE7CMD_DUMPREG) || fdcresult(fdc) != 10)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dumpreg[7] seems to be a motor-off timeout; set it to whatever
|
|
|
|
* the PROM thinks is appropriate.
|
|
|
|
*/
|
|
|
|
if ((vroom = fdc->sc_status[7]) == 0)
|
|
|
|
vroom = 0x64;
|
|
|
|
|
|
|
|
/* Configure controller to use FIFO and Implied Seek */
|
|
|
|
out_fdc(fdc, NE7CMD_CFG);
|
|
|
|
out_fdc(fdc, vroom);
|
1995-02-23 00:37:15 +03:00
|
|
|
out_fdc(fdc, fdc->sc_cfg);
|
1995-02-17 23:28:32 +03:00
|
|
|
out_fdc(fdc, 0); /* PRETRK */
|
|
|
|
/* No result phase */
|
|
|
|
}
|
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
/*
|
|
|
|
* Controller and drives are represented by one and the same
|
|
|
|
* Openprom node, so we can as well check for the floppy boots here.
|
|
|
|
*/
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
void
|
1998-03-21 23:11:30 +03:00
|
|
|
fdcattach_mainbus(parent, self, aux)
|
1995-02-17 23:28:32 +03:00
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)self;
|
1998-03-21 23:11:30 +03:00
|
|
|
struct mainbus_attach_args *ma = aux;
|
1996-02-26 00:45:53 +03:00
|
|
|
struct bootpath *bp;
|
1998-03-21 23:11:30 +03:00
|
|
|
|
|
|
|
fdc->sc_bustag = ma->ma_bustag;
|
|
|
|
|
1998-03-26 02:15:07 +03:00
|
|
|
if (ma->ma_promvaddr != 0)
|
|
|
|
fdc->sc_reg = (caddr_t)ma->ma_promvaddr;
|
|
|
|
else {
|
|
|
|
bus_space_handle_t bh;
|
1998-03-30 18:21:38 +04:00
|
|
|
if (bus_space_map2(
|
1998-03-26 02:15:07 +03:00
|
|
|
ma->ma_bustag,
|
|
|
|
ma->ma_iospace,
|
1998-03-30 18:21:38 +04:00
|
|
|
ma->ma_paddr,
|
1998-03-26 02:15:07 +03:00
|
|
|
ma->ma_size,
|
|
|
|
BUS_SPACE_MAP_LINEAR,
|
|
|
|
0,
|
|
|
|
&bh) != 0) {
|
|
|
|
printf("%s: cannot map registers\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fdc->sc_reg = (caddr_t)bh;
|
|
|
|
}
|
1998-03-21 23:11:30 +03:00
|
|
|
|
|
|
|
bp = NULL;
|
|
|
|
if (ma->ma_bp != NULL && strcmp(ma->ma_bp->name, OBP_FDNAME) == 0) {
|
|
|
|
int v0 = ma->ma_bp->val[0];
|
|
|
|
int v1 = ma->ma_bp->val[1];
|
|
|
|
/*
|
|
|
|
* We can get the bootpath in several different
|
|
|
|
* formats! The faked v1 bootpath looks like /fd@0,0.
|
|
|
|
* The v2 bootpath is either just /fd0, in which case
|
|
|
|
* `bp->val[0]' will have been set to -1, or /fd@x,y
|
|
|
|
* where <x,y> is the prom address specifier.
|
|
|
|
*/
|
|
|
|
if (((v0 == ma->ma_iospace) && (v1 == (int)ma->ma_paddr)) ||
|
|
|
|
((v0 == -1) && (v1 == 0)) || /* v2: /fd0 */
|
|
|
|
((v0 == 0) && (v1 == 0)) /* v1: /fd@0,0 */ )
|
|
|
|
bp = ma->ma_bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdcattach(fdc, ma->ma_pri, bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcattach_obio(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)self;
|
|
|
|
union obio_attach_args *uoba = aux;
|
|
|
|
struct sbus_attach_args *sa = &uoba->uoba_sbus;
|
|
|
|
struct bootpath *bp;
|
|
|
|
|
|
|
|
fdc->sc_bustag = sa->sa_bustag;
|
|
|
|
|
1998-07-29 22:44:22 +04:00
|
|
|
if (sa->sa_npromvaddrs != 0)
|
|
|
|
fdc->sc_reg = (caddr_t)sa->sa_promvaddrs[0];
|
1998-03-21 23:11:30 +03:00
|
|
|
else {
|
|
|
|
bus_space_handle_t bh;
|
|
|
|
|
|
|
|
if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
|
|
|
|
sa->sa_offset,
|
|
|
|
sa->sa_size,
|
|
|
|
BUS_SPACE_MAP_LINEAR,
|
|
|
|
0,
|
|
|
|
&bh) != 0) {
|
|
|
|
printf("%s: cannot map control registers\n",
|
|
|
|
self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fdc->sc_reg = (caddr_t)bh;
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = NULL;
|
|
|
|
if (sa->sa_bp != NULL && strcmp(sa->sa_bp->name, OBP_FDNAME) == 0) {
|
|
|
|
int v0 = sa->sa_bp->val[0];
|
|
|
|
int v1 = sa->sa_bp->val[1];
|
|
|
|
/*
|
|
|
|
* floppy controller on obio (such as on the sun4m),
|
|
|
|
* e.g.: `/obio0/SUNW,fdtwo@0,700000'.
|
|
|
|
* We use "slot, offset" to determine if this is the
|
|
|
|
* right one.
|
|
|
|
*/
|
|
|
|
if ((v0 != sa->sa_slot) || (v1 != sa->sa_offset))
|
|
|
|
bp = sa->sa_bp;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdcattach(fdc, sa->sa_pri, bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcattach(fdc, pri, bp)
|
|
|
|
struct fdc_softc *fdc;
|
1996-03-14 22:44:30 +03:00
|
|
|
int pri;
|
1998-03-21 23:11:30 +03:00
|
|
|
struct bootpath *bp;
|
|
|
|
{
|
|
|
|
struct fdc_attach_args fa;
|
1995-05-21 00:03:37 +04:00
|
|
|
char code;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
fdc->sc_istate = ISTATE_IDLE;
|
|
|
|
fdc->sc_flags |= FDC_EIS;
|
|
|
|
TAILQ_INIT(&fdc->sc_drives);
|
|
|
|
|
|
|
|
#ifdef FDC_C_HANDLER
|
1998-03-21 23:11:30 +03:00
|
|
|
(void)bus_intr_establish(fdc->sc_bustag, pri, 0,
|
|
|
|
fdchwintr, fdc);
|
1995-02-23 00:37:15 +03:00
|
|
|
#else
|
|
|
|
fdciop = &fdc->sc_io;
|
1998-03-21 23:11:30 +03:00
|
|
|
(void)bus_intr_establish(fdc->sc_bustag, pri,
|
|
|
|
BUS_INTR_ESTABLISH_FASTTRAP,
|
|
|
|
(int (*) __P((void *)))fdchwintr, NULL);
|
1995-02-23 00:37:15 +03:00
|
|
|
#endif
|
1998-03-21 23:11:30 +03:00
|
|
|
(void)bus_intr_establish(fdc->sc_bustag, PIL_FDSOFT,
|
|
|
|
BUS_INTR_ESTABLISH_SOFTINTR,
|
|
|
|
fdcswintr, fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-05-21 00:03:37 +04:00
|
|
|
/* Assume a 82077 */
|
|
|
|
fdc->sc_reg_msr = &((struct fdreg_77 *)fdc->sc_reg)->fd_msr;
|
|
|
|
fdc->sc_reg_fifo = &((struct fdreg_77 *)fdc->sc_reg)->fd_fifo;
|
|
|
|
fdc->sc_reg_dor = &((struct fdreg_77 *)fdc->sc_reg)->fd_dor;
|
|
|
|
|
|
|
|
code = '7';
|
|
|
|
if (*fdc->sc_reg_dor == NE7_RQM) {
|
|
|
|
/*
|
|
|
|
* This hack from Chris Torek: apparently DOR really
|
|
|
|
* addresses MSR/DRS on a 82072.
|
|
|
|
* We used to rely on the VERSION command to tell the
|
|
|
|
* difference (which did not work).
|
|
|
|
*/
|
|
|
|
*fdc->sc_reg_dor = FDC_250KBPS;
|
|
|
|
if (*fdc->sc_reg_dor == NE7_RQM)
|
|
|
|
code = '2';
|
1995-04-14 00:24:36 +04:00
|
|
|
}
|
1995-05-21 00:03:37 +04:00
|
|
|
if (code == '7') {
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_flags |= FDC_82077;
|
|
|
|
} else {
|
1995-05-21 00:03:37 +04:00
|
|
|
fdc->sc_reg_msr = &((struct fdreg_72 *)fdc->sc_reg)->fd_msr;
|
|
|
|
fdc->sc_reg_fifo = &((struct fdreg_72 *)fdc->sc_reg)->fd_fifo;
|
|
|
|
fdc->sc_reg_dor = 0;
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1995-05-21 00:03:37 +04:00
|
|
|
#ifdef FD_DEBUG
|
|
|
|
if (out_fdc(fdc, NE7CMD_VERSION) == 0 &&
|
|
|
|
fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x90) {
|
|
|
|
if (fdc_debug)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("[version cmd]");
|
1995-05-21 00:03:37 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
/*
|
|
|
|
* Configure controller; enable FIFO, Implied seek, no POLL mode?.
|
1995-04-25 18:44:44 +04:00
|
|
|
* Note: CFG_EFIFO is active-low, initial threshold value: 8
|
1995-02-23 00:37:15 +03:00
|
|
|
*/
|
1995-04-25 18:44:44 +04:00
|
|
|
fdc->sc_cfg = CFG_EIS|/*CFG_EFIFO|*/CFG_POLL|(8 & CFG_THRHLD_MASK);
|
1995-02-17 23:28:32 +03:00
|
|
|
fdconf(fdc);
|
|
|
|
|
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
|
|
|
/* Lock configuration across soft resets. */
|
|
|
|
out_fdc(fdc, NE7CMD_LOCK | CFG_LOCK);
|
|
|
|
if (fdcresult(fdc) != 1)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" CFGLOCK: unexpected response");
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1995-11-12 00:12:50 +03:00
|
|
|
evcnt_attach(&fdc->sc_dev, "intr", &fdc->sc_intrcnt);
|
1995-04-07 23:46:13 +04:00
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
printf(" softpri %d: chip 8207%c\n", PIL_FDSOFT, code);
|
1996-04-01 02:38:29 +04:00
|
|
|
|
1998-03-21 23:11:30 +03:00
|
|
|
fa.fa_bootpath = bp;
|
1995-08-18 14:30:16 +04:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* physical limit: four drives per controller. */
|
|
|
|
for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
|
|
|
|
fa.fa_deftype = NULL; /* unknown */
|
|
|
|
fa.fa_deftype = &fd_types[0]; /* XXX */
|
1998-03-21 23:11:30 +03:00
|
|
|
(void)config_found(&fdc->sc_dev, (void *)&fa, fdprint);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
1996-01-08 01:01:38 +03:00
|
|
|
|
|
|
|
bootpath_store(1, NULL);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
1996-12-11 01:54:46 +03:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)parent;
|
|
|
|
struct fdc_attach_args *fa = aux;
|
|
|
|
int drive = fa->fa_drive;
|
1996-04-29 16:07:32 +04:00
|
|
|
int n, ok;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-05-21 00:03:37 +04:00
|
|
|
if (drive > 0)
|
1997-05-02 17:03:44 +04:00
|
|
|
/* XXX - for now, punt on more than one drive */
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-05-21 00:03:37 +04:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
|
|
|
/* select drive and turn on motor */
|
|
|
|
*fdc->sc_reg_dor = drive | FDO_FRST | FDO_MOEN(drive);
|
|
|
|
/* wait for motor to spin up */
|
|
|
|
delay(250000);
|
|
|
|
} else {
|
1997-04-08 01:00:34 +04:00
|
|
|
auxregbisc(AUXIO4C_FDS, 0);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
fdc->sc_nstat = 0;
|
|
|
|
out_fdc(fdc, NE7CMD_RECAL);
|
|
|
|
out_fdc(fdc, drive);
|
|
|
|
/* wait for recalibrate */
|
1996-04-29 16:07:32 +04:00
|
|
|
for (n = 0; n < 10000; n++) {
|
|
|
|
delay(1000);
|
1995-02-23 00:37:15 +03:00
|
|
|
if ((*fdc->sc_reg_msr & (NE7_RQM|NE7_DIO|NE7_CB)) == NE7_RQM) {
|
|
|
|
/* wait a bit longer till device *really* is ready */
|
|
|
|
delay(100000);
|
|
|
|
if (out_fdc(fdc, NE7CMD_SENSEI))
|
|
|
|
break;
|
1995-05-16 21:02:00 +04:00
|
|
|
if (fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x80)
|
1995-02-23 00:37:15 +03:00
|
|
|
/*
|
|
|
|
* Got `invalid command'; we interpret it
|
|
|
|
* to mean that the re-calibrate hasn't in
|
|
|
|
* fact finished yet
|
|
|
|
*/
|
|
|
|
continue;
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n = fdc->sc_nstat;
|
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug) {
|
1995-02-17 23:28:32 +03:00
|
|
|
int i;
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdprobe: %d stati:", n);
|
1995-02-17 23:28:32 +03:00
|
|
|
for (i = 0; i < n; i++)
|
1997-07-29 13:58:04 +04:00
|
|
|
printf(" 0x%x", fdc->sc_status[i]);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
#endif
|
1996-04-29 16:07:32 +04:00
|
|
|
ok = (n == 2 && (fdc->sc_status[0] & 0xf8) == 0x20) ? 1 : 0;
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* turn off motor */
|
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
1997-05-02 17:03:44 +04:00
|
|
|
/* deselect drive and turn motor off */
|
|
|
|
*fdc->sc_reg_dor = FDO_FRST | FDO_DS;
|
1995-02-17 23:28:32 +03:00
|
|
|
} else {
|
1997-04-08 01:00:34 +04:00
|
|
|
auxregbisc(0, AUXIO4C_FDS);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
return (ok);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller is working, and drive responded. Attach it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* XXX Allow `flags' to override device type? */
|
|
|
|
|
|
|
|
if (type)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": %s %d cyl, %d head, %d sec\n", type->name,
|
1997-04-08 01:00:34 +04:00
|
|
|
type->cylinders, type->heads, type->sectrac);
|
1995-02-17 23:28:32 +03:00
|
|
|
else
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(": density unknown\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
fd->sc_cylin = -1;
|
|
|
|
fd->sc_drive = drive;
|
|
|
|
fd->sc_deftype = type;
|
|
|
|
fdc->sc_fd[drive] = fd;
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1997-05-02 17:03:44 +04:00
|
|
|
out_fdc(fdc, NE7CMD_SPECIFY);
|
|
|
|
out_fdc(fdc, type->steprate);
|
|
|
|
out_fdc(fdc, 6 | NE7_SPECIFY_NODMA);
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
|
|
|
fd->sc_dk.dk_name = fd->sc_dv.dv_xname;
|
1995-02-17 23:28:32 +03:00
|
|
|
fd->sc_dk.dk_driver = &fddkdriver;
|
1996-01-08 01:01:38 +03:00
|
|
|
disk_attach(&fd->sc_dk);
|
1995-08-18 14:30:16 +04:00
|
|
|
|
1995-10-10 01:33:07 +03:00
|
|
|
/*
|
|
|
|
* We're told if we're the boot device in fdcattach().
|
|
|
|
*/
|
1996-04-11 00:46:05 +04:00
|
|
|
if (fa->fa_bootpath)
|
|
|
|
fa->fa_bootpath->dev = &fd->sc_dv;
|
1995-10-10 01:33:07 +03:00
|
|
|
|
1996-01-15 03:14:42 +03:00
|
|
|
/*
|
|
|
|
* Establish a mountroot_hook anyway in case we booted
|
|
|
|
* with RB_ASKNAME and get selected as the boot device.
|
|
|
|
*/
|
1997-01-31 05:15:54 +03:00
|
|
|
mountroothook_establish(fd_mountroot_hook, &fd->sc_dv);
|
1996-01-15 03:14:42 +03:00
|
|
|
|
1996-01-16 22:35:06 +03:00
|
|
|
/* Make sure the drive motor gets turned off at shutdown time. */
|
|
|
|
fd->sc_sdhook = shutdownhook_establish(fd_motor_off, fd);
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* XXX Need to do some more fiddling with sc_dk. */
|
1996-01-08 01:01:38 +03:00
|
|
|
dk_establish(&fd->sc_dk, &fd->sc_dv);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1996-03-14 22:44:30 +03:00
|
|
|
__inline struct fd_type *
|
1995-02-17 23:28:32 +03:00
|
|
|
fd_dev_to_type(fd, dev)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int type = FDTYPE(dev);
|
|
|
|
|
|
|
|
if (type > (sizeof(fd_types) / sizeof(fd_types[0])))
|
1996-12-09 02:40:32 +03:00
|
|
|
return (NULL);
|
|
|
|
return (type ? &fd_types[type - 1] : fd->sc_deftype);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdstrategy(bp)
|
|
|
|
register struct buf *bp; /* IO operation to perform */
|
|
|
|
{
|
|
|
|
struct fd_softc *fd;
|
|
|
|
int unit = FDUNIT(bp->b_dev);
|
|
|
|
int sz;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* Valid unit, controller, and request? */
|
1996-03-17 05:00:30 +03:00
|
|
|
if (unit >= fd_cd.cd_ndevs ||
|
|
|
|
(fd = fd_cd.cd_devs[unit]) == 0 ||
|
1995-02-17 23:28:32 +03:00
|
|
|
bp->b_blkno < 0 ||
|
1997-10-20 02:29:21 +04:00
|
|
|
(((bp->b_bcount % FD_BSIZE(fd)) != 0 ||
|
|
|
|
(bp->b_blkno * DEV_BSIZE) % FD_BSIZE(fd) != 0) &&
|
1996-12-10 17:44:53 +03:00
|
|
|
(bp->b_flags & B_FORMAT) == 0)) {
|
1995-02-17 23:28:32 +03:00
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it's a null transfer, return immediately. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
1997-10-20 02:29:21 +04:00
|
|
|
sz = howmany(bp->b_bcount, DEV_BSIZE);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1997-10-20 02:29:21 +04:00
|
|
|
if (bp->b_blkno + sz > (fd->sc_type->size * DEV_BSIZE) / FD_BSIZE(fd)) {
|
|
|
|
sz = (fd->sc_type->size * DEV_BSIZE) / FD_BSIZE(fd)
|
|
|
|
- bp->b_blkno;
|
1995-02-17 23:28:32 +03:00
|
|
|
if (sz == 0) {
|
|
|
|
/* If exactly at end of disk, return EOF. */
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (sz < 0) {
|
|
|
|
/* If past end of disk, return EINVAL. */
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* Otherwise, truncate request. */
|
|
|
|
bp->b_bcount = sz << DEV_BSHIFT;
|
|
|
|
}
|
|
|
|
|
1997-10-20 02:29:21 +04:00
|
|
|
bp->b_cylin = (bp->b_blkno * DEV_BSIZE) /
|
|
|
|
(FD_BSIZE(fd) * fd->sc_type->seccyl);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug > 1)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdstrategy: b_blkno %d b_bcount %ld blkno %d cylin %ld\n",
|
1995-02-23 00:37:15 +03:00
|
|
|
bp->b_blkno, bp->b_bcount, fd->sc_blkno, bp->b_cylin);
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Queue transfer on drive, activate drive and controller if idle. */
|
|
|
|
s = splbio();
|
|
|
|
disksort(&fd->sc_q, bp);
|
|
|
|
untimeout(fd_motor_off, fd); /* a good idea */
|
|
|
|
if (!fd->sc_q.b_active)
|
|
|
|
fdstart(fd);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
else {
|
1996-01-08 01:01:38 +03:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
if (fdc->sc_state == DEVIDLE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdstrategy: controller inactive\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
fdcstart(fdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
/* Toss transfer; we're done early. */
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdstart(fd)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
{
|
1996-01-08 01:01:38 +03:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdfinish(fd, bp)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1996-01-08 01:01:38 +03:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
bp->b_resid = fd->sc_bcount;
|
|
|
|
fd->sc_skip = 0;
|
|
|
|
fd->sc_q.b_actf = bp->b_actf;
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
biodone(bp);
|
|
|
|
/* turn off motor 5s from now */
|
|
|
|
timeout(fd_motor_off, fd, 5 * hz);
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1995-10-03 20:32:12 +03:00
|
|
|
fdc_reset(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
1997-05-02 17:03:44 +04:00
|
|
|
*fdc->sc_reg_dor = FDO_FDMAEN | FDO_MOEN(0);
|
1995-10-03 20:32:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*fdc->sc_reg_drs = DRS_RESET;
|
|
|
|
delay(10);
|
|
|
|
*fdc->sc_reg_drs = 0;
|
1997-05-02 17:03:44 +04:00
|
|
|
|
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
|
|
|
*fdc->sc_reg_dor = FDO_FRST | FDO_FDMAEN | FDO_DS;
|
|
|
|
}
|
1995-10-03 20:32:12 +03:00
|
|
|
#ifdef FD_DEBUG
|
|
|
|
if (fdc_debug)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc reset\n");
|
1995-10-03 20:32:12 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_set_motor(fdc)
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd;
|
|
|
|
u_char status;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (fdc->sc_flags & FDC_82077) {
|
1995-10-03 20:32:12 +03:00
|
|
|
status = FDO_FRST | FDO_FDMAEN;
|
1996-03-14 22:44:30 +03:00
|
|
|
if ((fd = fdc->sc_drives.tqh_first) != NULL)
|
1995-10-03 20:32:12 +03:00
|
|
|
status |= fd->sc_drive;
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
for (n = 0; n < 4; n++)
|
|
|
|
if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
|
|
|
|
status |= FDO_MOEN(n);
|
|
|
|
*fdc->sc_reg_dor = status;
|
|
|
|
} else {
|
|
|
|
int on = 0;
|
|
|
|
|
|
|
|
for (n = 0; n < 4; n++)
|
|
|
|
if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
|
|
|
|
on = 1;
|
|
|
|
if (on) {
|
1997-04-08 01:00:34 +04:00
|
|
|
auxregbisc(AUXIO4C_FDS, 0);
|
1995-02-17 23:28:32 +03:00
|
|
|
} else {
|
1997-04-08 01:00:34 +04:00
|
|
|
auxregbisc(0, AUXIO4C_FDS);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_motor_off(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd = arg;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
1996-01-08 01:01:38 +03:00
|
|
|
fd_set_motor((struct fdc_softc *)fd->sc_dv.dv_parent);
|
1995-02-17 23:28:32 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_motor_on(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd = arg;
|
1996-01-08 01:01:38 +03:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fd->sc_flags &= ~FD_MOTOR_WAIT;
|
|
|
|
if ((fdc->sc_drives.tqh_first == fd) && (fdc->sc_state == MOTORWAIT))
|
1996-12-09 02:40:32 +03:00
|
|
|
(void) fdcstate(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdcresult(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
u_char i;
|
|
|
|
int j = 100000,
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
for (; j; j--) {
|
|
|
|
i = *fdc->sc_reg_msr & (NE7_DIO | NE7_RQM | NE7_CB);
|
|
|
|
if (i == NE7_RQM)
|
|
|
|
return (fdc->sc_nstat = n);
|
|
|
|
if (i == (NE7_DIO | NE7_RQM | NE7_CB)) {
|
|
|
|
if (n >= sizeof(fdc->sc_status)) {
|
|
|
|
log(LOG_ERR, "fdcresult: overrun\n");
|
1996-12-09 02:40:32 +03:00
|
|
|
return (-1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_status[n++] = *fdc->sc_reg_fifo;
|
1996-11-28 00:14:33 +03:00
|
|
|
} else
|
|
|
|
delay(10);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
log(LOG_ERR, "fdcresult: timeout\n");
|
|
|
|
return (fdc->sc_nstat = -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
out_fdc(fdc, x)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
u_char x;
|
|
|
|
{
|
|
|
|
int i = 100000;
|
|
|
|
|
1996-11-28 00:14:33 +03:00
|
|
|
while (((*fdc->sc_reg_msr & (NE7_DIO|NE7_RQM)) != NE7_RQM) && i-- > 0)
|
|
|
|
delay(1);
|
1995-02-17 23:28:32 +03:00
|
|
|
if (i <= 0)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (-1);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
*fdc->sc_reg_fifo = x;
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-03-14 22:44:30 +03:00
|
|
|
fdopen(dev, flags, fmt, p)
|
1995-02-17 23:28:32 +03:00
|
|
|
dev_t dev;
|
1996-01-15 03:14:42 +03:00
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
1996-01-15 03:14:42 +03:00
|
|
|
int unit, pmask;
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fd_softc *fd;
|
|
|
|
struct fd_type *type;
|
|
|
|
|
|
|
|
unit = FDUNIT(dev);
|
1996-03-17 05:00:30 +03:00
|
|
|
if (unit >= fd_cd.cd_ndevs)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (ENXIO);
|
1996-03-17 05:00:30 +03:00
|
|
|
fd = fd_cd.cd_devs[unit];
|
1995-02-17 23:28:32 +03:00
|
|
|
if (fd == 0)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (ENXIO);
|
1995-02-17 23:28:32 +03:00
|
|
|
type = fd_dev_to_type(fd, dev);
|
|
|
|
if (type == NULL)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (ENXIO);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
if ((fd->sc_flags & FD_OPEN) != 0 &&
|
|
|
|
fd->sc_type != type)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (EBUSY);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
fd->sc_type = type;
|
|
|
|
fd->sc_cylin = -1;
|
|
|
|
fd->sc_flags |= FD_OPEN;
|
|
|
|
|
1996-01-15 03:14:42 +03:00
|
|
|
/*
|
|
|
|
* Only update the disklabel if we're not open anywhere else.
|
|
|
|
*/
|
|
|
|
if (fd->sc_dk.dk_openmask == 0)
|
|
|
|
fdgetdisklabel(dev);
|
|
|
|
|
|
|
|
pmask = (1 << DISKPART(dev));
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
fd->sc_dk.dk_copenmask |= pmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
fd->sc_dk.dk_bopenmask |= pmask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fd->sc_dk.dk_openmask =
|
|
|
|
fd->sc_dk.dk_copenmask | fd->sc_dk.dk_bopenmask;
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-01-15 03:14:42 +03:00
|
|
|
fdclose(dev, flags, fmt, p)
|
1995-02-17 23:28:32 +03:00
|
|
|
dev_t dev;
|
1996-01-15 03:14:42 +03:00
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
1996-03-17 05:00:30 +03:00
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
|
1996-01-15 03:14:42 +03:00
|
|
|
int pmask = (1 << DISKPART(dev));
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
fd->sc_flags &= ~FD_OPEN;
|
1996-12-09 02:40:32 +03:00
|
|
|
fd->sc_opts &= ~(FDOPT_NORETRY|FDOPT_SILENT);
|
1996-01-15 03:14:42 +03:00
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
fd->sc_dk.dk_copenmask &= ~pmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
fd->sc_dk.dk_bopenmask &= ~pmask;
|
|
|
|
break;
|
|
|
|
}
|
1996-04-01 02:38:29 +04:00
|
|
|
fd->sc_dk.dk_openmask =
|
1996-01-15 03:14:42 +03:00
|
|
|
fd->sc_dk.dk_copenmask | fd->sc_dk.dk_bopenmask;
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1995-07-05 17:34:10 +04:00
|
|
|
int
|
1996-03-14 22:44:30 +03:00
|
|
|
fdread(dev, uio, flag)
|
1995-07-05 17:34:10 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-03-14 22:44:30 +03:00
|
|
|
int flag;
|
1995-07-05 17:34:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(fdstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-03-14 22:44:30 +03:00
|
|
|
fdwrite(dev, uio, flag)
|
1995-07-05 17:34:10 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-03-14 22:44:30 +03:00
|
|
|
int flag;
|
1995-07-05 17:34:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(fdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
void
|
|
|
|
fdcstart(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* only got here if controller's drive queue was inactive; should
|
|
|
|
be in idle state */
|
|
|
|
if (fdc->sc_state != DEVIDLE) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdcstart: not idle\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1996-12-09 02:40:32 +03:00
|
|
|
(void) fdcstate(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcstatus(dv, n, s)
|
|
|
|
struct device *dv;
|
|
|
|
int n;
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)dv->dv_parent;
|
1996-11-13 09:13:39 +03:00
|
|
|
char bits[64];
|
1995-02-17 23:28:32 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* A 82072 seems to return <invalid command> on
|
|
|
|
* gratuitous Sense Interrupt commands.
|
|
|
|
*/
|
|
|
|
if (n == 0 && (fdc->sc_flags & FDC_82077)) {
|
|
|
|
out_fdc(fdc, NE7CMD_SENSEI);
|
|
|
|
(void) fdcresult(fdc);
|
|
|
|
n = 2;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Just print last status */
|
|
|
|
n = fdc->sc_nstat;
|
|
|
|
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("%s: %s: state %d", dv->dv_xname, s, fdc->sc_state);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
1996-11-13 09:13:39 +03:00
|
|
|
printf(" (st0 %s cyl %d)\n",
|
|
|
|
bitmask_snprintf(fdc->sc_status[0], NE7_ST0BITS,
|
|
|
|
bits, sizeof(bits)), fdc->sc_status[1]);
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
case 7:
|
1996-11-13 09:13:39 +03:00
|
|
|
printf(" (st0 %s", bitmask_snprintf(fdc->sc_status[0],
|
|
|
|
NE7_ST0BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st1 %s", bitmask_snprintf(fdc->sc_status[1],
|
|
|
|
NE7_ST1BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st2 %s", bitmask_snprintf(fdc->sc_status[2],
|
|
|
|
NE7_ST2BITS, bits, sizeof(bits)));
|
|
|
|
printf(" cyl %d head %d sec %d)\n",
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" fdcstatus: weird size: %d\n", n);
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdctimeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = arg;
|
|
|
|
struct fd_softc *fd = fdc->sc_drives.tqh_first;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
1996-01-08 01:01:38 +03:00
|
|
|
fdcstatus(&fd->sc_dv, 0, "timeout");
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
if (fd->sc_q.b_actf)
|
|
|
|
fdc->sc_state++;
|
|
|
|
else
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
(void) fdcstate(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
void
|
|
|
|
fdcpseudointr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = arg;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* Just ensure it has the right spl. */
|
|
|
|
s = splbio();
|
1996-12-09 02:40:32 +03:00
|
|
|
(void) fdcstate(fdc);
|
1995-02-23 00:37:15 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef FDC_C_HANDLER
|
1995-02-17 23:28:32 +03:00
|
|
|
/*
|
|
|
|
* hardware interrupt entry point: must be converted to `fast'
|
|
|
|
* (in-window) handler.
|
|
|
|
*/
|
|
|
|
int
|
1998-03-21 23:11:30 +03:00
|
|
|
fdchwintr(arg)
|
|
|
|
void *arg;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
1998-03-21 23:11:30 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
switch (fdc->sc_istate) {
|
1996-12-09 02:40:32 +03:00
|
|
|
case ISTATE_IDLE:
|
|
|
|
return (0);
|
1995-02-23 00:37:15 +03:00
|
|
|
case ISTATE_SENSEI:
|
1995-02-17 23:28:32 +03:00
|
|
|
out_fdc(fdc, NE7CMD_SENSEI);
|
|
|
|
fdcresult(fdc);
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_IDLE;
|
1996-12-09 02:40:32 +03:00
|
|
|
FD_SET_SWINTR;
|
|
|
|
return (1);
|
1995-02-23 00:37:15 +03:00
|
|
|
case ISTATE_SPURIOUS:
|
1995-02-17 23:28:32 +03:00
|
|
|
fdcresult(fdc);
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_SPURIOUS;
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: stray hard interrupt... ");
|
1996-12-09 02:40:32 +03:00
|
|
|
FD_SET_SWINTR;
|
|
|
|
return (1);
|
1995-02-23 00:37:15 +03:00
|
|
|
case ISTATE_DMA:
|
|
|
|
break;
|
|
|
|
default:
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: goofed ...\n");
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
register int msr;
|
|
|
|
|
|
|
|
msr = *fdc->sc_reg_msr;
|
|
|
|
|
|
|
|
if ((msr & NE7_RQM) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((msr & NE7_NDM) == 0) {
|
|
|
|
fdcresult(fdc);
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_IDLE;
|
1995-02-17 23:28:32 +03:00
|
|
|
ienab_bis(IE_FDSOFT);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: overrun: tc = %d\n", fdc->sc_tc);
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msr & NE7_DIO) {
|
1995-02-23 00:37:15 +03:00
|
|
|
*fdc->sc_data++ = *fdc->sc_reg_fifo;
|
1995-02-17 23:28:32 +03:00
|
|
|
} else {
|
1995-02-23 00:37:15 +03:00
|
|
|
*fdc->sc_reg_fifo = *fdc->sc_data++;
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
if (--fdc->sc_tc == 0) {
|
1997-05-02 17:03:44 +04:00
|
|
|
fdc->sc_istate = ISTATE_DONE;
|
1997-04-08 01:00:34 +04:00
|
|
|
FTC_FLIP;
|
1995-02-17 23:28:32 +03:00
|
|
|
fdcresult(fdc);
|
1996-12-09 02:40:32 +03:00
|
|
|
FD_SET_SWINTR;
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
1995-02-23 00:37:15 +03:00
|
|
|
#endif
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
int
|
1998-03-21 23:11:30 +03:00
|
|
|
fdcswintr(arg)
|
|
|
|
void *arg;
|
1996-12-09 02:40:32 +03:00
|
|
|
{
|
1998-03-21 23:11:30 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
1996-12-09 02:40:32 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
if (fdc->sc_istate != ISTATE_DONE)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
fdc->sc_istate = ISTATE_IDLE;
|
|
|
|
s = splbio();
|
|
|
|
fdcstate(fdc);
|
|
|
|
splx(s);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdcstate(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
|
|
|
#define st0 fdc->sc_status[0]
|
|
|
|
#define st1 fdc->sc_status[1]
|
|
|
|
#define cyl fdc->sc_status[1]
|
1995-02-23 00:37:15 +03:00
|
|
|
#define OUT_FDC(fdc, c, s) \
|
|
|
|
do { if (out_fdc(fdc, (c))) { (fdc)->sc_state = (s); goto loop; } } while(0)
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
1996-03-14 22:44:30 +03:00
|
|
|
int read, head, sec, nblks;
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fd_type *type;
|
1996-12-10 17:44:53 +03:00
|
|
|
struct ne7_fd_formb *finfo = NULL;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-10-03 20:32:12 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc->sc_istate != ISTATE_IDLE) {
|
|
|
|
/* Trouble... */
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: spurious interrupt: state %d, istate=%d\n",
|
1995-10-03 20:32:12 +03:00
|
|
|
fdc->sc_state, fdc->sc_istate);
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_IDLE;
|
1995-10-03 20:32:12 +03:00
|
|
|
if (fdc->sc_state == RESETCOMPLETE ||
|
|
|
|
fdc->sc_state == RESETTIMEDOUT) {
|
|
|
|
panic("fdcintr: spurious interrupt can't be cleared");
|
|
|
|
}
|
1995-02-23 00:37:15 +03:00
|
|
|
goto doreset;
|
|
|
|
}
|
|
|
|
|
1995-10-03 20:32:12 +03:00
|
|
|
loop:
|
1995-02-17 23:28:32 +03:00
|
|
|
/* Is there a drive for the controller to do a transfer with? */
|
|
|
|
fd = fdc->sc_drives.tqh_first;
|
|
|
|
if (fd == NULL) {
|
|
|
|
fdc->sc_state = DEVIDLE;
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there a transfer to this drive? If not, deactivate drive. */
|
|
|
|
bp = fd->sc_q.b_actf;
|
|
|
|
if (bp == NULL) {
|
|
|
|
fd->sc_ops = 0;
|
|
|
|
TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
fd->sc_q.b_active = 0;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
1996-12-10 17:44:53 +03:00
|
|
|
if (bp->b_flags & B_FORMAT)
|
|
|
|
finfo = (struct ne7_fd_formb *)bp->b_data;
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
switch (fdc->sc_state) {
|
|
|
|
case DEVIDLE:
|
|
|
|
fdc->sc_errors = 0;
|
|
|
|
fd->sc_skip = 0;
|
|
|
|
fd->sc_bcount = bp->b_bcount;
|
1997-10-20 02:29:21 +04:00
|
|
|
fd->sc_blkno = (bp->b_blkno * DEV_BSIZE) / FD_BSIZE(fd);
|
1995-02-17 23:28:32 +03:00
|
|
|
untimeout(fd_motor_off, fd);
|
|
|
|
if ((fd->sc_flags & FD_MOTOR_WAIT) != 0) {
|
|
|
|
fdc->sc_state = MOTORWAIT;
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
if ((fd->sc_flags & FD_MOTOR) == 0) {
|
|
|
|
/* Turn on the motor, being careful about pairing. */
|
|
|
|
struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
|
|
|
|
if (ofd && ofd->sc_flags & FD_MOTOR) {
|
|
|
|
untimeout(fd_motor_off, ofd);
|
|
|
|
ofd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
|
|
|
}
|
|
|
|
fd->sc_flags |= FD_MOTOR | FD_MOTOR_WAIT;
|
1995-10-03 20:32:12 +03:00
|
|
|
fd_set_motor(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_state = MOTORWAIT;
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc->sc_flags & FDC_82077) { /* XXX */
|
|
|
|
/* Allow .25s for motor to stabilize. */
|
|
|
|
timeout(fd_motor_on, fd, hz / 4);
|
|
|
|
} else {
|
|
|
|
fd->sc_flags &= ~FD_MOTOR_WAIT;
|
|
|
|
goto loop;
|
|
|
|
}
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
/* Make sure the right drive is selected. */
|
1995-10-03 20:32:12 +03:00
|
|
|
fd_set_motor(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1997-04-08 01:00:34 +04:00
|
|
|
/*FALLTHROUGH*/
|
1995-02-17 23:28:32 +03:00
|
|
|
case DOSEEK:
|
|
|
|
doseek:
|
1996-12-10 17:44:53 +03:00
|
|
|
if ((fdc->sc_flags & FDC_EIS) &&
|
|
|
|
(bp->b_flags & B_FORMAT) == 0) {
|
1995-02-23 00:37:15 +03:00
|
|
|
fd->sc_cylin = bp->b_cylin;
|
|
|
|
/* We use implied seek */
|
|
|
|
goto doio;
|
|
|
|
}
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
if (fd->sc_cylin == bp->b_cylin)
|
|
|
|
goto doio;
|
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
/* specify command */
|
|
|
|
OUT_FDC(fdc, NE7CMD_SPECIFY, SEEKTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, fd->sc_type->steprate, SEEKTIMEDOUT);
|
1997-05-02 17:03:44 +04:00
|
|
|
/* XXX head load time == 6ms */
|
|
|
|
OUT_FDC(fdc, 6 | NE7_SPECIFY_NODMA, SEEKTIMEDOUT);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_SENSEI;
|
|
|
|
/* seek function */
|
|
|
|
OUT_FDC(fdc, NE7CMD_SEEK, SEEKTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, fd->sc_drive, SEEKTIMEDOUT); /* drive number */
|
|
|
|
OUT_FDC(fdc, bp->b_cylin * fd->sc_type->step, SEEKTIMEDOUT);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
fd->sc_cylin = -1;
|
|
|
|
fdc->sc_state = SEEKWAIT;
|
|
|
|
fdc->sc_nstat = 0;
|
1996-01-12 03:19:29 +03:00
|
|
|
|
|
|
|
fd->sc_dk.dk_seek++;
|
|
|
|
disk_busy(&fd->sc_dk);
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
timeout(fdctimeout, fdc, 4 * hz);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case DOIO:
|
|
|
|
doio:
|
1997-05-02 17:03:44 +04:00
|
|
|
if (finfo != NULL)
|
1996-12-10 17:44:53 +03:00
|
|
|
fd->sc_skip = (char *)&(finfo->fd_formb_cylno(0)) -
|
|
|
|
(char *)finfo;
|
1995-02-17 23:28:32 +03:00
|
|
|
type = fd->sc_type;
|
|
|
|
sec = fd->sc_blkno % type->seccyl;
|
|
|
|
nblks = type->seccyl - sec;
|
1997-10-20 02:29:21 +04:00
|
|
|
nblks = min(nblks, fd->sc_bcount / FD_BSIZE(fd));
|
|
|
|
nblks = min(nblks, FDC_MAXIOSIZE / FD_BSIZE(fd));
|
1995-02-17 23:28:32 +03:00
|
|
|
fd->sc_nblks = nblks;
|
1997-10-20 02:29:21 +04:00
|
|
|
fd->sc_nbytes = finfo ? bp->b_bcount : nblks * FD_BSIZE(fd);
|
1995-02-17 23:28:32 +03:00
|
|
|
head = sec / type->sectrac;
|
|
|
|
sec -= head * type->sectrac;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
{int block;
|
|
|
|
block = (fd->sc_cylin * type->heads + head) * type->sectrac + sec;
|
|
|
|
if (block != fd->sc_blkno) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdcintr: block %d != blkno %d\n", block, fd->sc_blkno);
|
1995-02-17 23:28:32 +03:00
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
read = bp->b_flags & B_READ;
|
|
|
|
|
|
|
|
/* Setup for pseudo DMA */
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_data = bp->b_data + fd->sc_skip;
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_tc = fd->sc_nbytes;
|
|
|
|
|
|
|
|
*fdc->sc_reg_drs = type->rate;
|
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug > 1)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdcintr: %s drive %d track %d head %d sec %d nblks %d\n",
|
1995-02-23 00:37:15 +03:00
|
|
|
read ? "read" : "write", fd->sc_drive,
|
|
|
|
fd->sc_cylin, head, sec, nblks);
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_state = IOCOMPLETE;
|
|
|
|
fdc->sc_istate = ISTATE_DMA;
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_nstat = 0;
|
1997-05-02 17:03:44 +04:00
|
|
|
if (finfo != NULL) {
|
1996-12-10 17:44:53 +03:00
|
|
|
/* formatting */
|
|
|
|
OUT_FDC(fdc, NE7CMD_FORMAT, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, (head << 2) | fd->sc_drive, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, finfo->fd_formb_secshift, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, finfo->fd_formb_nsecs, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, finfo->fd_formb_gaplen, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, finfo->fd_formb_fillbyte, IOTIMEDOUT);
|
|
|
|
} else {
|
|
|
|
if (read)
|
|
|
|
OUT_FDC(fdc, NE7CMD_READ, IOTIMEDOUT);
|
|
|
|
else
|
|
|
|
OUT_FDC(fdc, NE7CMD_WRITE, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, (head << 2) | fd->sc_drive, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, fd->sc_cylin, IOTIMEDOUT); /*track*/
|
|
|
|
OUT_FDC(fdc, head, IOTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, sec + 1, IOTIMEDOUT); /*sector+1*/
|
|
|
|
OUT_FDC(fdc, type->secsize, IOTIMEDOUT);/*sector size*/
|
|
|
|
OUT_FDC(fdc, type->sectrac, IOTIMEDOUT);/*secs/track*/
|
|
|
|
OUT_FDC(fdc, type->gap1, IOTIMEDOUT); /*gap1 size*/
|
|
|
|
OUT_FDC(fdc, type->datalen, IOTIMEDOUT);/*data length*/
|
|
|
|
}
|
1996-01-12 03:19:29 +03:00
|
|
|
|
|
|
|
disk_busy(&fd->sc_dk);
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* allow 2 seconds for operation */
|
|
|
|
timeout(fdctimeout, fdc, 2 * hz);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* will return later */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case SEEKWAIT:
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
fdc->sc_state = SEEKCOMPLETE;
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
|
|
|
|
/* allow 1/50 second for heads to settle */
|
|
|
|
timeout(fdcpseudointr, fdc, hz / 50);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* will return later */
|
1995-02-23 00:37:15 +03:00
|
|
|
}
|
1997-04-08 01:00:34 +04:00
|
|
|
/*FALLTHROUGH*/
|
1995-02-17 23:28:32 +03:00
|
|
|
case SEEKCOMPLETE:
|
1996-01-12 03:19:29 +03:00
|
|
|
disk_unbusy(&fd->sc_dk, 0); /* no data on seek */
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
/* Make sure seek really happened. */
|
|
|
|
if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
|
|
|
|
cyl != bp->b_cylin * fd->sc_type->step) {
|
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug)
|
1996-01-08 01:01:38 +03:00
|
|
|
fdcstatus(&fd->sc_dv, 2, "seek failed");
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
fd->sc_cylin = bp->b_cylin;
|
|
|
|
goto doio;
|
|
|
|
|
|
|
|
case IOTIMEDOUT:
|
1997-04-08 01:00:34 +04:00
|
|
|
FTC_FLIP;
|
1995-02-17 23:28:32 +03:00
|
|
|
(void)fdcresult(fdc);
|
1997-04-08 01:00:34 +04:00
|
|
|
/*FALLTHROUGH*/
|
1995-02-17 23:28:32 +03:00
|
|
|
case SEEKTIMEDOUT:
|
|
|
|
case RECALTIMEDOUT:
|
|
|
|
case RESETTIMEDOUT:
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
case IOCOMPLETE: /* IO DONE, post-analyze */
|
|
|
|
untimeout(fdctimeout, fdc);
|
1996-01-12 03:19:29 +03:00
|
|
|
|
|
|
|
disk_unbusy(&fd->sc_dk, (bp->b_bcount - bp->b_resid));
|
|
|
|
|
1997-05-02 17:03:44 +04:00
|
|
|
if (fdc->sc_nstat != 7 || st1 != 0 ||
|
|
|
|
((st0 & 0xf8) != 0 &&
|
|
|
|
((st0 & 0xf8) != 0x20 || (fdc->sc_cfg & CFG_EIS) == 0))) {
|
1995-02-17 23:28:32 +03:00
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug) {
|
1996-01-08 01:01:38 +03:00
|
|
|
fdcstatus(&fd->sc_dv, 7,
|
1995-02-23 00:37:15 +03:00
|
|
|
bp->b_flags & B_READ
|
|
|
|
? "read failed" : "write failed");
|
1997-05-02 17:03:44 +04:00
|
|
|
printf("blkno %d nblks %d nstat %d tc %d\n",
|
|
|
|
fd->sc_blkno, fd->sc_nblks,
|
|
|
|
fdc->sc_nstat, fdc->sc_tc);
|
1995-02-23 00:37:15 +03:00
|
|
|
}
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
1995-04-25 18:44:44 +04:00
|
|
|
if (fdc->sc_nstat == 7 &&
|
|
|
|
(st1 & ST1_OVERRUN) == ST1_OVERRUN) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Silently retry overruns if no other
|
|
|
|
* error bit is set. Adjust threshold.
|
|
|
|
*/
|
1995-02-23 00:37:15 +03:00
|
|
|
int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
|
1995-04-25 18:44:44 +04:00
|
|
|
if (thr < 15) {
|
|
|
|
thr++;
|
|
|
|
fdc->sc_cfg &= ~CFG_THRHLD_MASK;
|
|
|
|
fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
|
1995-02-23 00:37:15 +03:00
|
|
|
#ifdef FD_DEBUG
|
1995-04-25 18:44:44 +04:00
|
|
|
if (fdc_debug)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: %d -> threshold\n", thr);
|
1995-02-23 00:37:15 +03:00
|
|
|
#endif
|
1995-04-25 18:44:44 +04:00
|
|
|
fdconf(fdc);
|
|
|
|
fdc->sc_overruns = 0;
|
|
|
|
}
|
1996-05-27 04:10:40 +04:00
|
|
|
if (++fdc->sc_overruns < 3) {
|
|
|
|
fdc->sc_state = DOIO;
|
1995-04-25 18:44:44 +04:00
|
|
|
goto loop;
|
1996-05-27 04:10:40 +04:00
|
|
|
}
|
1995-02-23 00:37:15 +03:00
|
|
|
}
|
1995-02-17 23:28:32 +03:00
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
if (fdc->sc_errors) {
|
|
|
|
diskerr(bp, "fd", "soft error", LOG_PRINTF,
|
1997-10-20 02:29:21 +04:00
|
|
|
fd->sc_skip / FD_BSIZE(fd),
|
|
|
|
(struct disklabel *)NULL);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_errors = 0;
|
1995-04-25 18:44:44 +04:00
|
|
|
} else {
|
1995-10-03 20:32:12 +03:00
|
|
|
if (--fdc->sc_overruns < -20) {
|
1995-04-25 18:44:44 +04:00
|
|
|
int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
|
|
|
|
if (thr > 0) {
|
|
|
|
thr--;
|
|
|
|
fdc->sc_cfg &= ~CFG_THRHLD_MASK;
|
|
|
|
fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
|
|
|
|
#ifdef FD_DEBUG
|
|
|
|
if (fdc_debug)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("fdc: %d -> threshold\n", thr);
|
1995-04-25 18:44:44 +04:00
|
|
|
#endif
|
|
|
|
fdconf(fdc);
|
|
|
|
}
|
|
|
|
fdc->sc_overruns = 0;
|
|
|
|
}
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
fd->sc_blkno += fd->sc_nblks;
|
|
|
|
fd->sc_skip += fd->sc_nbytes;
|
|
|
|
fd->sc_bcount -= fd->sc_nbytes;
|
1997-05-02 17:03:44 +04:00
|
|
|
if (finfo == NULL && fd->sc_bcount > 0) {
|
1995-02-17 23:28:32 +03:00
|
|
|
bp->b_cylin = fd->sc_blkno / fd->sc_type->seccyl;
|
|
|
|
goto doseek;
|
|
|
|
}
|
|
|
|
fdfinish(fd, bp);
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
case DORESET:
|
1995-02-23 00:37:15 +03:00
|
|
|
doreset:
|
1995-02-17 23:28:32 +03:00
|
|
|
/* try a reset, keep motor on */
|
1995-10-03 20:32:12 +03:00
|
|
|
fd_set_motor(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
delay(100);
|
1995-10-03 20:32:12 +03:00
|
|
|
fdc_reset(fdc);
|
|
|
|
fdc->sc_nstat = 0;
|
|
|
|
fdc->sc_istate = ISTATE_SENSEI;
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_state = RESETCOMPLETE;
|
|
|
|
timeout(fdctimeout, fdc, hz / 2);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* will return later */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case RESETCOMPLETE:
|
|
|
|
untimeout(fdctimeout, fdc);
|
1995-10-03 20:32:12 +03:00
|
|
|
fdconf(fdc);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
case DORECAL:
|
|
|
|
fdc->sc_state = RECALWAIT;
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_istate = ISTATE_SENSEI;
|
1995-02-17 23:28:32 +03:00
|
|
|
fdc->sc_nstat = 0;
|
1995-02-23 00:37:15 +03:00
|
|
|
/* recalibrate function */
|
|
|
|
OUT_FDC(fdc, NE7CMD_RECAL, RECALTIMEDOUT);
|
|
|
|
OUT_FDC(fdc, fd->sc_drive, RECALTIMEDOUT);
|
1995-02-17 23:28:32 +03:00
|
|
|
timeout(fdctimeout, fdc, 5 * hz);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* will return later */
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case RECALWAIT:
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
fdc->sc_state = RECALCOMPLETE;
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
|
|
|
|
/* allow 1/30 second for heads to settle */
|
|
|
|
timeout(fdcpseudointr, fdc, hz / 30);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* will return later */
|
1995-02-23 00:37:15 +03:00
|
|
|
}
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case RECALCOMPLETE:
|
|
|
|
if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
|
|
|
|
#ifdef FD_DEBUG
|
1995-02-23 00:37:15 +03:00
|
|
|
if (fdc_debug)
|
1996-01-08 01:01:38 +03:00
|
|
|
fdcstatus(&fd->sc_dv, 2, "recalibrate failed");
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
fd->sc_cylin = 0;
|
|
|
|
goto doseek;
|
|
|
|
|
|
|
|
case MOTORWAIT:
|
|
|
|
if (fd->sc_flags & FD_MOTOR_WAIT)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1); /* time's not up yet */
|
1995-02-17 23:28:32 +03:00
|
|
|
goto doseek;
|
|
|
|
|
|
|
|
default:
|
1996-01-08 01:01:38 +03:00
|
|
|
fdcstatus(&fd->sc_dv, 0, "stray interrupt");
|
1996-12-09 02:40:32 +03:00
|
|
|
return (1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("fdcintr: impossible");
|
|
|
|
#endif
|
|
|
|
#undef st0
|
|
|
|
#undef st1
|
|
|
|
#undef cyl
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcretry(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
1996-11-13 09:13:39 +03:00
|
|
|
char bits[64];
|
1995-02-17 23:28:32 +03:00
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
fd = fdc->sc_drives.tqh_first;
|
|
|
|
bp = fd->sc_q.b_actf;
|
|
|
|
|
1995-04-25 18:44:44 +04:00
|
|
|
fdc->sc_overruns = 0;
|
1996-12-09 02:40:32 +03:00
|
|
|
if (fd->sc_opts & FDOPT_NORETRY)
|
|
|
|
goto fail;
|
1995-04-25 18:44:44 +04:00
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
switch (fdc->sc_errors) {
|
|
|
|
case 0:
|
|
|
|
/* try again */
|
1995-02-23 00:37:15 +03:00
|
|
|
fdc->sc_state =
|
1996-02-10 21:37:36 +03:00
|
|
|
(fdc->sc_flags & FDC_EIS) ? DOIO : DOSEEK;
|
1995-02-17 23:28:32 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: case 2: case 3:
|
|
|
|
/* didn't work; try recalibrating */
|
|
|
|
fdc->sc_state = DORECAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
/* still no go; reset the bastard */
|
|
|
|
fdc->sc_state = DORESET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-12-09 02:40:32 +03:00
|
|
|
fail:
|
|
|
|
if ((fd->sc_opts & FDOPT_SILENT) == 0) {
|
|
|
|
diskerr(bp, "fd", "hard error", LOG_PRINTF,
|
1997-10-20 02:29:21 +04:00
|
|
|
fd->sc_skip / FD_BSIZE(fd),
|
1996-12-09 02:40:32 +03:00
|
|
|
(struct disklabel *)NULL);
|
|
|
|
|
|
|
|
printf(" (st0 %s", bitmask_snprintf(fdc->sc_status[0],
|
|
|
|
NE7_ST0BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st1 %s", bitmask_snprintf(fdc->sc_status[1],
|
|
|
|
NE7_ST1BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st2 %s", bitmask_snprintf(fdc->sc_status[2],
|
|
|
|
NE7_ST2BITS, bits, sizeof(bits)));
|
|
|
|
printf(" cyl %d head %d sec %d)\n",
|
|
|
|
fdc->sc_status[3], fdc->sc_status[4],
|
|
|
|
fdc->sc_status[5]);
|
|
|
|
}
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
fdfinish(fd, bp);
|
|
|
|
}
|
|
|
|
fdc->sc_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdsize(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Swapping to floppies would not make sense. */
|
1996-12-09 02:40:32 +03:00
|
|
|
return (-1);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-03-14 22:44:30 +03:00
|
|
|
fddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
1996-12-09 02:40:32 +03:00
|
|
|
return (EINVAL);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-03-14 22:44:30 +03:00
|
|
|
fdioctl(dev, cmd, addr, flag, p)
|
1995-02-17 23:28:32 +03:00
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
1996-03-14 22:44:30 +03:00
|
|
|
struct proc *p;
|
1995-02-17 23:28:32 +03:00
|
|
|
{
|
1996-03-17 05:00:30 +03:00
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
|
1996-12-09 02:40:32 +03:00
|
|
|
struct fdformat_parms *form_parms;
|
|
|
|
struct fdformat_cmd *form_cmd;
|
|
|
|
struct ne7_fd_formb fd_formb;
|
|
|
|
int il[FD_MAX_NSEC + 1];
|
|
|
|
int i, j;
|
1995-02-17 23:28:32 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
1996-01-08 01:01:38 +03:00
|
|
|
*(struct disklabel *)addr = *(fd->sc_dk.dk_label);
|
1995-02-17 23:28:32 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
/* XXX do something */
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (EBADF);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
error = setdisklabel(fd->sc_dk.dk_label,
|
1995-10-03 00:04:45 +03:00
|
|
|
(struct disklabel *)addr, 0,
|
1996-01-08 01:01:38 +03:00
|
|
|
fd->sc_dk.dk_cpulabel);
|
1995-02-17 23:28:32 +03:00
|
|
|
if (error)
|
1996-12-09 02:40:32 +03:00
|
|
|
return (error);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1995-10-03 00:04:45 +03:00
|
|
|
error = writedisklabel(dev, fdstrategy,
|
1996-01-08 01:01:38 +03:00
|
|
|
fd->sc_dk.dk_label,
|
|
|
|
fd->sc_dk.dk_cpulabel);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (error);
|
1995-02-17 23:28:32 +03:00
|
|
|
|
1996-01-30 21:31:05 +03:00
|
|
|
case DIOCLOCK:
|
|
|
|
/*
|
|
|
|
* Nothing to do here, really.
|
|
|
|
*/
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1996-01-30 21:31:05 +03:00
|
|
|
|
1995-10-10 01:33:07 +03:00
|
|
|
case DIOCEJECT:
|
1999-02-08 19:33:16 +03:00
|
|
|
if (*(int *)addr == 0) {
|
|
|
|
int part = DISKPART(dev);
|
|
|
|
/*
|
|
|
|
* Don't force eject: check that we are the only
|
|
|
|
* partition open. If so, unlock it.
|
|
|
|
*/
|
|
|
|
if ((fd->sc_dk.dk_openmask & ~(1 << part)) != 0 ||
|
|
|
|
fd->sc_dk.dk_bopenmask + fd->sc_dk.dk_copenmask !=
|
|
|
|
fd->sc_dk.dk_openmask) {
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case ODIOCEJECT:
|
1997-05-02 17:03:44 +04:00
|
|
|
fd_do_eject(fd);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
case FDIOCGETFORMAT:
|
|
|
|
form_parms = (struct fdformat_parms *)addr;
|
|
|
|
form_parms->fdformat_version = FDFORMAT_VERSION;
|
|
|
|
form_parms->nbps = 128 * (1 << fd->sc_type->secsize);
|
1997-04-08 01:00:34 +04:00
|
|
|
form_parms->ncyl = fd->sc_type->cylinders;
|
1996-12-09 02:40:32 +03:00
|
|
|
form_parms->nspt = fd->sc_type->sectrac;
|
|
|
|
form_parms->ntrk = fd->sc_type->heads;
|
|
|
|
form_parms->stepspercyl = fd->sc_type->step;
|
|
|
|
form_parms->gaplen = fd->sc_type->gap2;
|
|
|
|
form_parms->fillbyte = fd->sc_type->fillbyte;
|
|
|
|
form_parms->interleave = fd->sc_type->interleave;
|
|
|
|
switch (fd->sc_type->rate) {
|
|
|
|
case FDC_500KBPS:
|
|
|
|
form_parms->xfer_rate = 500 * 1024;
|
|
|
|
break;
|
|
|
|
case FDC_300KBPS:
|
|
|
|
form_parms->xfer_rate = 300 * 1024;
|
|
|
|
break;
|
|
|
|
case FDC_250KBPS:
|
|
|
|
form_parms->xfer_rate = 250 * 1024;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
1996-12-10 17:44:53 +03:00
|
|
|
return (0);
|
1996-12-09 02:40:32 +03:00
|
|
|
|
|
|
|
case FDIOCSETFORMAT:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF); /* must be opened for writing */
|
|
|
|
|
|
|
|
form_parms = (struct fdformat_parms *)addr;
|
|
|
|
if (form_parms->fdformat_version != FDFORMAT_VERSION)
|
|
|
|
return (EINVAL);/* wrong version of formatting prog */
|
|
|
|
|
|
|
|
i = form_parms->nbps >> 7;
|
|
|
|
if ((form_parms->nbps & 0x7f) || ffs(i) == 0 ||
|
|
|
|
i & ~(1 << (ffs(i)-1)))
|
|
|
|
/* not a power-of-two multiple of 128 */
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
switch (form_parms->xfer_rate) {
|
|
|
|
case 500 * 1024:
|
|
|
|
fd->sc_type->rate = FDC_500KBPS;
|
|
|
|
break;
|
|
|
|
case 300 * 1024:
|
|
|
|
fd->sc_type->rate = FDC_300KBPS;
|
|
|
|
break;
|
|
|
|
case 250 * 1024:
|
|
|
|
fd->sc_type->rate = FDC_250KBPS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (form_parms->nspt > FD_MAX_NSEC ||
|
|
|
|
form_parms->fillbyte > 0xff ||
|
|
|
|
form_parms->interleave > 0xff)
|
|
|
|
return EINVAL;
|
|
|
|
fd->sc_type->sectrac = form_parms->nspt;
|
|
|
|
if (form_parms->ntrk != 2 && form_parms->ntrk != 1)
|
|
|
|
return EINVAL;
|
|
|
|
fd->sc_type->heads = form_parms->ntrk;
|
|
|
|
fd->sc_type->seccyl = form_parms->nspt * form_parms->ntrk;
|
|
|
|
fd->sc_type->secsize = ffs(i)-1;
|
|
|
|
fd->sc_type->gap2 = form_parms->gaplen;
|
1997-04-08 01:00:34 +04:00
|
|
|
fd->sc_type->cylinders = form_parms->ncyl;
|
1996-12-09 02:40:32 +03:00
|
|
|
fd->sc_type->size = fd->sc_type->seccyl * form_parms->ncyl *
|
|
|
|
form_parms->nbps / DEV_BSIZE;
|
|
|
|
fd->sc_type->step = form_parms->stepspercyl;
|
|
|
|
fd->sc_type->fillbyte = form_parms->fillbyte;
|
|
|
|
fd->sc_type->interleave = form_parms->interleave;
|
1997-04-08 01:00:34 +04:00
|
|
|
return (0);
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
case FDIOCFORMAT_TRACK:
|
|
|
|
if((flag & FWRITE) == 0)
|
|
|
|
/* must be opened for writing */
|
|
|
|
return (EBADF);
|
|
|
|
form_cmd = (struct fdformat_cmd *)addr;
|
|
|
|
if (form_cmd->formatcmd_version != FDFORMAT_VERSION)
|
|
|
|
/* wrong version of formatting prog */
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (form_cmd->head >= fd->sc_type->heads ||
|
1997-04-08 01:00:34 +04:00
|
|
|
form_cmd->cylinder >= fd->sc_type->cylinders) {
|
1996-12-09 02:40:32 +03:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd_formb.head = form_cmd->head;
|
|
|
|
fd_formb.cyl = form_cmd->cylinder;
|
|
|
|
fd_formb.transfer_rate = fd->sc_type->rate;
|
|
|
|
fd_formb.fd_formb_secshift = fd->sc_type->secsize;
|
|
|
|
fd_formb.fd_formb_nsecs = fd->sc_type->sectrac;
|
|
|
|
fd_formb.fd_formb_gaplen = fd->sc_type->gap2;
|
|
|
|
fd_formb.fd_formb_fillbyte = fd->sc_type->fillbyte;
|
|
|
|
|
1997-04-08 01:00:34 +04:00
|
|
|
bzero(il, sizeof il);
|
1996-12-09 02:40:32 +03:00
|
|
|
for (j = 0, i = 1; i <= fd_formb.fd_formb_nsecs; i++) {
|
1997-04-08 01:00:34 +04:00
|
|
|
while (il[(j%fd_formb.fd_formb_nsecs) + 1])
|
1996-12-09 02:40:32 +03:00
|
|
|
j++;
|
1997-04-08 01:00:34 +04:00
|
|
|
il[(j%fd_formb.fd_formb_nsecs) + 1] = i;
|
1996-12-09 02:40:32 +03:00
|
|
|
j += fd->sc_type->interleave;
|
|
|
|
}
|
|
|
|
for (i = 0; i < fd_formb.fd_formb_nsecs; i++) {
|
|
|
|
fd_formb.fd_formb_cylno(i) = form_cmd->cylinder;
|
|
|
|
fd_formb.fd_formb_headno(i) = form_cmd->head;
|
|
|
|
fd_formb.fd_formb_secno(i) = il[i+1];
|
|
|
|
fd_formb.fd_formb_secsize(i) = fd->sc_type->secsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fdformat(dev, &fd_formb, p);
|
|
|
|
|
|
|
|
case FDIOCGETOPTS: /* get drive options */
|
|
|
|
*(int *)addr = fd->sc_opts;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
case FDIOCSETOPTS: /* set drive options */
|
|
|
|
fd->sc_opts = *(int *)addr;
|
|
|
|
return (0);
|
|
|
|
|
1995-02-17 23:28:32 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
case _IO('f', 100):
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct fdc_softc *fdc = (struct fdc_softc *)
|
1996-01-08 01:01:38 +03:00
|
|
|
fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
|
|
|
|
out_fdc(fdc, NE7CMD_DUMPREG);
|
|
|
|
fdcresult(fdc);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("dumpreg(%d regs): <", fdc->sc_nstat);
|
1995-02-17 23:28:32 +03:00
|
|
|
for (i = 0; i < fdc->sc_nstat; i++)
|
1997-07-29 13:58:04 +04:00
|
|
|
printf(" 0x%x", fdc->sc_status[i]);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(">\n");
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
case _IOW('f', 101, int):
|
1996-01-08 01:01:38 +03:00
|
|
|
((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg &=
|
1995-02-23 00:37:15 +03:00
|
|
|
~CFG_THRHLD_MASK;
|
1996-01-08 01:01:38 +03:00
|
|
|
((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg |=
|
1995-02-23 00:37:15 +03:00
|
|
|
(*(int *)addr & CFG_THRHLD_MASK);
|
1996-03-14 22:44:30 +03:00
|
|
|
fdconf((struct fdc_softc *) fd->sc_dv.dv_parent);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
case _IO('f', 102):
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct fdc_softc *fdc = (struct fdc_softc *)
|
1996-01-08 01:01:38 +03:00
|
|
|
fd->sc_dv.dv_parent;
|
1995-02-17 23:28:32 +03:00
|
|
|
out_fdc(fdc, NE7CMD_SENSEI);
|
|
|
|
fdcresult(fdc);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("sensei(%d regs): <", fdc->sc_nstat);
|
1995-02-17 23:28:32 +03:00
|
|
|
for (i=0; i< fdc->sc_nstat; i++)
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(" 0x%x", fdc->sc_status[i]);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
1996-10-13 06:59:38 +04:00
|
|
|
printf(">\n");
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1995-02-17 23:28:32 +03:00
|
|
|
#endif
|
|
|
|
default:
|
1996-12-09 02:40:32 +03:00
|
|
|
return (ENOTTY);
|
1995-02-17 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("fdioctl: impossible");
|
|
|
|
#endif
|
|
|
|
}
|
1996-01-15 03:14:42 +03:00
|
|
|
|
1996-12-09 02:40:32 +03:00
|
|
|
int
|
|
|
|
fdformat(dev, finfo, p)
|
|
|
|
dev_t dev;
|
|
|
|
struct ne7_fd_formb *finfo;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
int rv = 0, s;
|
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
|
|
|
|
struct fd_type *type = fd->sc_type;
|
|
|
|
struct buf *bp;
|
|
|
|
|
|
|
|
/* set up a buffer header for fdstrategy() */
|
|
|
|
bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
|
|
|
|
if (bp == 0)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
PHOLD(p);
|
|
|
|
bzero((void *)bp, sizeof(struct buf));
|
|
|
|
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
|
|
|
|
bp->b_proc = p;
|
|
|
|
bp->b_dev = dev;
|
|
|
|
|
|
|
|
/*
|
1997-04-08 01:00:34 +04:00
|
|
|
* Calculate a fake blkno, so fdstrategy() would initiate a
|
|
|
|
* seek to the requested cylinder.
|
1996-12-09 02:40:32 +03:00
|
|
|
*/
|
1997-10-20 02:29:21 +04:00
|
|
|
bp->b_blkno = ((finfo->cyl * (type->sectrac * type->heads)
|
|
|
|
+ finfo->head * type->sectrac) * FD_BSIZE(fd))
|
|
|
|
/ DEV_BSIZE;
|
1996-12-09 02:40:32 +03:00
|
|
|
|
|
|
|
bp->b_bcount = sizeof(struct fd_idfield_data) * finfo->fd_formb_nsecs;
|
|
|
|
bp->b_data = (caddr_t)finfo;
|
|
|
|
|
|
|
|
#ifdef FD_DEBUG
|
|
|
|
if (fdc_debug)
|
1997-07-29 13:58:04 +04:00
|
|
|
printf("fdformat: blkno 0x%x count %ld\n",
|
1996-12-09 02:40:32 +03:00
|
|
|
bp->b_blkno, bp->b_bcount);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* now do the format */
|
|
|
|
fdstrategy(bp);
|
|
|
|
|
|
|
|
/* ...and wait for it to complete */
|
|
|
|
s = splbio();
|
|
|
|
while (!(bp->b_flags & B_DONE)) {
|
|
|
|
rv = tsleep((caddr_t)bp, PRIBIO, "fdform", 20 * hz);
|
|
|
|
if (rv == EWOULDBLOCK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
if (rv == EWOULDBLOCK) {
|
|
|
|
/* timed out */
|
|
|
|
rv = EIO;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
if (bp->b_flags & B_ERROR) {
|
|
|
|
rv = bp->b_error;
|
|
|
|
}
|
|
|
|
PRELE(p);
|
|
|
|
free(bp, M_TEMP);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
1996-01-15 03:14:42 +03:00
|
|
|
void
|
|
|
|
fdgetdisklabel(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int unit = FDUNIT(dev), i;
|
1996-03-17 05:00:30 +03:00
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[unit];
|
1996-01-15 03:14:42 +03:00
|
|
|
struct disklabel *lp = fd->sc_dk.dk_label;
|
|
|
|
struct cpu_disklabel *clp = fd->sc_dk.dk_cpulabel;
|
|
|
|
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
bzero(lp, sizeof(struct cpu_disklabel));
|
|
|
|
|
|
|
|
lp->d_type = DTYPE_FLOPPY;
|
1997-10-20 02:29:21 +04:00
|
|
|
lp->d_secsize = FD_BSIZE(fd);
|
1996-01-15 03:14:42 +03:00
|
|
|
lp->d_secpercyl = fd->sc_type->seccyl;
|
|
|
|
lp->d_nsectors = fd->sc_type->sectrac;
|
1997-04-08 01:00:34 +04:00
|
|
|
lp->d_ncylinders = fd->sc_type->cylinders;
|
1996-01-15 03:14:42 +03:00
|
|
|
lp->d_ntracks = fd->sc_type->heads; /* Go figure... */
|
|
|
|
lp->d_rpm = 3600; /* XXX like it matters... */
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, "floppy", sizeof(lp->d_typename));
|
|
|
|
strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size = lp->d_secpercyl * lp->d_ncylinders;
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the generic disklabel extraction routine. If there's
|
|
|
|
* not a label there, fake it.
|
|
|
|
*/
|
|
|
|
if (readdisklabel(dev, fdstrategy, lp, clp) != NULL) {
|
|
|
|
strncpy(lp->d_packname, "default label",
|
|
|
|
sizeof(lp->d_packname));
|
|
|
|
/*
|
|
|
|
* Reset the partition info; it might have gotten
|
|
|
|
* trashed in readdisklabel().
|
|
|
|
*
|
|
|
|
* XXX Why do we have to do this? readdisklabel()
|
|
|
|
* should be safe...
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXPARTITIONS; ++i) {
|
|
|
|
lp->d_partitions[i].p_offset = 0;
|
|
|
|
if (i == RAW_PART) {
|
|
|
|
lp->d_partitions[i].p_size =
|
|
|
|
lp->d_secpercyl * lp->d_ncylinders;
|
|
|
|
lp->d_partitions[i].p_fstype = FS_BSDFFS;
|
|
|
|
} else {
|
|
|
|
lp->d_partitions[i].p_size = 0;
|
|
|
|
lp->d_partitions[i].p_fstype = FS_UNUSED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-05-02 17:03:44 +04:00
|
|
|
fd_do_eject(fd)
|
|
|
|
struct fd_softc *fd;
|
1996-01-15 03:14:42 +03:00
|
|
|
{
|
1997-05-02 17:03:44 +04:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
|
|
|
|
|
1997-04-08 01:00:34 +04:00
|
|
|
if (CPU_ISSUN4C) {
|
|
|
|
auxregbisc(AUXIO4C_FDS, AUXIO4C_FEJ);
|
|
|
|
delay(10);
|
|
|
|
auxregbisc(AUXIO4C_FEJ, AUXIO4C_FDS);
|
1997-05-02 17:03:44 +04:00
|
|
|
return;
|
1997-04-08 01:00:34 +04:00
|
|
|
}
|
1997-05-02 17:03:44 +04:00
|
|
|
if (CPU_ISSUN4M && (fdc->sc_flags & FDC_82077)) {
|
|
|
|
int dor = FDO_FRST | FDO_FDMAEN | FDO_MOEN(0);
|
|
|
|
*fdc->sc_reg_dor = dor | FDO_EJ;
|
|
|
|
delay(10);
|
|
|
|
*fdc->sc_reg_dor = FDO_FRST | FDO_DS;
|
|
|
|
return;
|
1997-04-08 01:00:34 +04:00
|
|
|
}
|
1996-01-15 03:14:42 +03:00
|
|
|
}
|
|
|
|
|
1996-12-29 02:27:00 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
int fd_read_md_image __P((size_t *, caddr_t *));
|
1996-06-21 00:12:31 +04:00
|
|
|
#endif
|
|
|
|
|
1996-01-15 03:14:42 +03:00
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
fd_mountroot_hook(dev)
|
|
|
|
struct device *dev;
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
1997-05-02 17:03:44 +04:00
|
|
|
fd_do_eject((struct fd_softc *)dev);
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("Insert filesystem floppy and press return.");
|
1996-01-15 03:14:42 +03:00
|
|
|
for (;;) {
|
|
|
|
c = cngetc();
|
|
|
|
if ((c == '\r') || (c == '\n')) {
|
1996-10-13 06:59:38 +04:00
|
|
|
printf("\n");
|
1996-06-21 00:12:31 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-12-29 02:27:00 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1996-06-21 00:12:31 +04:00
|
|
|
|
|
|
|
#define FDMICROROOTSIZE ((2*18*80) << DEV_BSHIFT)
|
|
|
|
|
|
|
|
int
|
1996-12-29 02:27:00 +03:00
|
|
|
fd_read_md_image(sizep, addrp)
|
1996-06-21 00:12:31 +04:00
|
|
|
size_t *sizep;
|
|
|
|
caddr_t *addrp;
|
|
|
|
{
|
|
|
|
struct buf buf, *bp = &buf;
|
|
|
|
dev_t dev;
|
|
|
|
off_t offset;
|
|
|
|
caddr_t addr;
|
|
|
|
|
|
|
|
dev = makedev(54,0); /* XXX */
|
|
|
|
|
|
|
|
MALLOC(addr, caddr_t, FDMICROROOTSIZE, M_DEVBUF, M_WAITOK);
|
|
|
|
*addrp = addr;
|
|
|
|
|
|
|
|
if (fdopen(dev, 0, S_IFCHR, NULL))
|
|
|
|
panic("fd: mountroot: fdopen");
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
bp->b_dev = dev;
|
|
|
|
bp->b_error = 0;
|
|
|
|
bp->b_resid = 0;
|
|
|
|
bp->b_proc = NULL;
|
|
|
|
bp->b_flags = B_BUSY | B_PHYS | B_RAW | B_READ;
|
|
|
|
bp->b_blkno = btodb(offset);
|
|
|
|
bp->b_bcount = DEV_BSIZE;
|
|
|
|
bp->b_data = addr;
|
|
|
|
fdstrategy(bp);
|
|
|
|
while ((bp->b_flags & B_DONE) == 0) {
|
|
|
|
tsleep((caddr_t)bp, PRIBIO + 1, "physio", 0);
|
1996-01-15 03:14:42 +03:00
|
|
|
}
|
1996-06-21 00:12:31 +04:00
|
|
|
if (bp->b_error)
|
|
|
|
panic("fd: mountroot: fdread error %d", bp->b_error);
|
|
|
|
|
|
|
|
if (bp->b_resid != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
addr += DEV_BSIZE;
|
|
|
|
offset += DEV_BSIZE;
|
|
|
|
if (offset + DEV_BSIZE > FDMICROROOTSIZE)
|
|
|
|
break;
|
1996-01-15 03:14:42 +03:00
|
|
|
}
|
1996-06-21 00:12:31 +04:00
|
|
|
(void)fdclose(dev, 0, S_IFCHR, NULL);
|
|
|
|
*sizep = offset;
|
1997-05-02 17:03:44 +04:00
|
|
|
fd_do_eject(fd_cd.cd_devs[FDUNIT(dev)]);
|
1996-12-09 02:40:32 +03:00
|
|
|
return (0);
|
1996-01-15 03:14:42 +03:00
|
|
|
}
|
1996-06-21 00:12:31 +04:00
|
|
|
#endif
|