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