Home | History | Annotate | Line # | Download | only in dev
rd.c revision 1.15
      1 /*	$NetBSD: rd.c,v 1.15 1995/12/02 18:22:10 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1982, 1990, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  * from: Utah $Hdr: rd.c 1.44 92/12/26$
     41  *
     42  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
     43  */
     44 
     45 /*
     46  * CS80/SS80 disk driver
     47  */
     48 #include "rd.h"
     49 #if NRD > 0
     50 
     51 #include <sys/param.h>
     52 #include <sys/systm.h>
     53 #include <sys/buf.h>
     54 #include <sys/stat.h>
     55 #include <sys/dkstat.h>
     56 #include <sys/disklabel.h>
     57 #include <sys/ioctl.h>
     58 #include <sys/fcntl.h>
     59 
     60 #include <hp300/dev/device.h>
     61 #include <hp300/dev/rdreg.h>
     62 #include <hp300/dev/rdvar.h>
     63 #ifdef USELEDS
     64 #include <hp300/hp300/led.h>
     65 #endif
     66 
     67 #include <vm/vm_param.h>
     68 #include <vm/lock.h>
     69 #include <vm/vm_prot.h>
     70 #include <vm/pmap.h>
     71 
     72 int	rdmatch(), rdstart(), rdgo(), rdintr();
     73 void	rdattach(), rdstrategy();
     74 struct	driver rddriver = {
     75 	rdmatch, rdattach, "rd", rdstart, rdgo, rdintr,
     76 };
     77 
     78 struct	rd_softc rd_softc[NRD];
     79 struct	buf rdtab[NRD];
     80 int	rderrthresh = RDRETRY-1;	/* when to start reporting errors */
     81 
     82 #ifdef DEBUG
     83 /* error message tables */
     84 char *err_reject[] = {
     85 	0, 0,
     86 	"channel parity error",		/* 0x2000 */
     87 	0, 0,
     88 	"illegal opcode",		/* 0x0400 */
     89 	"module addressing",		/* 0x0200 */
     90 	"address bounds",		/* 0x0100 */
     91 	"parameter bounds",		/* 0x0080 */
     92 	"illegal parameter",		/* 0x0040 */
     93 	"message sequence",		/* 0x0020 */
     94 	0,
     95 	"message length",		/* 0x0008 */
     96 	0, 0, 0
     97 };
     98 
     99 char *err_fault[] = {
    100 	0,
    101 	"cross unit",			/* 0x4000 */
    102 	0,
    103 	"controller fault",		/* 0x1000 */
    104 	0, 0,
    105 	"unit fault",			/* 0x0200 */
    106 	0,
    107 	"diagnostic result",		/* 0x0080 */
    108 	0,
    109 	"operator release request",	/* 0x0020 */
    110 	"diagnostic release request",	/* 0x0010 */
    111 	"internal maintenance release request",	/* 0x0008 */
    112 	0,
    113 	"power fail",			/* 0x0002 */
    114 	"retransmit"			/* 0x0001 */
    115 };
    116 
    117 char *err_access[] = {
    118 	"illegal parallel operation",	/* 0x8000 */
    119 	"uninitialized media",		/* 0x4000 */
    120 	"no spares available",		/* 0x2000 */
    121 	"not ready",			/* 0x1000 */
    122 	"write protect",		/* 0x0800 */
    123 	"no data found",		/* 0x0400 */
    124 	0, 0,
    125 	"unrecoverable data overflow",	/* 0x0080 */
    126 	"unrecoverable data",		/* 0x0040 */
    127 	0,
    128 	"end of file",			/* 0x0010 */
    129 	"end of volume",		/* 0x0008 */
    130 	0, 0, 0
    131 };
    132 
    133 char *err_info[] = {
    134 	"operator release request",	/* 0x8000 */
    135 	"diagnostic release request",	/* 0x4000 */
    136 	"internal maintenance release request",	/* 0x2000 */
    137 	"media wear",			/* 0x1000 */
    138 	"latency induced",		/* 0x0800 */
    139 	0, 0,
    140 	"auto sparing invoked",		/* 0x0100 */
    141 	0,
    142 	"recoverable data overflow",	/* 0x0040 */
    143 	"marginal data",		/* 0x0020 */
    144 	"recoverable data",		/* 0x0010 */
    145 	0,
    146 	"maintenance track overflow",	/* 0x0004 */
    147 	0, 0
    148 };
    149 
    150 struct	rdstats rdstats[NRD];
    151 int	rddebug = 0x80;
    152 #define RDB_FOLLOW	0x01
    153 #define RDB_STATUS	0x02
    154 #define RDB_IDENT	0x04
    155 #define RDB_IO		0x08
    156 #define RDB_ASYNC	0x10
    157 #define RDB_ERROR	0x80
    158 #endif
    159 
    160 /*
    161  * Misc. HW description, indexed by sc_type.
    162  * Nothing really critical here, could do without it.
    163  */
    164 struct rdidentinfo rdidentinfo[] = {
    165 	{ RD7946AID,	0,	"7945A",	NRD7945ABPT,
    166 	  NRD7945ATRK,	968,	 108416 },
    167 
    168 	{ RD9134DID,	1,	"9134D",	NRD9134DBPT,
    169 	  NRD9134DTRK,	303,	  29088 },
    170 
    171 	{ RD9134LID,	1,	"9122S",	NRD9122SBPT,
    172 	  NRD9122STRK,	77,	   1232 },
    173 
    174 	{ RD7912PID,	0,	"7912P",	NRD7912PBPT,
    175 	  NRD7912PTRK,	572,	 128128 },
    176 
    177 	{ RD7914PID,	0,	"7914P",	NRD7914PBPT,
    178 	  NRD7914PTRK,	1152,	 258048 },
    179 
    180 	{ RD7958AID,	0,	"7958A",	NRD7958ABPT,
    181 	  NRD7958ATRK,	1013,	 255276 },
    182 
    183 	{ RD7957AID,	0,	"7957A",	NRD7957ABPT,
    184 	  NRD7957ATRK,	1036,	 159544 },
    185 
    186 	{ RD7933HID,	0,	"7933H",	NRD7933HBPT,
    187 	  NRD7933HTRK,	1321,	 789958 },
    188 
    189 	{ RD9134LID,	1,	"9134L",	NRD9134LBPT,
    190 	  NRD9134LTRK,	973,	  77840 },
    191 
    192 	{ RD7936HID,	0,	"7936H",	NRD7936HBPT,
    193 	  NRD7936HTRK,	698,	 600978 },
    194 
    195 	{ RD7937HID,	0,	"7937H",	NRD7937HBPT,
    196 	  NRD7937HTRK,	698,	1116102 },
    197 
    198 	{ RD7914CTID,	0,	"7914CT",	NRD7914PBPT,
    199 	  NRD7914PTRK,	1152,	 258048 },
    200 
    201 	{ RD7946AID,	0,	"7946A",	NRD7945ABPT,
    202 	  NRD7945ATRK,	968,	 108416 },
    203 
    204 	{ RD9134LID,	1,	"9122D",	NRD9122SBPT,
    205 	  NRD9122STRK,	77,	   1232 },
    206 
    207 	{ RD7957BID,	0,	"7957B",	NRD7957BBPT,
    208 	  NRD7957BTRK,	1269,	 159894 },
    209 
    210 	{ RD7958BID,	0,	"7958B",	NRD7958BBPT,
    211 	  NRD7958BTRK,	786,	 297108 },
    212 
    213 	{ RD7959BID,	0,	"7959B",	NRD7959BBPT,
    214 	  NRD7959BTRK,	1572,	 594216 },
    215 
    216 	{ RD2200AID,	0,	"2200A",	NRD2200ABPT,
    217 	  NRD2200ATRK,	1449,	 654948 },
    218 
    219 	{ RD2203AID,	0,	"2203A",	NRD2203ABPT,
    220 	  NRD2203ATRK,	1449,	1309896 }
    221 };
    222 int numrdidentinfo = sizeof(rdidentinfo) / sizeof(rdidentinfo[0]);
    223 
    224 int
    225 rdmatch(hd)
    226 	register struct hp_device *hd;
    227 {
    228 	register struct rd_softc *rs = &rd_softc[hd->hp_unit];
    229 
    230 	rs->sc_hd = hd;
    231 	rs->sc_punit = rdpunit(hd->hp_flags);
    232 	rs->sc_type = rdident(rs, hd, 0);
    233 	if (rs->sc_type < 0)
    234 		return (0);
    235 
    236 	return (1);
    237 }
    238 
    239 void
    240 rdattach(hd)
    241 	register struct hp_device *hd;
    242 {
    243 	register struct rd_softc *rs = &rd_softc[hd->hp_unit];
    244 
    245 	(void)rdident(rs, hd, 1);	/* XXX Ick. */
    246 
    247 	rs->sc_dq.dq_ctlr = hd->hp_ctlr;
    248 	rs->sc_dq.dq_unit = hd->hp_unit;
    249 	rs->sc_dq.dq_slave = hd->hp_slave;
    250 	rs->sc_dq.dq_driver = &rddriver;
    251 	rs->sc_flags = RDF_ALIVE;
    252 #ifdef DEBUG
    253 	/* always report errors */
    254 	if (rddebug & RDB_ERROR)
    255 		rderrthresh = 0;
    256 #endif
    257 }
    258 
    259 int
    260 rdident(rs, hd, verbose)
    261 	struct rd_softc *rs;
    262 	struct hp_device *hd;
    263 	int verbose;
    264 {
    265 	struct rd_describe *desc = &rs->sc_rddesc;
    266 	u_char stat, cmd[3];
    267 	int unit, lunit;
    268 	char name[7];
    269 	register int ctlr, slave, id, i;
    270 
    271 	ctlr = hd->hp_ctlr;
    272 	slave = hd->hp_slave;
    273 	unit = rs->sc_punit;
    274 	lunit = hd->hp_unit;
    275 
    276 	/*
    277 	 * Grab device id and make sure:
    278 	 * 1. It is a CS80 device.
    279 	 * 2. It is one of the types we support.
    280 	 * 3. If it is a 7946, we are accessing the disk unit (0)
    281 	 */
    282 	id = hpibid(ctlr, slave);
    283 #ifdef DEBUG
    284 	if (rddebug & RDB_IDENT)
    285 		printf("hpibid(%d, %d) -> %x\n", ctlr, slave, id);
    286 #endif
    287 	if ((id & 0x200) == 0)
    288 		return(-1);
    289 	for (i = 0; i < numrdidentinfo; i++)
    290 		if (id == rdidentinfo[i].ri_hwid)
    291 			break;
    292 	if (i == numrdidentinfo || unit > rdidentinfo[i].ri_maxunum)
    293 		return(-1);
    294 	id = i;
    295 
    296 	/*
    297 	 * Reset drive and collect device description.
    298 	 * Don't really use the description info right now but
    299 	 * might come in handy in the future (for disk labels).
    300 	 */
    301 	rdreset(rs, hd);
    302 	cmd[0] = C_SUNIT(unit);
    303 	cmd[1] = C_SVOL(0);
    304 	cmd[2] = C_DESC;
    305 	hpibsend(ctlr, slave, C_CMD, cmd, sizeof(cmd));
    306 	hpibrecv(ctlr, slave, C_EXEC, desc, 37);
    307 	hpibrecv(ctlr, slave, C_QSTAT, &stat, sizeof(stat));
    308 	bzero(name, sizeof(name));
    309 	if (!stat) {
    310 		register int n = desc->d_name;
    311 		for (i = 5; i >= 0; i--) {
    312 			name[i] = (n & 0xf) + '0';
    313 			n >>= 4;
    314 		}
    315 		/* use drive characteristics to calculate xfer rate */
    316 		rs->sc_wpms = 1000000 * (desc->d_sectsize/2) /
    317 		    desc->d_blocktime;
    318 	}
    319 #ifdef DEBUG
    320 	if (rddebug & RDB_IDENT) {
    321 		printf("rd%d: name: %x ('%s')\n",
    322 		       lunit, desc->d_name, name);
    323 		printf("  iuw %x, maxxfr %d, ctype %d\n",
    324 		       desc->d_iuw, desc->d_cmaxxfr, desc->d_ctype);
    325 		printf("  utype %d, bps %d, blkbuf %d, burst %d, blktime %d\n",
    326 		       desc->d_utype, desc->d_sectsize,
    327 		       desc->d_blkbuf, desc->d_burstsize, desc->d_blocktime);
    328 		printf("  avxfr %d, ort %d, atp %d, maxint %d, fv %x, rv %x\n",
    329 		       desc->d_uavexfr, desc->d_retry, desc->d_access,
    330 		       desc->d_maxint, desc->d_fvbyte, desc->d_rvbyte);
    331 		printf("  maxcyl/head/sect %d/%d/%d, maxvsect %d, inter %d\n",
    332 		       desc->d_maxcyl, desc->d_maxhead, desc->d_maxsect,
    333 		       desc->d_maxvsectl, desc->d_interleave);
    334 	}
    335 #endif
    336 	/*
    337 	 * Take care of a couple of anomolies:
    338 	 * 1. 7945A and 7946A both return same HW id
    339 	 * 2. 9122S and 9134D both return same HW id
    340 	 * 3. 9122D and 9134L both return same HW id
    341 	 */
    342 	switch (rdidentinfo[id].ri_hwid) {
    343 	case RD7946AID:
    344 		if (bcmp(name, "079450", 6) == 0)
    345 			id = RD7945A;
    346 		else
    347 			id = RD7946A;
    348 		break;
    349 
    350 	case RD9134LID:
    351 		if (bcmp(name, "091340", 6) == 0)
    352 			id = RD9134L;
    353 		else
    354 			id = RD9122D;
    355 		break;
    356 
    357 	case RD9134DID:
    358 		if (bcmp(name, "091220", 6) == 0)
    359 			id = RD9122S;
    360 		else
    361 			id = RD9134D;
    362 		break;
    363 	}
    364 	/*
    365 	 * XXX We use DEV_BSIZE instead of the sector size value pulled
    366 	 * off the driver because all of this code assumes 512 byte
    367 	 * blocks.  ICK!
    368 	 */
    369 	if (verbose) {
    370 		printf(": %s\n", rdidentinfo[id].ri_desc);
    371 		printf("%s: %d cylinders, %d heads, %d blocks, %d bytes/block\n",
    372 		    rs->sc_hd->hp_xname, rdidentinfo[id].ri_ncyl,
    373 		    rdidentinfo[id].ri_ntpc, rdidentinfo[id].ri_nblocks,
    374 		    DEV_BSIZE);
    375 	}
    376 	return(id);
    377 }
    378 
    379 rdreset(rs, hd)
    380 	register struct rd_softc *rs;
    381 	register struct hp_device *hd;
    382 {
    383 	u_char stat;
    384 
    385 	rs->sc_clear.c_unit = C_SUNIT(rs->sc_punit);
    386 	rs->sc_clear.c_cmd = C_CLEAR;
    387 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_TCMD, &rs->sc_clear,
    388 		sizeof(rs->sc_clear));
    389 	hpibswait(hd->hp_ctlr, hd->hp_slave);
    390 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
    391 	rs->sc_src.c_unit = C_SUNIT(RDCTLR);
    392 	rs->sc_src.c_nop = C_NOP;
    393 	rs->sc_src.c_cmd = C_SREL;
    394 	rs->sc_src.c_param = C_REL;
    395 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_src,
    396 		sizeof(rs->sc_src));
    397 	hpibswait(hd->hp_ctlr, hd->hp_slave);
    398 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
    399 	rs->sc_ssmc.c_unit = C_SUNIT(rs->sc_punit);
    400 	rs->sc_ssmc.c_cmd = C_SSM;
    401 	rs->sc_ssmc.c_refm = REF_MASK;
    402 	rs->sc_ssmc.c_fefm = FEF_MASK;
    403 	rs->sc_ssmc.c_aefm = AEF_MASK;
    404 	rs->sc_ssmc.c_iefm = IEF_MASK;
    405 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_ssmc,
    406 		sizeof(rs->sc_ssmc));
    407 	hpibswait(hd->hp_ctlr, hd->hp_slave);
    408 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
    409 #ifdef DEBUG
    410 	rdstats[hd->hp_unit].rdresets++;
    411 #endif
    412 }
    413 
    414 /*
    415  * Read or constuct a disklabel
    416  */
    417 int
    418 rdgetinfo(dev)
    419 	dev_t dev;
    420 {
    421 	int unit = rdunit(dev);
    422 	register struct rd_softc *rs = &rd_softc[unit];
    423 	register struct disklabel *lp = &rs->sc_info.ri_label;
    424 	register struct partition *pi;
    425 	char *msg, *readdisklabel();
    426 
    427 	/*
    428 	 * Set some default values to use while reading the label
    429 	 * or to use if there isn't a label.
    430 	 */
    431 	bzero((caddr_t)lp, sizeof *lp);
    432 	lp->d_type = DTYPE_HPIB;
    433 	lp->d_secsize = DEV_BSIZE;
    434 	lp->d_nsectors = 32;
    435 	lp->d_ntracks = 20;
    436 	lp->d_ncylinders = 1;
    437 	lp->d_secpercyl = 32*20;
    438 	lp->d_npartitions = 3;
    439 	lp->d_partitions[2].p_offset = 0;
    440 	lp->d_partitions[2].p_size = LABELSECTOR+1;
    441 
    442 	/*
    443 	 * Now try to read the disklabel
    444 	 */
    445 	msg = readdisklabel(rdlabdev(dev), rdstrategy, lp);
    446 	if (msg == NULL)
    447 		return(0);
    448 
    449 	pi = lp->d_partitions;
    450 	printf("%s: WARNING: %s, ", rs->sc_hd->hp_xname, msg);
    451 #ifdef COMPAT_NOLABEL
    452 	printf("using old default partitioning\n");
    453 	rdmakedisklabel(unit, lp);
    454 #else
    455 	printf("defining `c' partition as entire disk\n");
    456 	pi[2].p_size = rdidentinfo[rs->sc_type].ri_nblocks;
    457 	/* XXX reset other info since readdisklabel screws with it */
    458 	lp->d_npartitions = 3;
    459 	pi[0].p_size = 0;
    460 #endif
    461 	return(0);
    462 }
    463 
    464 int
    465 rdopen(dev, flags, mode, p)
    466 	dev_t dev;
    467 	int flags, mode;
    468 	struct proc *p;
    469 {
    470 	register int unit = rdunit(dev);
    471 	register struct rd_softc *rs = &rd_softc[unit];
    472 	int error, mask;
    473 
    474 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
    475 		return(ENXIO);
    476 
    477 	/*
    478 	 * Wait for any pending opens/closes to complete
    479 	 */
    480 	while (rs->sc_flags & (RDF_OPENING|RDF_CLOSING))
    481 		sleep((caddr_t)rs, PRIBIO);
    482 
    483 	/*
    484 	 * On first open, get label and partition info.
    485 	 * We may block reading the label, so be careful
    486 	 * to stop any other opens.
    487 	 */
    488 	if (rs->sc_info.ri_open == 0) {
    489 		rs->sc_flags |= RDF_OPENING;
    490 		error = rdgetinfo(dev);
    491 		rs->sc_flags &= ~RDF_OPENING;
    492 		wakeup((caddr_t)rs);
    493 		if (error)
    494 			return(error);
    495 	}
    496 	if (rs->sc_hd->hp_dk >= 0) {
    497 		/* guess at xfer rate based on 3600 rpm (60 rps) */
    498 		if (rs->sc_wpms == 0)
    499 			rs->sc_wpms = 60 * rs->sc_info.ri_label.d_nsectors
    500 				* DEV_BSIZE / 2;
    501 		dk_wpms[rs->sc_hd->hp_dk] = rs->sc_wpms;
    502 	}
    503 
    504 	mask = 1 << rdpart(dev);
    505 	if (mode == S_IFCHR)
    506 		rs->sc_info.ri_copen |= mask;
    507 	else
    508 		rs->sc_info.ri_bopen |= mask;
    509 	rs->sc_info.ri_open |= mask;
    510 	return(0);
    511 }
    512 
    513 int
    514 rdclose(dev, flag, mode, p)
    515 	dev_t dev;
    516 	int flag, mode;
    517 	struct proc *p;
    518 {
    519 	int unit = rdunit(dev);
    520 	register struct rd_softc *rs = &rd_softc[unit];
    521 	register struct rdinfo *ri = &rs->sc_info;
    522 	int mask, s;
    523 
    524 	mask = 1 << rdpart(dev);
    525 	if (mode == S_IFCHR)
    526 		ri->ri_copen &= ~mask;
    527 	else
    528 		ri->ri_bopen &= ~mask;
    529 	ri->ri_open = ri->ri_bopen | ri->ri_copen;
    530 	/*
    531 	 * On last close, we wait for all activity to cease since
    532 	 * the label/parition info will become invalid.  Since we
    533 	 * might sleep, we must block any opens while we are here.
    534 	 * Note we don't have to about other closes since we know
    535 	 * we are the last one.
    536 	 */
    537 	if (ri->ri_open == 0) {
    538 		rs->sc_flags |= RDF_CLOSING;
    539 		s = splbio();
    540 		while (rdtab[unit].b_active) {
    541 			rs->sc_flags |= RDF_WANTED;
    542 			sleep((caddr_t)&rdtab[unit], PRIBIO);
    543 		}
    544 		splx(s);
    545 		rs->sc_flags &= ~(RDF_CLOSING|RDF_WLABEL);
    546 		wakeup((caddr_t)rs);
    547 	}
    548 	return(0);
    549 }
    550 
    551 void
    552 rdstrategy(bp)
    553 	register struct buf *bp;
    554 {
    555 	int unit = rdunit(bp->b_dev);
    556 	register struct rd_softc *rs = &rd_softc[unit];
    557 	register struct buf *dp = &rdtab[unit];
    558 	register struct partition *pinfo;
    559 	register daddr_t bn;
    560 	register int sz, s;
    561 
    562 #ifdef DEBUG
    563 	if (rddebug & RDB_FOLLOW)
    564 		printf("rdstrategy(%x): dev %x, bn %x, bcount %x, %c\n",
    565 		       bp, bp->b_dev, bp->b_blkno, bp->b_bcount,
    566 		       (bp->b_flags & B_READ) ? 'R' : 'W');
    567 #endif
    568 	bn = bp->b_blkno;
    569 	sz = howmany(bp->b_bcount, DEV_BSIZE);
    570 	pinfo = &rs->sc_info.ri_label.d_partitions[rdpart(bp->b_dev)];
    571 	if (bn < 0 || bn + sz > pinfo->p_size) {
    572 		sz = pinfo->p_size - bn;
    573 		if (sz == 0) {
    574 			bp->b_resid = bp->b_bcount;
    575 			goto done;
    576 		}
    577 		if (sz < 0) {
    578 			bp->b_error = EINVAL;
    579 			goto bad;
    580 		}
    581 		bp->b_bcount = dbtob(sz);
    582 	}
    583 	/*
    584 	 * Check for write to write protected label
    585 	 */
    586 	if (bn + pinfo->p_offset <= LABELSECTOR &&
    587 #if LABELSECTOR != 0
    588 	    bn + pinfo->p_offset + sz > LABELSECTOR &&
    589 #endif
    590 	    !(bp->b_flags & B_READ) && !(rs->sc_flags & RDF_WLABEL)) {
    591 		bp->b_error = EROFS;
    592 		goto bad;
    593 	}
    594 	bp->b_cylin = bn + pinfo->p_offset;
    595 	s = splbio();
    596 	disksort(dp, bp);
    597 	if (dp->b_active == 0) {
    598 		dp->b_active = 1;
    599 		rdustart(unit);
    600 	}
    601 	splx(s);
    602 	return;
    603 bad:
    604 	bp->b_flags |= B_ERROR;
    605 done:
    606 	biodone(bp);
    607 }
    608 
    609 /*
    610  * Called from timeout() when handling maintenance releases
    611  */
    612 void
    613 rdrestart(arg)
    614 	void *arg;
    615 {
    616 	int s = splbio();
    617 	rdustart((int)arg);
    618 	splx(s);
    619 }
    620 
    621 rdustart(unit)
    622 	register int unit;
    623 {
    624 	register struct buf *bp;
    625 	register struct rd_softc *rs = &rd_softc[unit];
    626 
    627 	bp = rdtab[unit].b_actf;
    628 	rs->sc_addr = bp->b_un.b_addr;
    629 	rs->sc_resid = bp->b_bcount;
    630 	if (hpibreq(&rs->sc_dq))
    631 		rdstart(unit);
    632 }
    633 
    634 struct buf *
    635 rdfinish(unit, rs, bp)
    636 	int unit;
    637 	register struct rd_softc *rs;
    638 	register struct buf *bp;
    639 {
    640 	register struct buf *dp = &rdtab[unit];
    641 
    642 	dp->b_errcnt = 0;
    643 	dp->b_actf = bp->b_actf;
    644 	bp->b_resid = 0;
    645 	biodone(bp);
    646 	hpibfree(&rs->sc_dq);
    647 	if (dp->b_actf)
    648 		return(dp->b_actf);
    649 	dp->b_active = 0;
    650 	if (rs->sc_flags & RDF_WANTED) {
    651 		rs->sc_flags &= ~RDF_WANTED;
    652 		wakeup((caddr_t)dp);
    653 	}
    654 	return(NULL);
    655 }
    656 
    657 rdstart(unit)
    658 	register int unit;
    659 {
    660 	register struct rd_softc *rs = &rd_softc[unit];
    661 	register struct buf *bp = rdtab[unit].b_actf;
    662 	register struct hp_device *hp = rs->sc_hd;
    663 	register int part;
    664 
    665 again:
    666 #ifdef DEBUG
    667 	if (rddebug & RDB_FOLLOW)
    668 		printf("rdstart(%d): bp %x, %c\n", unit, bp,
    669 		       (bp->b_flags & B_READ) ? 'R' : 'W');
    670 #endif
    671 	part = rdpart(bp->b_dev);
    672 	rs->sc_flags |= RDF_SEEK;
    673 	rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit);
    674 	rs->sc_ioc.c_volume = C_SVOL(0);
    675 	rs->sc_ioc.c_saddr = C_SADDR;
    676 	rs->sc_ioc.c_hiaddr = 0;
    677 	rs->sc_ioc.c_addr = RDBTOS(bp->b_cylin);
    678 	rs->sc_ioc.c_nop2 = C_NOP;
    679 	rs->sc_ioc.c_slen = C_SLEN;
    680 	rs->sc_ioc.c_len = rs->sc_resid;
    681 	rs->sc_ioc.c_cmd = bp->b_flags & B_READ ? C_READ : C_WRITE;
    682 #ifdef DEBUG
    683 	if (rddebug & RDB_IO)
    684 		printf("rdstart: hpibsend(%x, %x, %x, %x, %x)\n",
    685 		       hp->hp_ctlr, hp->hp_slave, C_CMD,
    686 		       &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2);
    687 #endif
    688 	if (hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD, &rs->sc_ioc.c_unit,
    689 		     sizeof(rs->sc_ioc)-2) == sizeof(rs->sc_ioc)-2) {
    690 		if (hp->hp_dk >= 0) {
    691 			dk_busy |= 1 << hp->hp_dk;
    692 			dk_seek[hp->hp_dk]++;
    693 		}
    694 #ifdef DEBUG
    695 		if (rddebug & RDB_IO)
    696 			printf("rdstart: hpibawait(%x)\n", hp->hp_ctlr);
    697 #endif
    698 		hpibawait(hp->hp_ctlr);
    699 		return;
    700 	}
    701 	/*
    702 	 * Experience has shown that the hpibwait in this hpibsend will
    703 	 * occasionally timeout.  It appears to occur mostly on old 7914
    704 	 * drives with full maintenance tracks.  We should probably
    705 	 * integrate this with the backoff code in rderror.
    706 	 */
    707 #ifdef DEBUG
    708 	if (rddebug & RDB_ERROR)
    709 		printf("%s: rdstart: cmd %x adr %d blk %d len %d ecnt %d\n",
    710 		       rs->sc_hd->hp_xname, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr,
    711 		       bp->b_blkno, rs->sc_resid, rdtab[unit].b_errcnt);
    712 	rdstats[unit].rdretries++;
    713 #endif
    714 	rs->sc_flags &= ~RDF_SEEK;
    715 	rdreset(rs, hp);
    716 	if (rdtab[unit].b_errcnt++ < RDRETRY)
    717 		goto again;
    718 	printf("%s: rdstart err: cmd 0x%x sect %d blk %d len %d\n",
    719 	       rs->sc_hd->hp_xname, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr,
    720 	       bp->b_blkno, rs->sc_resid);
    721 	bp->b_flags |= B_ERROR;
    722 	bp->b_error = EIO;
    723 	bp = rdfinish(unit, rs, bp);
    724 	if (bp) {
    725 		rs->sc_addr = bp->b_un.b_addr;
    726 		rs->sc_resid = bp->b_bcount;
    727 		if (hpibreq(&rs->sc_dq))
    728 			goto again;
    729 	}
    730 }
    731 
    732 rdgo(unit)
    733 	register int unit;
    734 {
    735 	register struct rd_softc *rs = &rd_softc[unit];
    736 	register struct hp_device *hp = rs->sc_hd;
    737 	struct buf *bp = rdtab[unit].b_actf;
    738 	int rw;
    739 
    740 	rw = bp->b_flags & B_READ;
    741 
    742 	if (hp->hp_dk >= 0) {
    743 		dk_busy |= 1 << hp->hp_dk;
    744 		dk_xfer[hp->hp_dk]++;
    745 		dk_wds[hp->hp_dk] += rs->sc_resid >> 6;
    746 	}
    747 #ifdef USELEDS
    748 	if (inledcontrol == 0)
    749 		ledcontrol(0, 0, LED_DISK);
    750 #endif
    751 	hpibgo(hp->hp_ctlr, hp->hp_slave, C_EXEC,
    752 	       rs->sc_addr, rs->sc_resid, rw, rw != 0);
    753 }
    754 
    755 rdintr(unit)
    756 	register int unit;
    757 {
    758 	register struct rd_softc *rs = &rd_softc[unit];
    759 	register struct buf *bp = rdtab[unit].b_actf;
    760 	register struct hp_device *hp = rs->sc_hd;
    761 	u_char stat = 13;	/* in case hpibrecv fails */
    762 	int rv, restart;
    763 
    764 #ifdef DEBUG
    765 	if (rddebug & RDB_FOLLOW)
    766 		printf("rdintr(%d): bp %x, %c, flags %x\n", unit, bp,
    767 		       (bp->b_flags & B_READ) ? 'R' : 'W', rs->sc_flags);
    768 	if (bp == NULL) {
    769 		printf("%s: bp == NULL\n", rs->sc_hd->hp_xname);
    770 		return;
    771 	}
    772 #endif
    773 	if (hp->hp_dk >= 0)
    774 		dk_busy &= ~(1 << hp->hp_dk);
    775 	if (rs->sc_flags & RDF_SEEK) {
    776 		rs->sc_flags &= ~RDF_SEEK;
    777 		if (hpibustart(hp->hp_ctlr))
    778 			rdgo(unit);
    779 		return;
    780 	}
    781 	if ((rs->sc_flags & RDF_SWAIT) == 0) {
    782 #ifdef DEBUG
    783 		rdstats[unit].rdpolltries++;
    784 #endif
    785 		if (hpibpptest(hp->hp_ctlr, hp->hp_slave) == 0) {
    786 #ifdef DEBUG
    787 			rdstats[unit].rdpollwaits++;
    788 #endif
    789 			if (hp->hp_dk >= 0)
    790 				dk_busy |= 1 << hp->hp_dk;
    791 			rs->sc_flags |= RDF_SWAIT;
    792 			hpibawait(hp->hp_ctlr);
    793 			return;
    794 		}
    795 	} else
    796 		rs->sc_flags &= ~RDF_SWAIT;
    797 	rv = hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1);
    798 	if (rv != 1 || stat) {
    799 #ifdef DEBUG
    800 		if (rddebug & RDB_ERROR)
    801 			printf("rdintr: recv failed or bad stat %d\n", stat);
    802 #endif
    803 		restart = rderror(unit);
    804 #ifdef DEBUG
    805 		rdstats[unit].rdretries++;
    806 #endif
    807 		if (rdtab[unit].b_errcnt++ < RDRETRY) {
    808 			if (restart)
    809 				rdstart(unit);
    810 			return;
    811 		}
    812 		bp->b_flags |= B_ERROR;
    813 		bp->b_error = EIO;
    814 	}
    815 	if (rdfinish(unit, rs, bp))
    816 		rdustart(unit);
    817 }
    818 
    819 rdstatus(rs)
    820 	register struct rd_softc *rs;
    821 {
    822 	register int c, s;
    823 	u_char stat;
    824 	int rv;
    825 
    826 	c = rs->sc_hd->hp_ctlr;
    827 	s = rs->sc_hd->hp_slave;
    828 	rs->sc_rsc.c_unit = C_SUNIT(rs->sc_punit);
    829 	rs->sc_rsc.c_sram = C_SRAM;
    830 	rs->sc_rsc.c_ram = C_RAM;
    831 	rs->sc_rsc.c_cmd = C_STATUS;
    832 	bzero((caddr_t)&rs->sc_stat, sizeof(rs->sc_stat));
    833 	rv = hpibsend(c, s, C_CMD, &rs->sc_rsc, sizeof(rs->sc_rsc));
    834 	if (rv != sizeof(rs->sc_rsc)) {
    835 #ifdef DEBUG
    836 		if (rddebug & RDB_STATUS)
    837 			printf("rdstatus: send C_CMD failed %d != %d\n",
    838 			       rv, sizeof(rs->sc_rsc));
    839 #endif
    840 		return(1);
    841 	}
    842 	rv = hpibrecv(c, s, C_EXEC, &rs->sc_stat, sizeof(rs->sc_stat));
    843 	if (rv != sizeof(rs->sc_stat)) {
    844 #ifdef DEBUG
    845 		if (rddebug & RDB_STATUS)
    846 			printf("rdstatus: send C_EXEC failed %d != %d\n",
    847 			       rv, sizeof(rs->sc_stat));
    848 #endif
    849 		return(1);
    850 	}
    851 	rv = hpibrecv(c, s, C_QSTAT, &stat, 1);
    852 	if (rv != 1 || stat) {
    853 #ifdef DEBUG
    854 		if (rddebug & RDB_STATUS)
    855 			printf("rdstatus: recv failed %d or bad stat %d\n",
    856 			       rv, stat);
    857 #endif
    858 		return(1);
    859 	}
    860 	return(0);
    861 }
    862 
    863 /*
    864  * Deal with errors.
    865  * Returns 1 if request should be restarted,
    866  * 0 if we should just quietly give up.
    867  */
    868 rderror(unit)
    869 	int unit;
    870 {
    871 	struct rd_softc *rs = &rd_softc[unit];
    872 	register struct rd_stat *sp;
    873 	struct buf *bp;
    874 	daddr_t hwbn, pbn;
    875 
    876 	if (rdstatus(rs)) {
    877 #ifdef DEBUG
    878 		printf("%s: couldn't get status\n", rs->sc_hd->hp_xname);
    879 #endif
    880 		rdreset(rs, rs->sc_hd);
    881 		return(1);
    882 	}
    883 	sp = &rs->sc_stat;
    884 	if (sp->c_fef & FEF_REXMT)
    885 		return(1);
    886 	if (sp->c_fef & FEF_PF) {
    887 		rdreset(rs, rs->sc_hd);
    888 		return(1);
    889 	}
    890 	/*
    891 	 * Unit requests release for internal maintenance.
    892 	 * We just delay awhile and try again later.  Use expontially
    893 	 * increasing backoff ala ethernet drivers since we don't really
    894 	 * know how long the maintenance will take.  With RDWAITC and
    895 	 * RDRETRY as defined, the range is 1 to 32 seconds.
    896 	 */
    897 	if (sp->c_fef & FEF_IMR) {
    898 		extern int hz;
    899 		int rdtimo = RDWAITC << rdtab[unit].b_errcnt;
    900 #ifdef DEBUG
    901 		printf("%s: internal maintenance, %d second timeout\n",
    902 		       rs->sc_hd->hp_xname, rdtimo);
    903 		rdstats[unit].rdtimeouts++;
    904 #endif
    905 		hpibfree(&rs->sc_dq);
    906 		timeout(rdrestart, (void *)unit, rdtimo * hz);
    907 		return(0);
    908 	}
    909 	/*
    910 	 * Only report error if we have reached the error reporting
    911 	 * threshhold.  By default, this will only report after the
    912 	 * retry limit has been exceeded.
    913 	 */
    914 	if (rdtab[unit].b_errcnt < rderrthresh)
    915 		return(1);
    916 
    917 	/*
    918 	 * First conjure up the block number at which the error occured.
    919 	 * Note that not all errors report a block number, in that case
    920 	 * we just use b_blkno.
    921  	 */
    922 	bp = rdtab[unit].b_actf;
    923 	pbn = rs->sc_info.ri_label.d_partitions[rdpart(bp->b_dev)].p_offset;
    924 	if ((sp->c_fef & FEF_CU) || (sp->c_fef & FEF_DR) ||
    925 	    (sp->c_ief & IEF_RRMASK)) {
    926 		hwbn = RDBTOS(pbn + bp->b_blkno);
    927 		pbn = bp->b_blkno;
    928 	} else {
    929 		hwbn = sp->c_blk;
    930 		pbn = RDSTOB(hwbn) - pbn;
    931 	}
    932 	/*
    933 	 * Now output a generic message suitable for badsect.
    934 	 * Note that we don't use harderr cuz it just prints
    935 	 * out b_blkno which is just the beginning block number
    936 	 * of the transfer, not necessary where the error occured.
    937 	 */
    938 	printf("rd%d%c: hard error sn%d\n",
    939 	       rdunit(bp->b_dev), 'a'+rdpart(bp->b_dev), pbn);
    940 	/*
    941 	 * Now report the status as returned by the hardware with
    942 	 * attempt at interpretation (unless debugging).
    943 	 */
    944 	printf("rd%d %s error:",
    945 	       unit, (bp->b_flags & B_READ) ? "read" : "write");
    946 #ifdef DEBUG
    947 	if (rddebug & RDB_ERROR) {
    948 		/* status info */
    949 		printf("\n    volume: %d, unit: %d\n",
    950 		       (sp->c_vu>>4)&0xF, sp->c_vu&0xF);
    951 		rdprinterr("reject", sp->c_ref, err_reject);
    952 		rdprinterr("fault", sp->c_fef, err_fault);
    953 		rdprinterr("access", sp->c_aef, err_access);
    954 		rdprinterr("info", sp->c_ief, err_info);
    955 		printf("    block: %d, P1-P10: ", hwbn);
    956 		printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8));
    957 		printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8));
    958 		printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4));
    959 		/* command */
    960 		printf("    ioc: ");
    961 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_pad, 8));
    962 		printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_hiaddr, 4));
    963 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_addr, 8));
    964 		printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_nop2, 4));
    965 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_len, 8));
    966 		printf("%s\n", hexstr(*(u_short *)&rs->sc_ioc.c_cmd, 4));
    967 		return(1);
    968 	}
    969 #endif
    970 	printf(" v%d u%d, R0x%x F0x%x A0x%x I0x%x\n",
    971 	       (sp->c_vu>>4)&0xF, sp->c_vu&0xF,
    972 	       sp->c_ref, sp->c_fef, sp->c_aef, sp->c_ief);
    973 	printf("P1-P10: ");
    974 	printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8));
    975 	printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8));
    976 	printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4));
    977 	return(1);
    978 }
    979 
    980 int
    981 rdread(dev, uio, flags)
    982 	dev_t dev;
    983 	struct uio *uio;
    984 	int flags;
    985 {
    986 
    987 	return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
    988 }
    989 
    990 int
    991 rdwrite(dev, uio, flags)
    992 	dev_t dev;
    993 	struct uio *uio;
    994 	int flags;
    995 {
    996 
    997 	return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
    998 }
    999 
   1000 int
   1001 rdioctl(dev, cmd, data, flag, p)
   1002 	dev_t dev;
   1003 	int cmd;
   1004 	caddr_t data;
   1005 	int flag;
   1006 	struct proc *p;
   1007 {
   1008 	int unit = rdunit(dev);
   1009 	register struct rd_softc *sc = &rd_softc[unit];
   1010 	register struct disklabel *lp = &sc->sc_info.ri_label;
   1011 	int error, flags;
   1012 
   1013 	switch (cmd) {
   1014 	case DIOCGDINFO:
   1015 		*(struct disklabel *)data = *lp;
   1016 		return (0);
   1017 
   1018 	case DIOCGPART:
   1019 		((struct partinfo *)data)->disklab = lp;
   1020 		((struct partinfo *)data)->part =
   1021 			&lp->d_partitions[rdpart(dev)];
   1022 		return (0);
   1023 
   1024 	case DIOCWLABEL:
   1025 		if ((flag & FWRITE) == 0)
   1026 			return (EBADF);
   1027 		if (*(int *)data)
   1028 			sc->sc_flags |= RDF_WLABEL;
   1029 		else
   1030 			sc->sc_flags &= ~RDF_WLABEL;
   1031 		return (0);
   1032 
   1033 	case DIOCSDINFO:
   1034 		if ((flag & FWRITE) == 0)
   1035 			return (EBADF);
   1036 		return (setdisklabel(lp, (struct disklabel *)data,
   1037 				     (sc->sc_flags & RDF_WLABEL) ? 0
   1038 				     : sc->sc_info.ri_open,
   1039 				     (struct cpu_disklabel *)0));
   1040 
   1041 	case DIOCWDINFO:
   1042 		if ((flag & FWRITE) == 0)
   1043 			return (EBADF);
   1044 		error = setdisklabel(lp, (struct disklabel *)data,
   1045 				     (sc->sc_flags & RDF_WLABEL) ? 0
   1046 				     : sc->sc_info.ri_open,
   1047 				     (struct cpu_disklabel *)0);
   1048 		if (error)
   1049 			return (error);
   1050 		flags = sc->sc_flags;
   1051 		sc->sc_flags = RDF_ALIVE | RDF_WLABEL;
   1052 		error = writedisklabel(rdlabdev(dev), rdstrategy, lp,
   1053 				       (struct cpu_disklabel *)0);
   1054 		sc->sc_flags = flags;
   1055 		return (error);
   1056 	}
   1057 	return(EINVAL);
   1058 }
   1059 
   1060 int
   1061 rdsize(dev)
   1062 	dev_t dev;
   1063 {
   1064 	register int unit = rdunit(dev);
   1065 	register struct rd_softc *rs = &rd_softc[unit];
   1066 	int psize, didopen = 0;
   1067 
   1068 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
   1069 		return(-1);
   1070 
   1071 	/*
   1072 	 * We get called very early on (via swapconf)
   1073 	 * without the device being open so we may need
   1074 	 * to handle it here.
   1075 	 */
   1076 	if (rs->sc_info.ri_open == 0) {
   1077 		if (rdopen(dev, FREAD|FWRITE, S_IFBLK, NULL))
   1078 			return(-1);
   1079 		didopen = 1;
   1080 	}
   1081 	psize = rs->sc_info.ri_label.d_partitions[rdpart(dev)].p_size;
   1082 	if (didopen)
   1083 		(void) rdclose(dev, FREAD|FWRITE, S_IFBLK, NULL);
   1084 	return (psize);
   1085 }
   1086 
   1087 #ifdef DEBUG
   1088 rdprinterr(str, err, tab)
   1089 	char *str;
   1090 	short err;
   1091 	char *tab[];
   1092 {
   1093 	register int i;
   1094 	int printed;
   1095 
   1096 	if (err == 0)
   1097 		return;
   1098 	printf("    %s error field:", str, err);
   1099 	printed = 0;
   1100 	for (i = 0; i < 16; i++)
   1101 		if (err & (0x8000 >> i))
   1102 			printf("%s%s", printed++ ? " + " : " ", tab[i]);
   1103 	printf("\n");
   1104 }
   1105 #endif
   1106 
   1107 /*
   1108  * Non-interrupt driven, non-dma dump routine.
   1109  */
   1110 int
   1111 rddump(dev)
   1112 	dev_t dev;
   1113 {
   1114 	int part = rdpart(dev);
   1115 	int unit = rdunit(dev);
   1116 	register struct rd_softc *rs = &rd_softc[unit];
   1117 	register struct hp_device *hp = rs->sc_hd;
   1118 	register struct partition *pinfo;
   1119 	register daddr_t baddr;
   1120 	register int maddr, pages, i;
   1121 	char stat;
   1122 	extern int lowram, dumpsize;
   1123 #ifdef DEBUG
   1124 	extern int pmapdebug;
   1125 	pmapdebug = 0;
   1126 #endif
   1127 
   1128 	/* is drive ok? */
   1129 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
   1130 		return (ENXIO);
   1131 	pinfo = &rs->sc_info.ri_label.d_partitions[part];
   1132 	/* dump parameters in range? */
   1133 	if (dumplo < 0 || dumplo >= pinfo->p_size ||
   1134 	    pinfo->p_fstype != FS_SWAP)
   1135 		return (EINVAL);
   1136 	pages = dumpsize;
   1137 	if (dumplo + ctod(pages) > pinfo->p_size)
   1138 		pages = dtoc(pinfo->p_size - dumplo);
   1139 	maddr = lowram;
   1140 	baddr = dumplo + pinfo->p_offset;
   1141 	/* HPIB idle? */
   1142 	if (!hpibreq(&rs->sc_dq)) {
   1143 		hpibreset(hp->hp_ctlr);
   1144 		rdreset(rs, rs->sc_hd);
   1145 		printf("[ drive %d reset ] ", unit);
   1146 	}
   1147 	for (i = 0; i < pages; i++) {
   1148 #define NPGMB	(1024*1024/NBPG)
   1149 		/* print out how many Mbs we have dumped */
   1150 		if (i && (i % NPGMB) == 0)
   1151 			printf("%d ", i / NPGMB);
   1152 #undef NPBMG
   1153 		rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit);
   1154 		rs->sc_ioc.c_volume = C_SVOL(0);
   1155 		rs->sc_ioc.c_saddr = C_SADDR;
   1156 		rs->sc_ioc.c_hiaddr = 0;
   1157 		rs->sc_ioc.c_addr = RDBTOS(baddr);
   1158 		rs->sc_ioc.c_nop2 = C_NOP;
   1159 		rs->sc_ioc.c_slen = C_SLEN;
   1160 		rs->sc_ioc.c_len = NBPG;
   1161 		rs->sc_ioc.c_cmd = C_WRITE;
   1162 		hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD,
   1163 			 &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2);
   1164 		if (hpibswait(hp->hp_ctlr, hp->hp_slave))
   1165 			return (EIO);
   1166 		pmap_enter(pmap_kernel(), (vm_offset_t)vmmap, maddr,
   1167 		    VM_PROT_READ, TRUE);
   1168 		hpibsend(hp->hp_ctlr, hp->hp_slave, C_EXEC, vmmap, NBPG);
   1169 		(void) hpibswait(hp->hp_ctlr, hp->hp_slave);
   1170 		hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1);
   1171 		if (stat)
   1172 			return (EIO);
   1173 		maddr += NBPG;
   1174 		baddr += ctod(1);
   1175 	}
   1176 	return (0);
   1177 }
   1178 #endif
   1179