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