1998-01-13 05:09:58 +03:00
|
|
|
/* $NetBSD: wd.c,v 1.21 1998/01/13 02:10:10 thorpej Exp $ */
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* DMA and multi-sector PIO handling are derived from code contributed by
|
|
|
|
* Onno van der Linden.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Charles M. Hannum.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1996-05-08 01:00:09 +04:00
|
|
|
*
|
1997-10-17 10:41:35 +04:00
|
|
|
* $NetBSD: wd.c,v 1.166 1997/10/13 00:47:33 explorer Exp
|
1996-02-01 02:24:54 +03:00
|
|
|
*/
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
#include "rnd.h"
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/syslog.h>
|
1996-05-08 01:00:09 +04:00
|
|
|
#include <sys/proc.h>
|
1997-10-17 10:41:35 +04:00
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
1997-10-17 10:41:35 +04:00
|
|
|
#include <machine/intr.h>
|
1997-02-04 05:04:51 +03:00
|
|
|
#include <machine/bus.h>
|
1996-05-08 01:00:09 +04:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
#include <arm32/dev/wdreg.h>
|
|
|
|
#include <arm32/dev/wdlink.h>
|
1997-07-17 05:48:35 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
#define WAITTIME (4 * hz) /* time to wait for a completion */
|
|
|
|
|
|
|
|
#define WDIORETRIES 5 /* number of retries before giving up */
|
|
|
|
|
|
|
|
#define WDUNIT(dev) DISKUNIT(dev)
|
|
|
|
#define WDPART(dev) DISKPART(dev)
|
|
|
|
#define MAKEWDDEV(maj, unit, part) MAKEDISKDEV(maj, unit, part)
|
|
|
|
|
|
|
|
#define WDLABELDEV(dev) (MAKEWDDEV(major(dev), WDUNIT(dev), RAW_PART))
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
#ifdef WDDEBUG
|
|
|
|
#define WDDEBUG_PRINT(args) printf args
|
|
|
|
#else
|
|
|
|
#define WDDEBUG_PRINT(args)
|
|
|
|
#endif
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
struct wd_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct disk sc_dk;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
struct buf sc_q;
|
1997-10-17 10:41:35 +04:00
|
|
|
#if NRND > 0
|
|
|
|
rndsource_element_t rnd_source;
|
|
|
|
#endif
|
1996-02-01 02:24:54 +03:00
|
|
|
};
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
int wdprobe __P((struct device *, struct cfdata *, void *));
|
|
|
|
void wdattach __P((struct device *, struct device *, void *));
|
|
|
|
int wdprint __P((void *, char *));
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
struct cfattach wd_ca = {
|
|
|
|
sizeof(struct wd_softc), wdprobe, wdattach
|
|
|
|
};
|
|
|
|
|
1998-01-13 05:09:58 +03:00
|
|
|
extern struct cfdriver wd_cd;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-09 03:37:50 +04:00
|
|
|
void wdgetdefaultlabel __P((struct wd_softc *, struct disklabel *));
|
1996-05-08 01:00:09 +04:00
|
|
|
void wdgetdisklabel __P((struct wd_softc *));
|
|
|
|
int wd_get_parms __P((struct wd_softc *));
|
|
|
|
void wdstrategy __P((struct buf *));
|
1997-10-17 10:41:35 +04:00
|
|
|
void wdstart __P((void *));
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
struct dkdriver wddkdriver = { wdstrategy };
|
|
|
|
|
1996-05-08 01:00:09 +04:00
|
|
|
/* XXX: these should go elsewhere */
|
|
|
|
cdev_decl(wd);
|
|
|
|
bdev_decl(wd);
|
|
|
|
|
|
|
|
void wdfinish __P((struct wd_softc *, struct buf *));
|
1997-10-17 10:41:35 +04:00
|
|
|
int wdsetctlr __P((struct wd_link *));
|
1996-02-01 02:24:54 +03:00
|
|
|
static void bad144intern __P((struct wd_softc *));
|
1997-10-17 10:41:35 +04:00
|
|
|
int wdlock __P((struct wd_link *));
|
|
|
|
void wdunlock __P((struct wd_link *));
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
int
|
1997-10-17 10:41:35 +04:00
|
|
|
wdprobe(parent, match, aux)
|
1996-02-01 02:24:54 +03:00
|
|
|
struct device *parent;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct cfdata *match;
|
1997-10-14 23:13:54 +04:00
|
|
|
void *aux;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct cfdata *cf = match;
|
|
|
|
struct wd_link *d_link = aux;
|
|
|
|
int drive;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link == NULL)
|
|
|
|
return 0;
|
|
|
|
if (d_link->type != ATA)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
drive = d_link->drive;
|
|
|
|
if (cf->cf_loc[ATACF_DRIVE] != ATACF_DRIVE_DEFAULT &&
|
|
|
|
cf->cf_loc[ATACF_DRIVE] != drive)
|
1996-02-01 02:24:54 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct wd_softc *wd = (void *)self;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link= aux;
|
1996-02-01 02:24:54 +03:00
|
|
|
int i, blank;
|
|
|
|
char buf[41], c, *p, *q;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
wd->d_link = d_link;
|
|
|
|
d_link->openings = 1;
|
|
|
|
d_link->wd_softc = (caddr_t)wd;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
|
|
|
wd->sc_dk.dk_driver = &wddkdriver;
|
|
|
|
wd->sc_dk.dk_name = wd->sc_dev.dv_xname;
|
|
|
|
disk_attach(&wd->sc_dk);
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_lp = wd->sc_dk.dk_label;
|
|
|
|
|
|
|
|
wdc_get_parms((struct wdc_softc *)d_link->wdc_softc, d_link);
|
|
|
|
for (blank = 0, p = d_link->sc_params.wdp_model, q = buf, i = 0;
|
|
|
|
i < sizeof(d_link->sc_params.wdp_model); i++) {
|
1996-02-01 02:24:54 +03:00
|
|
|
c = *p++;
|
|
|
|
if (c == '\0')
|
|
|
|
break;
|
|
|
|
if (c != ' ') {
|
|
|
|
if (blank) {
|
|
|
|
*q++ = ' ';
|
|
|
|
blank = 0;
|
|
|
|
}
|
|
|
|
*q++ = c;
|
|
|
|
} else
|
|
|
|
blank = 1;
|
|
|
|
}
|
|
|
|
*q++ = '\0';
|
|
|
|
|
1997-02-04 05:04:51 +03:00
|
|
|
printf(": <%s>\n%s: %dMB, %d cyl, %d head, %d sec, %d bytes/sec\n",
|
1997-10-17 10:41:35 +04:00
|
|
|
buf, self->dv_xname,
|
|
|
|
d_link->sc_params.wdp_cylinders *
|
|
|
|
(d_link->sc_params.wdp_heads * d_link->sc_params.wdp_sectors) /
|
|
|
|
(1048576 / DEV_BSIZE),
|
|
|
|
d_link->sc_params.wdp_cylinders,
|
|
|
|
d_link->sc_params.wdp_heads,
|
|
|
|
d_link->sc_params.wdp_sectors,
|
1997-02-04 05:04:51 +03:00
|
|
|
DEV_BSIZE);
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((d_link->sc_params.wdp_capabilities & WD_CAP_DMA) != 0 &&
|
|
|
|
d_link->sc_mode == WDM_DMA) {
|
|
|
|
d_link->sc_mode = WDM_DMA;
|
|
|
|
} else if (d_link->sc_params.wdp_maxmulti > 1) {
|
|
|
|
d_link->sc_mode = WDM_PIOMULTI;
|
|
|
|
d_link->sc_multiple = min(d_link->sc_params.wdp_maxmulti, 16);
|
1996-02-01 02:24:54 +03:00
|
|
|
} else {
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_mode = WDM_PIOSINGLE;
|
|
|
|
d_link->sc_multiple = 1;
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: using", wd->sc_dev.dv_xname);
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_mode == WDM_DMA)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" dma transfers,");
|
1996-02-01 02:24:54 +03:00
|
|
|
else
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" %d-sector %d-bit pio transfers,",
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_multiple,
|
|
|
|
(d_link->sc_flags & WDF_32BIT) == 0 ? 16 : 32);
|
|
|
|
if ((d_link->sc_params.wdp_capabilities & WD_CAP_LBA) != 0)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" lba addressing\n");
|
1996-02-01 02:24:54 +03:00
|
|
|
else
|
1996-10-13 07:05:43 +04:00
|
|
|
printf(" chs addressing\n");
|
1997-10-17 10:41:35 +04:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_attach_source(&wd->rnd_source, wd->sc_dev.dv_xname, RND_TYPE_DISK);
|
|
|
|
#endif
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read/write routine for a buffer. Validates the arguments and schedules the
|
|
|
|
* transfer. Does not wait for the transfer to complete.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wdstrategy(bp)
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(bp->b_dev)];
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link= wd->d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
/* Valid request? */
|
|
|
|
if (bp->b_blkno < 0 ||
|
|
|
|
(bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 ||
|
|
|
|
(bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If device invalidated (e.g. media change, door open), error. */
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((d_link->sc_flags & WDF_LOADED) == 0) {
|
1996-02-01 02:24:54 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it's a null transfer, return immediately. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do bounds checking, adjust transfer. if error, process.
|
|
|
|
* If end of partition, just return.
|
|
|
|
*/
|
|
|
|
if (WDPART(bp->b_dev) != RAW_PART &&
|
|
|
|
bounds_check_with_label(bp, wd->sc_dk.dk_label,
|
1997-10-17 10:41:35 +04:00
|
|
|
(d_link->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
|
1996-02-01 02:24:54 +03:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Queue transfer on drive, activate drive and controller if idle. */
|
|
|
|
s = splbio();
|
|
|
|
disksort(&wd->sc_q, bp);
|
1997-10-17 10:41:35 +04:00
|
|
|
wdstart(wd);
|
|
|
|
splx(s);
|
1996-02-01 02:24:54 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
/* Toss transfer; we're done early. */
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a drive for I/O.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-17 10:41:35 +04:00
|
|
|
wdstart(arg)
|
|
|
|
void *arg;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_softc *wd = arg;
|
|
|
|
struct buf *dp, *bp=0;
|
|
|
|
struct wd_link *d_link = wd->d_link;
|
|
|
|
struct wdc_xfer *xfer;
|
|
|
|
u_long p_offset;
|
|
|
|
|
|
|
|
while (d_link->openings > 0) {
|
|
|
|
|
|
|
|
/* Is there a buf for us ? */
|
|
|
|
dp = &wd->sc_q;
|
|
|
|
if ((bp = dp->b_actf) == NULL) /* yes, an assign */
|
|
|
|
return;
|
|
|
|
dp->b_actf = bp->b_actf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the command. First lock the device
|
|
|
|
*/
|
|
|
|
d_link->openings--;
|
|
|
|
if (WDPART(bp->b_dev) != RAW_PART)
|
|
|
|
p_offset =
|
|
|
|
wd->sc_dk.dk_label->d_partitions[WDPART(bp->b_dev)].p_offset;
|
|
|
|
else
|
|
|
|
p_offset = 0;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
xfer = wdc_get_xfer(0);
|
|
|
|
if (xfer == NULL)
|
|
|
|
panic("wdc_xfer");
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
xfer->d_link = d_link;
|
|
|
|
xfer->c_bp = bp;
|
|
|
|
xfer->c_p_offset = p_offset;
|
|
|
|
xfer->databuf = bp->b_data;
|
|
|
|
xfer->c_bcount = bp->b_bcount;
|
|
|
|
xfer->c_flags |= bp->b_flags & (B_READ|B_WRITE);
|
|
|
|
xfer->c_blkno = bp->b_blkno;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
/* Instrumentation. */
|
1996-02-01 02:24:54 +03:00
|
|
|
disk_busy(&wd->sc_dk);
|
1997-10-17 10:41:35 +04:00
|
|
|
wdc_exec_xfer((struct wdc_softc *)wd->d_link->wdc_softc,
|
|
|
|
wd->d_link, xfer);
|
|
|
|
}
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-05-08 01:00:09 +04:00
|
|
|
wdread(dev, uio, flags)
|
1996-02-01 02:24:54 +03:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-05-08 01:00:09 +04:00
|
|
|
int flags;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("wdread\n"));
|
1996-02-01 02:24:54 +03:00
|
|
|
return (physio(wdstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-05-08 01:00:09 +04:00
|
|
|
wdwrite(dev, uio, flags)
|
1996-02-01 02:24:54 +03:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1996-05-08 01:00:09 +04:00
|
|
|
int flags;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("wdwrite\n"));
|
1996-02-01 02:24:54 +03:00
|
|
|
return (physio(wdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait interruptibly for an exclusive lock.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Several drivers do this; it should be abstracted and made MP-safe.
|
|
|
|
*/
|
|
|
|
int
|
1997-10-17 10:41:35 +04:00
|
|
|
wdlock(d_link)
|
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
|
|
|
int error;
|
1997-10-17 10:41:35 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
WDDEBUG_PRINT(("wdlock\n"));
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
while ((d_link->sc_flags & WDF_LOCKED) != 0) {
|
|
|
|
d_link->sc_flags |= WDF_WANTED;
|
|
|
|
if ((error = tsleep(d_link, PRIBIO | PCATCH,
|
|
|
|
"wdlck", 0)) != 0) {
|
|
|
|
splx(s);
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
1997-10-17 10:41:35 +04:00
|
|
|
}
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags |= WDF_LOCKED;
|
|
|
|
splx(s);
|
1996-02-01 02:24:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock and wake up any waiters.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-17 10:41:35 +04:00
|
|
|
wdunlock(d_link)
|
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("wdunlock"));
|
|
|
|
|
|
|
|
d_link->sc_flags &= ~WDF_LOCKED;
|
|
|
|
if ((d_link->sc_flags & WDF_WANTED) != 0) {
|
|
|
|
d_link->sc_flags &= ~WDF_WANTED;
|
|
|
|
wakeup(d_link);
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-05-08 01:00:09 +04:00
|
|
|
wdopen(dev, flag, fmt, p)
|
1996-02-01 02:24:54 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flag, fmt;
|
1996-05-08 01:00:09 +04:00
|
|
|
struct proc *p;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
|
|
|
struct wd_softc *wd;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
int unit, part;
|
|
|
|
int error;
|
1997-10-17 10:41:35 +04:00
|
|
|
|
|
|
|
WDDEBUG_PRINT(("wdopen\n"));
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
unit = WDUNIT(dev);
|
1996-03-17 04:16:48 +03:00
|
|
|
if (unit >= wd_cd.cd_ndevs)
|
1996-02-01 02:24:54 +03:00
|
|
|
return ENXIO;
|
1996-03-17 04:16:48 +03:00
|
|
|
wd = wd_cd.cd_devs[unit];
|
1997-06-19 00:39:55 +04:00
|
|
|
if (wd == NULL)
|
1996-02-01 02:24:54 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link = wd->d_link;
|
|
|
|
if ((error = wdlock(d_link)) != 0)
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
if (wd->sc_dk.dk_openmask != 0) {
|
|
|
|
/*
|
|
|
|
* If any partition is open, but the disk has been invalidated,
|
|
|
|
* disallow further opens.
|
|
|
|
*/
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((d_link->sc_flags & WDF_LOADED) == 0) {
|
1996-02-01 02:24:54 +03:00
|
|
|
error = EIO;
|
|
|
|
goto bad3;
|
|
|
|
}
|
|
|
|
} else {
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((d_link->sc_flags & WDF_LOADED) == 0) {
|
|
|
|
d_link->sc_flags |= WDF_LOADED;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
/* Load the physical device parameters. */
|
1997-10-17 10:41:35 +04:00
|
|
|
if (wdc_get_parms((struct wdc_softc *)d_link->wdc_softc,
|
|
|
|
d_link) != 0) {
|
1996-02-01 02:24:54 +03:00
|
|
|
error = ENXIO;
|
|
|
|
goto bad2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the partition info if not already loaded. */
|
|
|
|
wdgetdisklabel(wd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
part = WDPART(dev);
|
|
|
|
|
|
|
|
/* Check that the partition exists. */
|
|
|
|
if (part != RAW_PART &&
|
|
|
|
(part >= wd->sc_dk.dk_label->d_npartitions ||
|
|
|
|
wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insure only one open at a time. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
wd->sc_dk.dk_copenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
wd->sc_dk.dk_bopenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wd->sc_dk.dk_openmask = wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
wdunlock(d_link);
|
1996-02-01 02:24:54 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad2:
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags &= ~WDF_LOADED;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
bad:
|
|
|
|
if (wd->sc_dk.dk_openmask == 0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bad3:
|
1997-10-17 10:41:35 +04:00
|
|
|
wdunlock(d_link);
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-05-08 01:00:09 +04:00
|
|
|
wdclose(dev, flag, fmt, p)
|
1996-02-01 02:24:54 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flag, fmt;
|
1996-05-08 01:00:09 +04:00
|
|
|
struct proc *p;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
|
1996-02-01 02:24:54 +03:00
|
|
|
int part = WDPART(dev);
|
|
|
|
int error;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((error = wdlock(wd->d_link)) != 0)
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
wd->sc_dk.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
wd->sc_dk.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wd->sc_dk.dk_openmask = wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
|
|
|
|
|
|
|
|
if (wd->sc_dk.dk_openmask == 0) {
|
|
|
|
/* XXXX Must wait for I/O to complete! */
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
wdunlock(wd->d_link);
|
1996-02-01 02:24:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-09 03:37:50 +04:00
|
|
|
wdgetdefaultlabel(wd, lp)
|
1996-02-01 02:24:54 +03:00
|
|
|
struct wd_softc *wd;
|
1997-10-09 03:37:50 +04:00
|
|
|
struct disklabel *lp;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link = wd->d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
|
|
|
|
lp->d_secsize = DEV_BSIZE;
|
1997-10-17 10:41:35 +04:00
|
|
|
lp->d_ntracks = d_link->sc_params.wdp_heads;
|
|
|
|
lp->d_nsectors = d_link->sc_params.wdp_sectors;
|
|
|
|
lp->d_ncylinders = d_link->sc_params.wdp_cylinders;
|
1996-02-01 02:24:54 +03:00
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
strncpy(lp->d_typename, "ST506 disk", 16);
|
|
|
|
lp->d_type = DTYPE_ST506;
|
|
|
|
#endif
|
1997-10-17 10:41:35 +04:00
|
|
|
strncpy(lp->d_packname, d_link->sc_params.wdp_model, 16);
|
1996-02-01 02:24:54 +03:00
|
|
|
lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
|
|
|
|
lp->d_rpm = 3600;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size =
|
|
|
|
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
|
|
|
|
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);
|
1997-10-09 03:37:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fabricate a default disk label, and try to read the correct one.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
wdgetdisklabel(wd)
|
|
|
|
struct wd_softc *wd;
|
|
|
|
{
|
|
|
|
struct disklabel *lp = wd->sc_dk.dk_label;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link = wd->d_link;
|
1997-10-09 03:37:50 +04:00
|
|
|
char *errstring;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("wdgetdisklabel\n"));
|
|
|
|
|
1997-10-09 03:37:50 +04:00
|
|
|
bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
|
|
|
|
|
|
|
|
wdgetdefaultlabel(wd, lp);
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_badsect[0] = -1;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_state > RECAL)
|
|
|
|
d_link->sc_state = RECAL;
|
1996-02-01 02:24:54 +03:00
|
|
|
errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART),
|
|
|
|
wdstrategy, lp, wd->sc_dk.dk_cpulabel);
|
|
|
|
if (errstring) {
|
|
|
|
/*
|
|
|
|
* This probably happened because the drive's default
|
|
|
|
* geometry doesn't match the DOS geometry. We
|
|
|
|
* assume the DOS geometry is now in the label and try
|
|
|
|
* again. XXX This is a kluge.
|
|
|
|
*/
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_state > GEOMETRY)
|
|
|
|
d_link->sc_state = GEOMETRY;
|
1996-02-01 02:24:54 +03:00
|
|
|
errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART),
|
|
|
|
wdstrategy, lp, wd->sc_dk.dk_cpulabel);
|
|
|
|
}
|
|
|
|
if (errstring) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("%s: %s\n", wd->sc_dev.dv_xname, errstring);
|
1996-02-01 02:24:54 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_state > GEOMETRY)
|
|
|
|
d_link->sc_state = GEOMETRY;
|
1996-02-01 02:24:54 +03:00
|
|
|
if ((lp->d_flags & D_BADSECT) != 0)
|
|
|
|
bad144intern(wd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the drive what geometry to use.
|
|
|
|
*/
|
|
|
|
int
|
1997-10-17 10:41:35 +04:00
|
|
|
wdsetctlr(d_link)
|
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_softc *wd=(struct wd_softc *)d_link->wd_softc;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("wd(%d,%d) C%dH%dS%d\n", wd->sc_dev.dv_unit,
|
|
|
|
d_link->drive, wd->sc_dk.dk_label->d_ncylinders,
|
|
|
|
wd->sc_dk.dk_label->d_ntracks, wd->sc_dk.dk_label->d_nsectors));
|
|
|
|
|
|
|
|
if (wdccommand((struct wdc_softc *)d_link->wdc_softc,
|
|
|
|
d_link, WDCC_IDP, d_link->drive,
|
|
|
|
wd->sc_dk.dk_label->d_ncylinders,
|
1996-02-01 02:24:54 +03:00
|
|
|
wd->sc_dk.dk_label->d_ntracks - 1, 0,
|
|
|
|
wd->sc_dk.dk_label->d_nsectors) != 0) {
|
1997-10-17 10:41:35 +04:00
|
|
|
wderror(d_link, NULL, "wdsetctlr: geometry upload failed");
|
1996-02-01 02:24:54 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-17 10:41:35 +04:00
|
|
|
wdioctl(dev, xfer, addr, flag, p)
|
1996-02-01 02:24:54 +03:00
|
|
|
dev_t dev;
|
1997-10-17 10:41:35 +04:00
|
|
|
u_long xfer;
|
1996-02-01 02:24:54 +03:00
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1996-03-17 04:16:48 +03:00
|
|
|
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link = wd->d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
int error;
|
1997-10-17 10:41:35 +04:00
|
|
|
|
|
|
|
WDDEBUG_PRINT(("wdioctl\n"));
|
|
|
|
|
|
|
|
if ((d_link->sc_flags & WDF_LOADED) == 0)
|
1996-02-01 02:24:54 +03:00
|
|
|
return EIO;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
switch (xfer) {
|
1996-02-01 02:24:54 +03:00
|
|
|
case DIOCSBAD:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
wd->sc_dk.dk_cpulabel->bad = *(struct dkbad *)addr;
|
|
|
|
wd->sc_dk.dk_label->d_flags |= D_BADSECT;
|
|
|
|
bad144intern(wd);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCGDINFO:
|
|
|
|
*(struct disklabel *)addr = *(wd->sc_dk.dk_label);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCGPART:
|
|
|
|
((struct partinfo *)addr)->disklab = wd->sc_dk.dk_label;
|
|
|
|
((struct partinfo *)addr)->part =
|
|
|
|
&wd->sc_dk.dk_label->d_partitions[WDPART(dev)];
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((error = wdlock(wd->d_link)) != 0)
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags |= WDF_LABELLING;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
error = setdisklabel(wd->sc_dk.dk_label,
|
|
|
|
(struct disklabel *)addr, /*wd->sc_dk.dk_openmask : */0,
|
|
|
|
wd->sc_dk.dk_cpulabel);
|
|
|
|
if (error == 0) {
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_state > GEOMETRY)
|
|
|
|
d_link->sc_state = GEOMETRY;
|
|
|
|
if (xfer == DIOCWDINFO)
|
1996-02-01 02:24:54 +03:00
|
|
|
error = writedisklabel(WDLABELDEV(dev),
|
|
|
|
wdstrategy, wd->sc_dk.dk_label,
|
|
|
|
wd->sc_dk.dk_cpulabel);
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags &= ~WDF_LABELLING;
|
|
|
|
wdunlock(d_link);
|
1996-02-01 02:24:54 +03:00
|
|
|
return error;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
if (*(int *)addr)
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags |= WDF_WLABEL;
|
1996-02-01 02:24:54 +03:00
|
|
|
else
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_flags &= ~WDF_WLABEL;
|
1996-02-01 02:24:54 +03:00
|
|
|
return 0;
|
1997-10-09 03:37:50 +04:00
|
|
|
|
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
wdgetdefaultlabel(wd, (struct disklabel *)addr);
|
|
|
|
return 0;
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
#ifdef notyet
|
|
|
|
case DIOCWFORMAT:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
{
|
|
|
|
register struct format_op *fop;
|
|
|
|
struct iovec aiov;
|
|
|
|
struct uio auio;
|
|
|
|
|
|
|
|
fop = (struct format_op *)addr;
|
|
|
|
aiov.iov_base = fop->df_buf;
|
|
|
|
aiov.iov_len = fop->df_count;
|
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_resid = fop->df_count;
|
|
|
|
auio.uio_segflg = 0;
|
|
|
|
auio.uio_offset =
|
|
|
|
fop->df_startblk * wd->sc_dk.dk_label->d_secsize;
|
|
|
|
auio.uio_procp = p;
|
|
|
|
error = physio(wdformat, NULL, dev, B_WRITE, minphys,
|
|
|
|
&auio);
|
|
|
|
fop->df_count -= auio.uio_resid;
|
|
|
|
fop->df_reg[0] = wdc->sc_status;
|
|
|
|
fop->df_reg[1] = wdc->sc_error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
#endif
|
1997-10-17 10:41:35 +04:00
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("wdioctl: impossible");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef B_FORMAT
|
|
|
|
int
|
|
|
|
wdformat(struct buf *bp)
|
|
|
|
{
|
|
|
|
|
|
|
|
bp->b_flags |= B_FORMAT;
|
|
|
|
return wdstrategy(bp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
wdsize(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
struct wd_softc *wd;
|
1997-06-19 00:39:55 +04:00
|
|
|
int part, unit, omask;
|
1996-02-01 02:24:54 +03:00
|
|
|
int size;
|
1997-10-17 10:41:35 +04:00
|
|
|
|
|
|
|
WDDEBUG_PRINT(("wdsize\n"));
|
|
|
|
|
1997-06-19 00:39:55 +04:00
|
|
|
unit = WDUNIT(dev);
|
|
|
|
if (unit >= wd_cd.cd_ndevs)
|
|
|
|
return (-1);
|
|
|
|
wd = wd_cd.cd_devs[unit];
|
|
|
|
if (wd == NULL)
|
|
|
|
return (-1);
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
part = WDPART(dev);
|
1997-06-19 00:39:55 +04:00
|
|
|
omask = wd->sc_dk.dk_openmask & (1 << part);
|
|
|
|
|
|
|
|
if (omask == 0 && wdopen(dev, 0, S_IFBLK, NULL) != 0)
|
|
|
|
return (-1);
|
1996-02-01 02:24:54 +03:00
|
|
|
if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
|
|
|
|
size = -1;
|
|
|
|
else
|
1997-06-24 04:38:46 +04:00
|
|
|
size = wd->sc_dk.dk_label->d_partitions[part].p_size *
|
1997-10-17 10:41:35 +04:00
|
|
|
(wd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
|
1997-06-19 00:39:55 +04:00
|
|
|
if (omask == 0 && wdclose(dev, 0, S_IFBLK, NULL) != 0)
|
|
|
|
return (-1);
|
|
|
|
return (size);
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __BDEVSW_DUMP_OLD_TYPE
|
|
|
|
/* #define WD_DUMP_NOT_TRUSTED if you just want to watch */
|
|
|
|
static int wddoingadump;
|
|
|
|
static int wddumprecalibrated;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dump core after a system crash.
|
1997-10-17 10:41:35 +04:00
|
|
|
*
|
|
|
|
* XXX: This needs work! Currently, it's a major hack: the
|
|
|
|
* use of wdc_softc is very bad and should go away.
|
1996-02-01 02:24:54 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
wddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
struct wd_softc *wd; /* disk unit to do the I/O */
|
|
|
|
struct wdc_softc *wdc; /* disk controller to do the I/O */
|
|
|
|
struct disklabel *lp; /* disk's disklabel */
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
int unit, part;
|
|
|
|
int nblks; /* total number of sectors left to write */
|
|
|
|
|
|
|
|
/* Check if recursive dump; if so, punt. */
|
|
|
|
if (wddoingadump)
|
|
|
|
return EFAULT;
|
|
|
|
wddoingadump = 1;
|
|
|
|
|
|
|
|
unit = WDUNIT(dev);
|
1996-03-17 04:16:48 +03:00
|
|
|
if (unit >= wd_cd.cd_ndevs)
|
1996-02-01 02:24:54 +03:00
|
|
|
return ENXIO;
|
1996-03-17 04:16:48 +03:00
|
|
|
wd = wd_cd.cd_devs[unit];
|
1997-10-17 10:41:35 +04:00
|
|
|
if (wd == (struct wd_softc *)0)
|
1996-02-01 02:24:54 +03:00
|
|
|
return ENXIO;
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link = wd->d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
part = WDPART(dev);
|
|
|
|
|
|
|
|
/* Make sure it was initialized. */
|
1997-10-17 10:41:35 +04:00
|
|
|
if (d_link->sc_state < READY)
|
1996-02-01 02:24:54 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
wdc = (void *)wd->sc_dev.dv_parent;
|
|
|
|
|
|
|
|
/* Convert to disk sectors. Request must be a multiple of size. */
|
|
|
|
lp = wd->sc_dk.dk_label;
|
|
|
|
if ((size % lp->d_secsize) != 0)
|
|
|
|
return EFAULT;
|
|
|
|
nblks = size / lp->d_secsize;
|
|
|
|
blkno = blkno / (lp->d_secsize / DEV_BSIZE);
|
|
|
|
|
|
|
|
/* Check transfer bounds against partition size. */
|
|
|
|
if ((blkno < 0) || ((blkno + nblks) > lp->d_partitions[part].p_size))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Offset block number to start of partition. */
|
|
|
|
blkno += lp->d_partitions[part].p_offset;
|
|
|
|
|
|
|
|
/* Recalibrate, if first dump transfer. */
|
|
|
|
if (wddumprecalibrated == 0) {
|
|
|
|
wddumprecalibrated = 1;
|
1997-10-17 10:41:35 +04:00
|
|
|
if (wdccommandshort(wdc, d_link->drive, WDCC_RECAL) != 0 ||
|
|
|
|
wait_for_ready(wdc) != 0 || wdsetctlr(d_link) != 0 ||
|
1996-02-01 02:24:54 +03:00
|
|
|
wait_for_ready(wdc) != 0) {
|
1997-10-17 10:41:35 +04:00
|
|
|
wderror(d_link, NULL, "wddump: recal failed");
|
1996-02-01 02:24:54 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (nblks > 0) {
|
|
|
|
daddr_t xlt_blkno = blkno;
|
|
|
|
long cylin, head, sector;
|
|
|
|
|
|
|
|
if ((lp->d_flags & D_BADSECT) != 0) {
|
|
|
|
long blkdiff;
|
|
|
|
int i;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
for (i = 0; (blkdiff = d_link->sc_badsect[i]) != -1; i++) {
|
1996-02-01 02:24:54 +03:00
|
|
|
blkdiff -= xlt_blkno;
|
|
|
|
if (blkdiff < 0)
|
|
|
|
continue;
|
|
|
|
if (blkdiff == 0) {
|
|
|
|
/* Replace current block of transfer. */
|
|
|
|
xlt_blkno = lp->d_secperunit -
|
|
|
|
lp->d_nsectors - i - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Tranfer is okay now. */
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if ((d_link->sc_params.wdp_capabilities & WD_CAP_LBA) != 0) {
|
1996-02-01 02:24:54 +03:00
|
|
|
sector = (xlt_blkno >> 0) & 0xff;
|
|
|
|
cylin = (xlt_blkno >> 8) & 0xffff;
|
|
|
|
head = (xlt_blkno >> 24) & 0xf;
|
|
|
|
head |= WDSD_LBA;
|
|
|
|
} else {
|
|
|
|
sector = xlt_blkno % lp->d_nsectors;
|
|
|
|
sector++; /* Sectors begin with 1, not 0. */
|
|
|
|
xlt_blkno /= lp->d_nsectors;
|
|
|
|
head = xlt_blkno % lp->d_ntracks;
|
|
|
|
xlt_blkno /= lp->d_ntracks;
|
|
|
|
cylin = xlt_blkno;
|
|
|
|
head |= WDSD_CHS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WD_DUMP_NOT_TRUSTED
|
1997-10-17 10:41:35 +04:00
|
|
|
if (wdccommand((struct wdc_softc *)d_link->wdc_softc, d_link,
|
|
|
|
WDCC_WRITE, d_link->drive, cylin, head, sector, 1) != 0 ||
|
1996-02-01 02:24:54 +03:00
|
|
|
wait_for_drq(wdc) != 0) {
|
1997-10-17 10:41:35 +04:00
|
|
|
wderror(d_link, NULL, "wddump: write failed");
|
1996-02-01 02:24:54 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
/* XXX XXX XXX */
|
|
|
|
bus_space_write_multi_2(wdc->sc_iot, wdc->sc_dataioh, wd_data,
|
|
|
|
(u_int16_t *)va, lp->d_secsize >> 1);
|
1996-02-01 02:24:54 +03:00
|
|
|
|
|
|
|
/* Check data request (should be done). */
|
|
|
|
if (wait_for_ready(wdc) != 0) {
|
1997-10-17 10:41:35 +04:00
|
|
|
wderror(d_link, NULL,
|
|
|
|
"wddump: timeout waiting for ready");
|
1996-02-01 02:24:54 +03:00
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
#else /* WD_DUMP_NOT_TRUSTED */
|
|
|
|
/* Let's just talk about this first... */
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("wd%d: dump addr 0x%x, cylin %d, head %d, sector %d\n",
|
1996-02-01 02:24:54 +03:00
|
|
|
unit, va, cylin, head, sector);
|
|
|
|
delay(500 * 1000); /* half a second */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* update block count */
|
|
|
|
nblks -= 1;
|
|
|
|
blkno += 1;
|
|
|
|
va += lp->d_secsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
wddoingadump = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else /* __BDEVSW_DUMP_NEW_TYPE */
|
1997-10-17 10:41:35 +04:00
|
|
|
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
int
|
|
|
|
wddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
#endif /* __BDEVSW_DUMP_NEW_TYPE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internalize the bad sector table.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
bad144intern(wd)
|
|
|
|
struct wd_softc *wd;
|
|
|
|
{
|
|
|
|
struct dkbad *bt = &wd->sc_dk.dk_cpulabel->bad;
|
|
|
|
struct disklabel *lp = wd->sc_dk.dk_label;
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_link *d_link = wd->d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
int i = 0;
|
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
WDDEBUG_PRINT(("bad144intern\n"));
|
|
|
|
|
1996-02-01 02:24:54 +03:00
|
|
|
for (; i < 126; i++) {
|
|
|
|
if (bt->bt_bad[i].bt_cyl == 0xffff)
|
|
|
|
break;
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_badsect[i] =
|
1996-02-01 02:24:54 +03:00
|
|
|
bt->bt_bad[i].bt_cyl * lp->d_secpercyl +
|
|
|
|
(bt->bt_bad[i].bt_trksec >> 8) * lp->d_nsectors +
|
|
|
|
(bt->bt_bad[i].bt_trksec & 0xff);
|
|
|
|
}
|
|
|
|
for (; i < 127; i++)
|
1997-10-17 10:41:35 +04:00
|
|
|
d_link->sc_badsect[i] = -1;
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-17 10:41:35 +04:00
|
|
|
wderror(d_link, bp, msg)
|
|
|
|
struct wd_link *d_link;
|
|
|
|
struct buf *bp;
|
|
|
|
char *msg;
|
1996-02-01 02:24:54 +03:00
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_softc *wd = (struct wd_softc *)d_link->wd_softc;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
if (bp) {
|
|
|
|
diskerr(bp, "wd", msg, LOG_PRINTF, bp->b_bcount,
|
|
|
|
wd->sc_dk.dk_label);
|
|
|
|
printf("\n");
|
1996-02-01 02:24:54 +03:00
|
|
|
} else
|
1997-10-17 10:41:35 +04:00
|
|
|
printf("%s: %s\n", wd->sc_dev.dv_xname, msg);
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-17 10:41:35 +04:00
|
|
|
wddone(d_link, bp)
|
|
|
|
struct wd_link *d_link;
|
1996-02-01 02:24:54 +03:00
|
|
|
struct buf *bp;
|
|
|
|
{
|
1997-10-17 10:41:35 +04:00
|
|
|
struct wd_softc *wd = (void *)d_link->wd_softc;
|
1996-02-01 02:24:54 +03:00
|
|
|
|
1997-10-17 10:41:35 +04:00
|
|
|
disk_unbusy(&wd->sc_dk, (bp->b_bcount - bp->b_resid));
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&wd->rnd_source, bp->b_blkno);
|
|
|
|
#endif
|
1996-02-01 02:24:54 +03:00
|
|
|
}
|