Home | History | Annotate | Line # | Download | only in mca
ed_mca.c revision 1.7.2.10
      1  1.7.2.10  nathanw /*	$NetBSD: ed_mca.c,v 1.7.2.10 2002/11/11 22:10:26 nathanw Exp $	*/
      2   1.7.2.2  nathanw 
      3   1.7.2.2  nathanw /*
      4   1.7.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.7.2.2  nathanw  *
      6   1.7.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      7   1.7.2.2  nathanw  * by Jaromir Dolecek.
      8   1.7.2.2  nathanw  *
      9   1.7.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     10   1.7.2.2  nathanw  * modification, are permitted provided that the following conditions
     11   1.7.2.2  nathanw  * are met:
     12   1.7.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     13   1.7.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     14   1.7.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.7.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     16   1.7.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     17   1.7.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     18   1.7.2.2  nathanw  *    must display the following acknowledgement:
     19   1.7.2.2  nathanw  *        This product includes software developed by the NetBSD
     20   1.7.2.2  nathanw  *        Foundation, Inc. and its contributors.
     21   1.7.2.2  nathanw  * 4. The name of the author may not be used to endorse or promote products
     22   1.7.2.2  nathanw  *    derived from this software without specific prior written permission.
     23   1.7.2.2  nathanw  *
     24   1.7.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25   1.7.2.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26   1.7.2.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27   1.7.2.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28   1.7.2.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29   1.7.2.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30   1.7.2.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31   1.7.2.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32   1.7.2.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33   1.7.2.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34   1.7.2.2  nathanw  */
     35   1.7.2.2  nathanw 
     36   1.7.2.2  nathanw /*
     37   1.7.2.5  nathanw  * Disk drive goo for MCA ESDI controller driver.
     38   1.7.2.2  nathanw  */
     39   1.7.2.2  nathanw 
     40   1.7.2.4  nathanw #include <sys/cdefs.h>
     41  1.7.2.10  nathanw __KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.7.2.10 2002/11/11 22:10:26 nathanw Exp $");
     42   1.7.2.4  nathanw 
     43   1.7.2.2  nathanw #include "rnd.h"
     44   1.7.2.5  nathanw #include "locators.h"
     45   1.7.2.2  nathanw 
     46   1.7.2.2  nathanw #include <sys/param.h>
     47   1.7.2.2  nathanw #include <sys/systm.h>
     48   1.7.2.2  nathanw #include <sys/kernel.h>
     49   1.7.2.2  nathanw #include <sys/conf.h>
     50   1.7.2.2  nathanw #include <sys/file.h>
     51   1.7.2.2  nathanw #include <sys/stat.h>
     52   1.7.2.2  nathanw #include <sys/ioctl.h>
     53   1.7.2.2  nathanw #include <sys/buf.h>
     54   1.7.2.2  nathanw #include <sys/uio.h>
     55   1.7.2.2  nathanw #include <sys/malloc.h>
     56   1.7.2.2  nathanw #include <sys/device.h>
     57   1.7.2.2  nathanw #include <sys/disklabel.h>
     58   1.7.2.2  nathanw #include <sys/disk.h>
     59   1.7.2.2  nathanw #include <sys/syslog.h>
     60   1.7.2.2  nathanw #include <sys/proc.h>
     61   1.7.2.2  nathanw #include <sys/vnode.h>
     62   1.7.2.2  nathanw #if NRND > 0
     63   1.7.2.2  nathanw #include <sys/rnd.h>
     64   1.7.2.2  nathanw #endif
     65   1.7.2.2  nathanw 
     66   1.7.2.2  nathanw #include <machine/intr.h>
     67   1.7.2.2  nathanw #include <machine/bus.h>
     68   1.7.2.2  nathanw 
     69   1.7.2.2  nathanw #include <dev/mca/mcavar.h>
     70   1.7.2.2  nathanw 
     71   1.7.2.2  nathanw #include <dev/mca/edcreg.h>
     72   1.7.2.2  nathanw #include <dev/mca/edvar.h>
     73   1.7.2.2  nathanw #include <dev/mca/edcvar.h>
     74   1.7.2.2  nathanw 
     75   1.7.2.2  nathanw /* #define WDCDEBUG */
     76   1.7.2.2  nathanw 
     77   1.7.2.2  nathanw #ifdef WDCDEBUG
     78   1.7.2.2  nathanw #define WDCDEBUG_PRINT(args, level)  printf args
     79   1.7.2.2  nathanw #else
     80   1.7.2.2  nathanw #define WDCDEBUG_PRINT(args, level)
     81   1.7.2.2  nathanw #endif
     82   1.7.2.2  nathanw 
     83   1.7.2.2  nathanw #define	EDLABELDEV(dev) (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
     84   1.7.2.2  nathanw 
     85   1.7.2.2  nathanw static int     ed_mca_probe   __P((struct device *, struct cfdata *, void *));
     86   1.7.2.2  nathanw static void    ed_mca_attach  __P((struct device *, struct device *, void *));
     87   1.7.2.2  nathanw 
     88   1.7.2.9  nathanw CFATTACH_DECL(ed_mca, sizeof(struct ed_softc),
     89   1.7.2.9  nathanw     ed_mca_probe, ed_mca_attach, NULL, NULL);
     90   1.7.2.2  nathanw 
     91   1.7.2.2  nathanw extern struct cfdriver ed_cd;
     92   1.7.2.2  nathanw 
     93   1.7.2.5  nathanw static int	ed_get_params __P((struct ed_softc *, int *));
     94   1.7.2.2  nathanw static int	ed_lock	__P((struct ed_softc *));
     95   1.7.2.2  nathanw static void	ed_unlock	__P((struct ed_softc *));
     96   1.7.2.5  nathanw static void	edgetdisklabel	__P((dev_t, struct ed_softc *));
     97   1.7.2.2  nathanw static void	edgetdefaultlabel __P((struct ed_softc *, struct disklabel *));
     98   1.7.2.2  nathanw 
     99   1.7.2.8  nathanw dev_type_open(edmcaopen);
    100   1.7.2.8  nathanw dev_type_close(edmcaclose);
    101   1.7.2.8  nathanw dev_type_read(edmcaread);
    102   1.7.2.8  nathanw dev_type_write(edmcawrite);
    103   1.7.2.8  nathanw dev_type_ioctl(edmcaioctl);
    104   1.7.2.8  nathanw dev_type_strategy(edmcastrategy);
    105   1.7.2.8  nathanw dev_type_dump(edmcadump);
    106   1.7.2.8  nathanw dev_type_size(edmcasize);
    107   1.7.2.8  nathanw 
    108   1.7.2.8  nathanw const struct bdevsw ed_bdevsw = {
    109   1.7.2.8  nathanw 	edmcaopen, edmcaclose, edmcastrategy, edmcaioctl,
    110   1.7.2.8  nathanw 	edmcadump, edmcasize, D_DISK
    111   1.7.2.8  nathanw };
    112   1.7.2.8  nathanw 
    113   1.7.2.8  nathanw const struct cdevsw ed_cdevsw = {
    114   1.7.2.8  nathanw 	edmcaopen, edmcaclose, edmcaread, edmcawrite, edmcaioctl,
    115  1.7.2.10  nathanw 	nostop, notty, nopoll, nommap, nokqfilter, D_DISK
    116   1.7.2.8  nathanw };
    117   1.7.2.8  nathanw 
    118   1.7.2.2  nathanw static struct dkdriver eddkdriver = { edmcastrategy };
    119   1.7.2.2  nathanw 
    120   1.7.2.2  nathanw /*
    121   1.7.2.2  nathanw  * Just check if it's possible to identify the disk.
    122   1.7.2.2  nathanw  */
    123   1.7.2.2  nathanw static int
    124   1.7.2.5  nathanw ed_mca_probe(parent, cf, aux)
    125   1.7.2.2  nathanw 	struct device *parent;
    126   1.7.2.5  nathanw 	struct cfdata *cf;
    127   1.7.2.2  nathanw 	void *aux;
    128   1.7.2.2  nathanw {
    129   1.7.2.2  nathanw 	u_int16_t cmd_args[2];
    130   1.7.2.2  nathanw 	struct edc_mca_softc *sc = (void *) parent;
    131   1.7.2.5  nathanw 	struct ed_attach_args *eda = (struct ed_attach_args *) aux;
    132   1.7.2.2  nathanw 	int found = 1;
    133   1.7.2.2  nathanw 
    134   1.7.2.2  nathanw 	/*
    135   1.7.2.5  nathanw 	 * Check we match hardwired config.
    136   1.7.2.5  nathanw 	 */
    137   1.7.2.5  nathanw 	if (cf->edccf_unit != EDCCF_DRIVE_DEFAULT &&
    138   1.7.2.5  nathanw 	    cf->edccf_unit != eda->edc_drive)
    139   1.7.2.5  nathanw 		return (0);
    140   1.7.2.5  nathanw 
    141   1.7.2.5  nathanw 	/*
    142   1.7.2.2  nathanw 	 * Get Device Configuration (09).
    143   1.7.2.2  nathanw 	 */
    144   1.7.2.2  nathanw 	cmd_args[0] = 14;	/* Options: 00s110, s: 0=Physical 1=Pseudo */
    145   1.7.2.2  nathanw 	cmd_args[1] = 0;
    146   1.7.2.5  nathanw 	if (edc_run_cmd(sc, CMD_GET_DEV_CONF, eda->edc_drive, cmd_args, 2, 1))
    147   1.7.2.2  nathanw 		found = 0;
    148   1.7.2.2  nathanw 
    149   1.7.2.2  nathanw 	return (found);
    150   1.7.2.2  nathanw }
    151   1.7.2.2  nathanw 
    152   1.7.2.2  nathanw static void
    153   1.7.2.2  nathanw ed_mca_attach(parent, self, aux)
    154   1.7.2.2  nathanw 	struct device *parent, *self;
    155   1.7.2.2  nathanw 	void *aux;
    156   1.7.2.2  nathanw {
    157   1.7.2.2  nathanw 	struct ed_softc *ed = (void *) self;
    158   1.7.2.2  nathanw 	struct edc_mca_softc *sc = (void *) parent;
    159   1.7.2.5  nathanw 	struct ed_attach_args *eda = (struct ed_attach_args *) aux;
    160   1.7.2.5  nathanw 	char pbuf[8], lckname[10];
    161   1.7.2.5  nathanw 	int drv_flags;
    162   1.7.2.2  nathanw 
    163   1.7.2.2  nathanw 	ed->edc_softc = sc;
    164   1.7.2.5  nathanw 	ed->sc_devno  = eda->edc_drive;
    165   1.7.2.5  nathanw 	edc_add_disk(sc, ed);
    166   1.7.2.2  nathanw 
    167   1.7.2.7  nathanw 	bufq_alloc(&ed->sc_q, BUFQ_DISKSORT|BUFQ_SORT_RAWBLOCK);
    168   1.7.2.3  nathanw 	simple_lock_init(&ed->sc_q_lock);
    169   1.7.2.5  nathanw 	snprintf(lckname, sizeof(lckname), "%slck", ed->sc_dev.dv_xname);
    170   1.7.2.5  nathanw 	lockinit(&ed->sc_lock, PRIBIO | PCATCH, lckname, 0, 0);
    171   1.7.2.2  nathanw 
    172   1.7.2.5  nathanw 	if (ed_get_params(ed, &drv_flags)) {
    173   1.7.2.2  nathanw 		printf(": IDENTIFY failed, no disk found\n");
    174   1.7.2.2  nathanw 		return;
    175   1.7.2.2  nathanw 	}
    176   1.7.2.2  nathanw 
    177   1.7.2.2  nathanw 	format_bytes(pbuf, sizeof(pbuf),
    178   1.7.2.2  nathanw 		(u_int64_t) ed->sc_capacity * DEV_BSIZE);
    179   1.7.2.2  nathanw 	printf(": %s, %u cyl, %u head, %u sec, 512 bytes/sect x %u sectors\n",
    180   1.7.2.2  nathanw 		pbuf,
    181   1.7.2.2  nathanw 		ed->cyl, ed->heads, ed->sectors,
    182   1.7.2.2  nathanw 		ed->sc_capacity);
    183   1.7.2.2  nathanw 
    184   1.7.2.2  nathanw 	printf("%s: %u spares/cyl, %s, %s, %s, %s, %s\n",
    185   1.7.2.2  nathanw 		ed->sc_dev.dv_xname, ed->spares,
    186   1.7.2.5  nathanw 		(drv_flags & (1 << 0)) ? "NoRetries" : "Retries",
    187   1.7.2.5  nathanw 		(drv_flags & (1 << 1)) ? "Removable" : "Fixed",
    188   1.7.2.5  nathanw 		(drv_flags & (1 << 2)) ? "SkewedFormat" : "NoSkew",
    189   1.7.2.5  nathanw 		(drv_flags & (1 << 3)) ? "ZeroDefect" : "Defects",
    190   1.7.2.5  nathanw 		(drv_flags & (1 << 4)) ? "InvalidSecondary" : "SecondaryOK"
    191   1.7.2.2  nathanw 		);
    192   1.7.2.3  nathanw 
    193   1.7.2.2  nathanw 	/*
    194   1.7.2.2  nathanw 	 * Initialize and attach the disk structure.
    195   1.7.2.2  nathanw 	 */
    196   1.7.2.2  nathanw 	ed->sc_dk.dk_driver = &eddkdriver;
    197   1.7.2.2  nathanw 	ed->sc_dk.dk_name = ed->sc_dev.dv_xname;
    198   1.7.2.2  nathanw 	disk_attach(&ed->sc_dk);
    199   1.7.2.2  nathanw #if NRND > 0
    200   1.7.2.2  nathanw 	rnd_attach_source(&ed->rnd_source, ed->sc_dev.dv_xname,
    201   1.7.2.2  nathanw 			  RND_TYPE_DISK, 0);
    202   1.7.2.2  nathanw #endif
    203   1.7.2.2  nathanw 
    204   1.7.2.2  nathanw 	ed->sc_flags |= EDF_INIT;
    205   1.7.2.2  nathanw }
    206   1.7.2.2  nathanw 
    207   1.7.2.2  nathanw /*
    208   1.7.2.2  nathanw  * Read/write routine for a buffer.  Validates the arguments and schedules the
    209   1.7.2.2  nathanw  * transfer.  Does not wait for the transfer to complete.
    210   1.7.2.2  nathanw  */
    211   1.7.2.2  nathanw void
    212   1.7.2.2  nathanw edmcastrategy(bp)
    213   1.7.2.2  nathanw 	struct buf *bp;
    214   1.7.2.2  nathanw {
    215   1.7.2.5  nathanw 	struct ed_softc *ed = device_lookup(&ed_cd, DISKUNIT(bp->b_dev));
    216   1.7.2.5  nathanw 	struct disklabel *lp = ed->sc_dk.dk_label;
    217   1.7.2.2  nathanw 	daddr_t blkno;
    218   1.7.2.2  nathanw 
    219   1.7.2.5  nathanw 	WDCDEBUG_PRINT(("edmcastrategy (%s)\n", ed->sc_dev.dv_xname),
    220   1.7.2.2  nathanw 	    DEBUG_XFERS);
    221   1.7.2.3  nathanw 
    222   1.7.2.2  nathanw 	/* Valid request?  */
    223   1.7.2.2  nathanw 	if (bp->b_blkno < 0 ||
    224   1.7.2.2  nathanw 	    (bp->b_bcount % lp->d_secsize) != 0 ||
    225   1.7.2.2  nathanw 	    (bp->b_bcount / lp->d_secsize) >= (1 << NBBY)) {
    226   1.7.2.2  nathanw 		bp->b_error = EINVAL;
    227   1.7.2.2  nathanw 		goto bad;
    228   1.7.2.2  nathanw 	}
    229   1.7.2.3  nathanw 
    230   1.7.2.2  nathanw 	/* If device invalidated (e.g. media change, door open), error. */
    231   1.7.2.5  nathanw 	if ((ed->sc_flags & WDF_LOADED) == 0) {
    232   1.7.2.2  nathanw 		bp->b_error = EIO;
    233   1.7.2.2  nathanw 		goto bad;
    234   1.7.2.2  nathanw 	}
    235   1.7.2.2  nathanw 
    236   1.7.2.2  nathanw 	/* If it's a null transfer, return immediately. */
    237   1.7.2.2  nathanw 	if (bp->b_bcount == 0)
    238   1.7.2.2  nathanw 		goto done;
    239   1.7.2.2  nathanw 
    240   1.7.2.2  nathanw 	/*
    241   1.7.2.2  nathanw 	 * Do bounds checking, adjust transfer. if error, process.
    242   1.7.2.2  nathanw 	 * If end of partition, just return.
    243   1.7.2.2  nathanw 	 */
    244   1.7.2.2  nathanw 	if (DISKPART(bp->b_dev) != RAW_PART &&
    245   1.7.2.5  nathanw 	    bounds_check_with_label(bp, ed->sc_dk.dk_label,
    246   1.7.2.5  nathanw 	    (ed->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
    247   1.7.2.2  nathanw 		goto done;
    248   1.7.2.2  nathanw 
    249   1.7.2.2  nathanw 	/*
    250   1.7.2.2  nathanw 	 * Now convert the block number to absolute and put it in
    251   1.7.2.2  nathanw 	 * terms of the device's logical block size.
    252   1.7.2.2  nathanw 	 */
    253   1.7.2.2  nathanw 	if (lp->d_secsize >= DEV_BSIZE)
    254   1.7.2.2  nathanw 		blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
    255   1.7.2.2  nathanw 	else
    256   1.7.2.2  nathanw 		blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
    257   1.7.2.2  nathanw 
    258   1.7.2.2  nathanw 	if (DISKPART(bp->b_dev) != RAW_PART)
    259   1.7.2.2  nathanw 		blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
    260   1.7.2.2  nathanw 
    261   1.7.2.2  nathanw 	bp->b_rawblkno = blkno;
    262   1.7.2.2  nathanw 
    263   1.7.2.2  nathanw 	/* Queue transfer on drive, activate drive and controller if idle. */
    264   1.7.2.5  nathanw 	simple_lock(&ed->sc_q_lock);
    265   1.7.2.7  nathanw 	BUFQ_PUT(&ed->sc_q, bp);
    266   1.7.2.5  nathanw 	simple_unlock(&ed->sc_q_lock);
    267   1.7.2.2  nathanw 
    268   1.7.2.2  nathanw 	/* Ring the worker thread */
    269   1.7.2.5  nathanw 	wakeup_one(ed->edc_softc);
    270   1.7.2.2  nathanw 
    271   1.7.2.2  nathanw 	return;
    272   1.7.2.2  nathanw bad:
    273   1.7.2.2  nathanw 	bp->b_flags |= B_ERROR;
    274   1.7.2.2  nathanw done:
    275   1.7.2.2  nathanw 	/* Toss transfer; we're done early. */
    276   1.7.2.2  nathanw 	bp->b_resid = bp->b_bcount;
    277   1.7.2.2  nathanw 	biodone(bp);
    278   1.7.2.2  nathanw }
    279   1.7.2.2  nathanw 
    280   1.7.2.2  nathanw int
    281   1.7.2.2  nathanw edmcaread(dev, uio, flags)
    282   1.7.2.2  nathanw 	dev_t dev;
    283   1.7.2.2  nathanw 	struct uio *uio;
    284   1.7.2.2  nathanw 	int flags;
    285   1.7.2.2  nathanw {
    286   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edread\n"), DEBUG_XFERS);
    287   1.7.2.2  nathanw 	return (physio(edmcastrategy, NULL, dev, B_READ, minphys, uio));
    288   1.7.2.2  nathanw }
    289   1.7.2.2  nathanw 
    290   1.7.2.2  nathanw int
    291   1.7.2.2  nathanw edmcawrite(dev, uio, flags)
    292   1.7.2.2  nathanw 	dev_t dev;
    293   1.7.2.2  nathanw 	struct uio *uio;
    294   1.7.2.2  nathanw 	int flags;
    295   1.7.2.2  nathanw {
    296   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edwrite\n"), DEBUG_XFERS);
    297   1.7.2.2  nathanw 	return (physio(edmcastrategy, NULL, dev, B_WRITE, minphys, uio));
    298   1.7.2.2  nathanw }
    299   1.7.2.2  nathanw 
    300   1.7.2.2  nathanw /*
    301   1.7.2.2  nathanw  * Wait interruptibly for an exclusive lock.
    302   1.7.2.2  nathanw  */
    303   1.7.2.2  nathanw static int
    304   1.7.2.2  nathanw ed_lock(ed)
    305   1.7.2.2  nathanw 	struct ed_softc *ed;
    306   1.7.2.2  nathanw {
    307   1.7.2.2  nathanw 	int error;
    308   1.7.2.2  nathanw 	int s;
    309   1.7.2.2  nathanw 
    310   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("ed_lock\n"), DEBUG_FUNCS);
    311   1.7.2.2  nathanw 
    312   1.7.2.2  nathanw 	s = splbio();
    313   1.7.2.2  nathanw 	error = lockmgr(&ed->sc_lock, LK_EXCLUSIVE, NULL);
    314   1.7.2.2  nathanw 	splx(s);
    315   1.7.2.2  nathanw 
    316   1.7.2.2  nathanw 	return (error);
    317   1.7.2.2  nathanw }
    318   1.7.2.2  nathanw 
    319   1.7.2.2  nathanw /*
    320   1.7.2.2  nathanw  * Unlock and wake up any waiters.
    321   1.7.2.2  nathanw  */
    322   1.7.2.2  nathanw static void
    323   1.7.2.2  nathanw ed_unlock(ed)
    324   1.7.2.2  nathanw 	struct ed_softc *ed;
    325   1.7.2.2  nathanw {
    326   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("ed_unlock\n"), DEBUG_FUNCS);
    327   1.7.2.2  nathanw 
    328   1.7.2.2  nathanw 	(void) lockmgr(&ed->sc_lock, LK_RELEASE, NULL);
    329   1.7.2.2  nathanw }
    330   1.7.2.2  nathanw 
    331   1.7.2.2  nathanw int
    332   1.7.2.2  nathanw edmcaopen(dev, flag, fmt, p)
    333   1.7.2.2  nathanw 	dev_t dev;
    334   1.7.2.2  nathanw 	int flag, fmt;
    335   1.7.2.2  nathanw 	struct proc *p;
    336   1.7.2.2  nathanw {
    337   1.7.2.2  nathanw 	struct ed_softc *wd;
    338   1.7.2.2  nathanw 	int part, error;
    339   1.7.2.2  nathanw 
    340   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edopen\n"), DEBUG_FUNCS);
    341   1.7.2.2  nathanw 	wd = device_lookup(&ed_cd, DISKUNIT(dev));
    342   1.7.2.2  nathanw 	if (wd == NULL || (wd->sc_flags & EDF_INIT) == 0)
    343   1.7.2.2  nathanw 		return (ENXIO);
    344   1.7.2.2  nathanw 
    345   1.7.2.2  nathanw 	if ((error = ed_lock(wd)) != 0)
    346   1.7.2.2  nathanw 		goto bad4;
    347   1.7.2.2  nathanw 
    348   1.7.2.2  nathanw 	if (wd->sc_dk.dk_openmask != 0) {
    349   1.7.2.2  nathanw 		/*
    350   1.7.2.2  nathanw 		 * If any partition is open, but the disk has been invalidated,
    351   1.7.2.2  nathanw 		 * disallow further opens.
    352   1.7.2.2  nathanw 		 */
    353   1.7.2.2  nathanw 		if ((wd->sc_flags & WDF_LOADED) == 0) {
    354   1.7.2.2  nathanw 			error = EIO;
    355   1.7.2.2  nathanw 			goto bad3;
    356   1.7.2.2  nathanw 		}
    357   1.7.2.2  nathanw 	} else {
    358   1.7.2.2  nathanw 		if ((wd->sc_flags & WDF_LOADED) == 0) {
    359   1.7.2.5  nathanw 			int s;
    360   1.7.2.5  nathanw 
    361   1.7.2.2  nathanw 			wd->sc_flags |= WDF_LOADED;
    362   1.7.2.2  nathanw 
    363   1.7.2.2  nathanw 			/* Load the physical device parameters. */
    364   1.7.2.5  nathanw 			s = splbio();
    365   1.7.2.5  nathanw 			ed_get_params(wd, NULL);
    366   1.7.2.5  nathanw 			splx(s);
    367   1.7.2.2  nathanw 
    368   1.7.2.2  nathanw 			/* Load the partition info if not already loaded. */
    369   1.7.2.5  nathanw 			edgetdisklabel(dev, wd);
    370   1.7.2.2  nathanw 		}
    371   1.7.2.2  nathanw 	}
    372   1.7.2.2  nathanw 
    373   1.7.2.2  nathanw 	part = DISKPART(dev);
    374   1.7.2.2  nathanw 
    375   1.7.2.2  nathanw 	/* Check that the partition exists. */
    376   1.7.2.2  nathanw 	if (part != RAW_PART &&
    377   1.7.2.2  nathanw 	    (part >= wd->sc_dk.dk_label->d_npartitions ||
    378   1.7.2.2  nathanw 	     wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
    379   1.7.2.2  nathanw 		error = ENXIO;
    380   1.7.2.2  nathanw 		goto bad;
    381   1.7.2.2  nathanw 	}
    382   1.7.2.3  nathanw 
    383   1.7.2.2  nathanw 	/* Insure only one open at a time. */
    384   1.7.2.2  nathanw 	switch (fmt) {
    385   1.7.2.2  nathanw 	case S_IFCHR:
    386   1.7.2.2  nathanw 		wd->sc_dk.dk_copenmask |= (1 << part);
    387   1.7.2.2  nathanw 		break;
    388   1.7.2.2  nathanw 	case S_IFBLK:
    389   1.7.2.2  nathanw 		wd->sc_dk.dk_bopenmask |= (1 << part);
    390   1.7.2.2  nathanw 		break;
    391   1.7.2.2  nathanw 	}
    392   1.7.2.2  nathanw 	wd->sc_dk.dk_openmask =
    393   1.7.2.2  nathanw 	    wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
    394   1.7.2.2  nathanw 
    395   1.7.2.2  nathanw 	ed_unlock(wd);
    396   1.7.2.2  nathanw 	return 0;
    397   1.7.2.2  nathanw 
    398   1.7.2.2  nathanw bad:
    399   1.7.2.2  nathanw 	if (wd->sc_dk.dk_openmask == 0) {
    400   1.7.2.2  nathanw 	}
    401   1.7.2.2  nathanw 
    402   1.7.2.2  nathanw bad3:
    403   1.7.2.2  nathanw 	ed_unlock(wd);
    404   1.7.2.2  nathanw bad4:
    405   1.7.2.2  nathanw 	return (error);
    406   1.7.2.2  nathanw }
    407   1.7.2.2  nathanw 
    408   1.7.2.2  nathanw int
    409   1.7.2.2  nathanw edmcaclose(dev, flag, fmt, p)
    410   1.7.2.2  nathanw 	dev_t dev;
    411   1.7.2.2  nathanw 	int flag, fmt;
    412   1.7.2.2  nathanw 	struct proc *p;
    413   1.7.2.2  nathanw {
    414   1.7.2.2  nathanw 	struct ed_softc *wd = device_lookup(&ed_cd, DISKUNIT(dev));
    415   1.7.2.2  nathanw 	int part = DISKPART(dev);
    416   1.7.2.2  nathanw 	int error;
    417   1.7.2.3  nathanw 
    418   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edmcaclose\n"), DEBUG_FUNCS);
    419   1.7.2.2  nathanw 	if ((error = ed_lock(wd)) != 0)
    420   1.7.2.2  nathanw 		return error;
    421   1.7.2.2  nathanw 
    422   1.7.2.2  nathanw 	switch (fmt) {
    423   1.7.2.2  nathanw 	case S_IFCHR:
    424   1.7.2.2  nathanw 		wd->sc_dk.dk_copenmask &= ~(1 << part);
    425   1.7.2.2  nathanw 		break;
    426   1.7.2.2  nathanw 	case S_IFBLK:
    427   1.7.2.2  nathanw 		wd->sc_dk.dk_bopenmask &= ~(1 << part);
    428   1.7.2.2  nathanw 		break;
    429   1.7.2.2  nathanw 	}
    430   1.7.2.2  nathanw 	wd->sc_dk.dk_openmask =
    431   1.7.2.2  nathanw 	    wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
    432   1.7.2.2  nathanw 
    433   1.7.2.2  nathanw 	if (wd->sc_dk.dk_openmask == 0) {
    434   1.7.2.2  nathanw #if 0
    435   1.7.2.2  nathanw 		wd_flushcache(wd, AT_WAIT);
    436   1.7.2.2  nathanw #endif
    437   1.7.2.2  nathanw 		/* XXXX Must wait for I/O to complete! */
    438   1.7.2.2  nathanw 
    439   1.7.2.2  nathanw 		if (! (wd->sc_flags & WDF_KLABEL))
    440   1.7.2.2  nathanw 			wd->sc_flags &= ~WDF_LOADED;
    441   1.7.2.2  nathanw 	}
    442   1.7.2.2  nathanw 
    443   1.7.2.2  nathanw 	ed_unlock(wd);
    444   1.7.2.2  nathanw 
    445   1.7.2.2  nathanw 	return 0;
    446   1.7.2.2  nathanw }
    447   1.7.2.2  nathanw 
    448   1.7.2.2  nathanw static void
    449   1.7.2.5  nathanw edgetdefaultlabel(ed, lp)
    450   1.7.2.5  nathanw 	struct ed_softc *ed;
    451   1.7.2.2  nathanw 	struct disklabel *lp;
    452   1.7.2.2  nathanw {
    453   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edgetdefaultlabel\n"), DEBUG_FUNCS);
    454   1.7.2.2  nathanw 	memset(lp, 0, sizeof(struct disklabel));
    455   1.7.2.2  nathanw 
    456   1.7.2.2  nathanw 	lp->d_secsize = DEV_BSIZE;
    457   1.7.2.5  nathanw 	lp->d_ntracks = ed->heads;
    458   1.7.2.5  nathanw 	lp->d_nsectors = ed->sectors;
    459   1.7.2.5  nathanw 	lp->d_ncylinders = ed->cyl;
    460   1.7.2.2  nathanw 	lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
    461   1.7.2.2  nathanw 
    462   1.7.2.2  nathanw 	lp->d_type = DTYPE_ESDI;
    463   1.7.2.2  nathanw 
    464   1.7.2.2  nathanw 	strncpy(lp->d_typename, "ESDI", 16);
    465   1.7.2.2  nathanw 	strncpy(lp->d_packname, "fictitious", 16);
    466   1.7.2.5  nathanw 	lp->d_secperunit = ed->sc_capacity;
    467   1.7.2.2  nathanw 	lp->d_rpm = 3600;
    468   1.7.2.2  nathanw 	lp->d_interleave = 1;
    469   1.7.2.2  nathanw 	lp->d_flags = 0;
    470   1.7.2.2  nathanw 
    471   1.7.2.2  nathanw 	lp->d_partitions[RAW_PART].p_offset = 0;
    472   1.7.2.2  nathanw 	lp->d_partitions[RAW_PART].p_size =
    473   1.7.2.2  nathanw 	lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
    474   1.7.2.2  nathanw 	lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
    475   1.7.2.2  nathanw 	lp->d_npartitions = RAW_PART + 1;
    476   1.7.2.2  nathanw 
    477   1.7.2.2  nathanw 	lp->d_magic = DISKMAGIC;
    478   1.7.2.2  nathanw 	lp->d_magic2 = DISKMAGIC;
    479   1.7.2.2  nathanw 	lp->d_checksum = dkcksum(lp);
    480   1.7.2.2  nathanw }
    481   1.7.2.2  nathanw 
    482   1.7.2.2  nathanw /*
    483   1.7.2.2  nathanw  * Fabricate a default disk label, and try to read the correct one.
    484   1.7.2.2  nathanw  */
    485   1.7.2.2  nathanw static void
    486   1.7.2.5  nathanw edgetdisklabel(dev, ed)
    487   1.7.2.5  nathanw 	dev_t dev;
    488   1.7.2.5  nathanw 	struct ed_softc *ed;
    489   1.7.2.2  nathanw {
    490   1.7.2.5  nathanw 	struct disklabel *lp = ed->sc_dk.dk_label;
    491   1.7.2.2  nathanw 	char *errstring;
    492   1.7.2.2  nathanw 
    493   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edgetdisklabel\n"), DEBUG_FUNCS);
    494   1.7.2.2  nathanw 
    495   1.7.2.5  nathanw 	memset(ed->sc_dk.dk_cpulabel, 0, sizeof(struct cpu_disklabel));
    496   1.7.2.2  nathanw 
    497   1.7.2.5  nathanw 	edgetdefaultlabel(ed, lp);
    498   1.7.2.2  nathanw 
    499   1.7.2.5  nathanw 	errstring = readdisklabel(
    500   1.7.2.5  nathanw 	    EDLABELDEV(dev), edmcastrategy, lp, ed->sc_dk.dk_cpulabel);
    501   1.7.2.2  nathanw 	if (errstring) {
    502   1.7.2.2  nathanw 		/*
    503   1.7.2.2  nathanw 		 * This probably happened because the drive's default
    504   1.7.2.2  nathanw 		 * geometry doesn't match the DOS geometry.  We
    505   1.7.2.2  nathanw 		 * assume the DOS geometry is now in the label and try
    506   1.7.2.2  nathanw 		 * again.  XXX This is a kluge.
    507   1.7.2.2  nathanw 		 */
    508   1.7.2.2  nathanw #if 0
    509   1.7.2.2  nathanw 		if (wd->drvp->state > RECAL)
    510   1.7.2.2  nathanw 			wd->drvp->drive_flags |= DRIVE_RESET;
    511   1.7.2.2  nathanw #endif
    512   1.7.2.5  nathanw 		errstring = readdisklabel(EDLABELDEV(dev),
    513   1.7.2.5  nathanw 			edmcastrategy, lp, ed->sc_dk.dk_cpulabel);
    514   1.7.2.2  nathanw 	}
    515   1.7.2.2  nathanw 	if (errstring) {
    516   1.7.2.5  nathanw 		printf("%s: %s\n", ed->sc_dev.dv_xname, errstring);
    517   1.7.2.2  nathanw 		return;
    518   1.7.2.2  nathanw 	}
    519   1.7.2.2  nathanw }
    520   1.7.2.2  nathanw 
    521   1.7.2.2  nathanw int
    522   1.7.2.2  nathanw edmcaioctl(dev, xfer, addr, flag, p)
    523   1.7.2.2  nathanw 	dev_t dev;
    524   1.7.2.2  nathanw 	u_long xfer;
    525   1.7.2.2  nathanw 	caddr_t addr;
    526   1.7.2.2  nathanw 	int flag;
    527   1.7.2.2  nathanw 	struct proc *p;
    528   1.7.2.2  nathanw {
    529   1.7.2.5  nathanw 	struct ed_softc *ed = device_lookup(&ed_cd, DISKUNIT(dev));
    530   1.7.2.2  nathanw 	int error;
    531   1.7.2.2  nathanw 
    532   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edioctl\n"), DEBUG_FUNCS);
    533   1.7.2.2  nathanw 
    534   1.7.2.5  nathanw 	if ((ed->sc_flags & WDF_LOADED) == 0)
    535   1.7.2.2  nathanw 		return EIO;
    536   1.7.2.2  nathanw 
    537   1.7.2.2  nathanw 	switch (xfer) {
    538   1.7.2.2  nathanw 	case DIOCGDINFO:
    539   1.7.2.5  nathanw 		*(struct disklabel *)addr = *(ed->sc_dk.dk_label);
    540   1.7.2.2  nathanw 		return 0;
    541   1.7.2.2  nathanw 
    542   1.7.2.2  nathanw 	case DIOCGPART:
    543   1.7.2.5  nathanw 		((struct partinfo *)addr)->disklab = ed->sc_dk.dk_label;
    544   1.7.2.2  nathanw 		((struct partinfo *)addr)->part =
    545   1.7.2.5  nathanw 		    &ed->sc_dk.dk_label->d_partitions[DISKPART(dev)];
    546   1.7.2.2  nathanw 		return 0;
    547   1.7.2.3  nathanw 
    548   1.7.2.2  nathanw 	case DIOCWDINFO:
    549   1.7.2.2  nathanw 	case DIOCSDINFO:
    550   1.7.2.2  nathanw 	{
    551   1.7.2.2  nathanw 		struct disklabel *lp;
    552   1.7.2.2  nathanw 
    553   1.7.2.2  nathanw 		lp = (struct disklabel *)addr;
    554   1.7.2.2  nathanw 
    555   1.7.2.2  nathanw 		if ((flag & FWRITE) == 0)
    556   1.7.2.2  nathanw 			return EBADF;
    557   1.7.2.2  nathanw 
    558   1.7.2.5  nathanw 		if ((error = ed_lock(ed)) != 0)
    559   1.7.2.2  nathanw 			return error;
    560   1.7.2.5  nathanw 		ed->sc_flags |= WDF_LABELLING;
    561   1.7.2.2  nathanw 
    562   1.7.2.5  nathanw 		error = setdisklabel(ed->sc_dk.dk_label,
    563   1.7.2.2  nathanw 		    lp, /*wd->sc_dk.dk_openmask : */0,
    564   1.7.2.5  nathanw 		    ed->sc_dk.dk_cpulabel);
    565   1.7.2.2  nathanw 		if (error == 0) {
    566   1.7.2.2  nathanw #if 0
    567   1.7.2.2  nathanw 			if (wd->drvp->state > RECAL)
    568   1.7.2.2  nathanw 				wd->drvp->drive_flags |= DRIVE_RESET;
    569   1.7.2.2  nathanw #endif
    570   1.7.2.5  nathanw 			if (xfer == DIOCWDINFO)
    571   1.7.2.2  nathanw 				error = writedisklabel(EDLABELDEV(dev),
    572   1.7.2.5  nathanw 				    edmcastrategy, ed->sc_dk.dk_label,
    573   1.7.2.5  nathanw 				    ed->sc_dk.dk_cpulabel);
    574   1.7.2.2  nathanw 		}
    575   1.7.2.2  nathanw 
    576   1.7.2.5  nathanw 		ed->sc_flags &= ~WDF_LABELLING;
    577   1.7.2.5  nathanw 		ed_unlock(ed);
    578   1.7.2.5  nathanw 		return (error);
    579   1.7.2.2  nathanw 	}
    580   1.7.2.2  nathanw 
    581   1.7.2.2  nathanw 	case DIOCKLABEL:
    582   1.7.2.2  nathanw 		if (*(int *)addr)
    583   1.7.2.5  nathanw 			ed->sc_flags |= WDF_KLABEL;
    584   1.7.2.2  nathanw 		else
    585   1.7.2.5  nathanw 			ed->sc_flags &= ~WDF_KLABEL;
    586   1.7.2.2  nathanw 		return 0;
    587   1.7.2.3  nathanw 
    588   1.7.2.2  nathanw 	case DIOCWLABEL:
    589   1.7.2.2  nathanw 		if ((flag & FWRITE) == 0)
    590   1.7.2.2  nathanw 			return EBADF;
    591   1.7.2.2  nathanw 		if (*(int *)addr)
    592   1.7.2.5  nathanw 			ed->sc_flags |= WDF_WLABEL;
    593   1.7.2.2  nathanw 		else
    594   1.7.2.5  nathanw 			ed->sc_flags &= ~WDF_WLABEL;
    595   1.7.2.2  nathanw 		return 0;
    596   1.7.2.2  nathanw 
    597   1.7.2.2  nathanw 	case DIOCGDEFLABEL:
    598   1.7.2.5  nathanw 		edgetdefaultlabel(ed, (struct disklabel *)addr);
    599   1.7.2.2  nathanw 		return 0;
    600   1.7.2.2  nathanw 
    601   1.7.2.5  nathanw #if 0
    602   1.7.2.2  nathanw 	case DIOCWFORMAT:
    603   1.7.2.2  nathanw 		if ((flag & FWRITE) == 0)
    604   1.7.2.2  nathanw 			return EBADF;
    605   1.7.2.2  nathanw 		{
    606   1.7.2.2  nathanw 		register struct format_op *fop;
    607   1.7.2.2  nathanw 		struct iovec aiov;
    608   1.7.2.2  nathanw 		struct uio auio;
    609   1.7.2.3  nathanw 
    610   1.7.2.2  nathanw 		fop = (struct format_op *)addr;
    611   1.7.2.2  nathanw 		aiov.iov_base = fop->df_buf;
    612   1.7.2.2  nathanw 		aiov.iov_len = fop->df_count;
    613   1.7.2.2  nathanw 		auio.uio_iov = &aiov;
    614   1.7.2.2  nathanw 		auio.uio_iovcnt = 1;
    615   1.7.2.2  nathanw 		auio.uio_resid = fop->df_count;
    616   1.7.2.2  nathanw 		auio.uio_segflg = 0;
    617   1.7.2.2  nathanw 		auio.uio_offset =
    618   1.7.2.2  nathanw 			fop->df_startblk * wd->sc_dk.dk_label->d_secsize;
    619   1.7.2.2  nathanw 		auio.uio_procp = p;
    620   1.7.2.2  nathanw 		error = physio(wdformat, NULL, dev, B_WRITE, minphys,
    621   1.7.2.2  nathanw 		    &auio);
    622   1.7.2.2  nathanw 		fop->df_count -= auio.uio_resid;
    623   1.7.2.2  nathanw 		fop->df_reg[0] = wdc->sc_status;
    624   1.7.2.2  nathanw 		fop->df_reg[1] = wdc->sc_error;
    625   1.7.2.2  nathanw 		return error;
    626   1.7.2.2  nathanw 		}
    627   1.7.2.2  nathanw #endif
    628   1.7.2.2  nathanw 
    629   1.7.2.2  nathanw 	default:
    630   1.7.2.2  nathanw 		return ENOTTY;
    631   1.7.2.2  nathanw 	}
    632   1.7.2.2  nathanw 
    633   1.7.2.2  nathanw #ifdef DIAGNOSTIC
    634   1.7.2.2  nathanw 	panic("edioctl: impossible");
    635   1.7.2.2  nathanw #endif
    636   1.7.2.2  nathanw }
    637   1.7.2.2  nathanw 
    638   1.7.2.2  nathanw int
    639   1.7.2.2  nathanw edmcasize(dev)
    640   1.7.2.2  nathanw 	dev_t dev;
    641   1.7.2.2  nathanw {
    642   1.7.2.2  nathanw 	struct ed_softc *wd;
    643   1.7.2.2  nathanw 	int part, omask;
    644   1.7.2.2  nathanw 	int size;
    645   1.7.2.2  nathanw 
    646   1.7.2.2  nathanw 	WDCDEBUG_PRINT(("edsize\n"), DEBUG_FUNCS);
    647   1.7.2.2  nathanw 
    648   1.7.2.2  nathanw 	wd = device_lookup(&ed_cd, DISKUNIT(dev));
    649   1.7.2.2  nathanw 	if (wd == NULL)
    650   1.7.2.2  nathanw 		return (-1);
    651   1.7.2.2  nathanw 
    652   1.7.2.2  nathanw 	part = DISKPART(dev);
    653   1.7.2.2  nathanw 	omask = wd->sc_dk.dk_openmask & (1 << part);
    654   1.7.2.2  nathanw 
    655   1.7.2.2  nathanw 	if (omask == 0 && edmcaopen(dev, 0, S_IFBLK, NULL) != 0)
    656   1.7.2.2  nathanw 		return (-1);
    657   1.7.2.2  nathanw 	if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
    658   1.7.2.2  nathanw 		size = -1;
    659   1.7.2.2  nathanw 	else
    660   1.7.2.2  nathanw 		size = wd->sc_dk.dk_label->d_partitions[part].p_size *
    661   1.7.2.2  nathanw 		    (wd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
    662   1.7.2.2  nathanw 	if (omask == 0 && edmcaclose(dev, 0, S_IFBLK, NULL) != 0)
    663   1.7.2.2  nathanw 		return (-1);
    664   1.7.2.2  nathanw 	return (size);
    665   1.7.2.2  nathanw }
    666   1.7.2.2  nathanw 
    667   1.7.2.2  nathanw /* #define WD_DUMP_NOT_TRUSTED if you just want to watch */
    668   1.7.2.2  nathanw static int eddoingadump = 0;
    669   1.7.2.2  nathanw static int eddumprecalibrated = 0;
    670   1.7.2.2  nathanw static int eddumpmulti = 1;
    671   1.7.2.2  nathanw 
    672   1.7.2.2  nathanw /*
    673   1.7.2.2  nathanw  * Dump core after a system crash.
    674   1.7.2.2  nathanw  */
    675   1.7.2.2  nathanw int
    676   1.7.2.2  nathanw edmcadump(dev, blkno, va, size)
    677   1.7.2.2  nathanw 	dev_t dev;
    678   1.7.2.2  nathanw 	daddr_t blkno;
    679   1.7.2.2  nathanw 	caddr_t va;
    680   1.7.2.2  nathanw 	size_t size;
    681   1.7.2.2  nathanw {
    682   1.7.2.2  nathanw 	struct ed_softc *ed;	/* disk unit to do the I/O */
    683   1.7.2.2  nathanw 	struct disklabel *lp;   /* disk's disklabel */
    684   1.7.2.2  nathanw 	int part;
    685   1.7.2.2  nathanw 	int nblks;	/* total number of sectors left to write */
    686   1.7.2.5  nathanw 	int error;
    687   1.7.2.2  nathanw 
    688   1.7.2.2  nathanw 	/* Check if recursive dump; if so, punt. */
    689   1.7.2.2  nathanw 	if (eddoingadump)
    690   1.7.2.2  nathanw 		return EFAULT;
    691   1.7.2.2  nathanw 	eddoingadump = 1;
    692   1.7.2.2  nathanw 
    693   1.7.2.2  nathanw 	ed = device_lookup(&ed_cd, DISKUNIT(dev));
    694   1.7.2.2  nathanw 	if (ed == NULL)
    695   1.7.2.2  nathanw 		return (ENXIO);
    696   1.7.2.2  nathanw 
    697   1.7.2.2  nathanw 	part = DISKPART(dev);
    698   1.7.2.2  nathanw 
    699   1.7.2.2  nathanw 	/* Make sure it was initialized. */
    700   1.7.2.2  nathanw 	if ((ed->sc_flags & EDF_INIT) == 0)
    701   1.7.2.2  nathanw 		return ENXIO;
    702   1.7.2.2  nathanw 
    703   1.7.2.2  nathanw 	/* Convert to disk sectors.  Request must be a multiple of size. */
    704   1.7.2.2  nathanw 	lp = ed->sc_dk.dk_label;
    705   1.7.2.2  nathanw 	if ((size % lp->d_secsize) != 0)
    706   1.7.2.2  nathanw 		return EFAULT;
    707   1.7.2.2  nathanw 	nblks = size / lp->d_secsize;
    708   1.7.2.2  nathanw 	blkno = blkno / (lp->d_secsize / DEV_BSIZE);
    709   1.7.2.2  nathanw 
    710   1.7.2.2  nathanw 	/* Check transfer bounds against partition size. */
    711   1.7.2.2  nathanw 	if ((blkno < 0) || ((blkno + nblks) > lp->d_partitions[part].p_size))
    712   1.7.2.3  nathanw 		return EINVAL;
    713   1.7.2.2  nathanw 
    714   1.7.2.2  nathanw 	/* Offset block number to start of partition. */
    715   1.7.2.2  nathanw 	blkno += lp->d_partitions[part].p_offset;
    716   1.7.2.2  nathanw 
    717   1.7.2.2  nathanw 	/* Recalibrate, if first dump transfer. */
    718   1.7.2.2  nathanw 	if (eddumprecalibrated == 0) {
    719   1.7.2.2  nathanw 		eddumprecalibrated = 1;
    720   1.7.2.2  nathanw 		eddumpmulti = 8;
    721   1.7.2.2  nathanw #if 0
    722   1.7.2.2  nathanw 		wd->drvp->state = RESET;
    723   1.7.2.2  nathanw #endif
    724   1.7.2.2  nathanw 	}
    725   1.7.2.3  nathanw 
    726   1.7.2.2  nathanw 	while (nblks > 0) {
    727   1.7.2.5  nathanw 		error = edc_bio(ed->edc_softc, ed, va, blkno,
    728   1.7.2.5  nathanw 			min(nblks, eddumpmulti) * lp->d_secsize, 0, 1);
    729   1.7.2.5  nathanw 		if (error)
    730   1.7.2.5  nathanw 			return (error);
    731   1.7.2.2  nathanw 
    732   1.7.2.2  nathanw 		/* update block count */
    733   1.7.2.2  nathanw 		nblks -= min(nblks, eddumpmulti);
    734   1.7.2.2  nathanw 		blkno += min(nblks, eddumpmulti);
    735   1.7.2.2  nathanw 		va += min(nblks, eddumpmulti) * lp->d_secsize;
    736   1.7.2.2  nathanw 	}
    737   1.7.2.2  nathanw 
    738   1.7.2.2  nathanw 	eddoingadump = 0;
    739   1.7.2.2  nathanw 	return (0);
    740   1.7.2.2  nathanw }
    741   1.7.2.2  nathanw 
    742   1.7.2.2  nathanw static int
    743   1.7.2.5  nathanw ed_get_params(ed, drv_flags)
    744   1.7.2.2  nathanw 	struct ed_softc *ed;
    745   1.7.2.5  nathanw 	int *drv_flags;
    746   1.7.2.2  nathanw {
    747   1.7.2.2  nathanw 	u_int16_t cmd_args[2];
    748   1.7.2.2  nathanw 
    749   1.7.2.2  nathanw 	/*
    750   1.7.2.2  nathanw 	 * Get Device Configuration (09).
    751   1.7.2.2  nathanw 	 */
    752   1.7.2.2  nathanw 	cmd_args[0] = 14;	/* Options: 00s110, s: 0=Physical 1=Pseudo */
    753   1.7.2.2  nathanw 	cmd_args[1] = 0;
    754   1.7.2.2  nathanw 	if (edc_run_cmd(ed->edc_softc, CMD_GET_DEV_CONF, ed->sc_devno,
    755   1.7.2.5  nathanw 	    cmd_args, 2, 1))
    756   1.7.2.2  nathanw 		return (1);
    757   1.7.2.2  nathanw 
    758   1.7.2.5  nathanw 	ed->spares = ed->sense_data[1] >> 8;
    759   1.7.2.5  nathanw 	if (drv_flags)
    760   1.7.2.5  nathanw 		*drv_flags = ed->sense_data[1] & 0x1f;
    761   1.7.2.5  nathanw 	ed->rba = ed->sense_data[2] | (ed->sense_data[3] << 16);
    762   1.7.2.2  nathanw 	/* Instead of using:
    763   1.7.2.5  nathanw 		ed->cyl = ed->sense_data[4];
    764   1.7.2.5  nathanw 		ed->heads = ed->sense_data[5] & 0xff;
    765   1.7.2.5  nathanw 		ed->sectors = ed->sense_data[5] >> 8;
    766   1.7.2.2  nathanw 	 * we fabricate the numbers from RBA count, so that
    767   1.7.2.2  nathanw 	 * number of sectors is 32 and heads 64. This seems
    768   1.7.2.2  nathanw 	 * to be necessary for integrated ESDI controller.
    769   1.7.2.2  nathanw 	 */
    770   1.7.2.2  nathanw 	ed->sectors = 32;
    771   1.7.2.2  nathanw 	ed->heads = 64;
    772   1.7.2.2  nathanw 	ed->cyl = ed->rba / (ed->heads * ed->sectors);
    773   1.7.2.2  nathanw 	ed->sc_capacity = ed->rba;
    774   1.7.2.2  nathanw 
    775   1.7.2.2  nathanw 	return (0);
    776   1.7.2.2  nathanw }
    777