Home | History | Annotate | Line # | Download | only in gpib
rd.c revision 1.1.2.1
      1  1.1.2.1     skrll /*	$NetBSD: rd.c,v 1.1.2.1 2004/08/03 10:45:57 skrll Exp $ */
      2      1.1  gmcgarry 
      3      1.1  gmcgarry /*-
      4      1.1  gmcgarry  * Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
      5      1.1  gmcgarry  * All rights reserved.
      6      1.1  gmcgarry  *
      7      1.1  gmcgarry  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  gmcgarry  * by Jason R. Thorpe.
      9      1.1  gmcgarry  *
     10      1.1  gmcgarry  * Redistribution and use in source and binary forms, with or without
     11      1.1  gmcgarry  * modification, are permitted provided that the following conditions
     12      1.1  gmcgarry  * are met:
     13      1.1  gmcgarry  * 1. Redistributions of source code must retain the above copyright
     14      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer.
     15      1.1  gmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  gmcgarry  *    documentation and/or other materials provided with the distribution.
     18      1.1  gmcgarry  * 3. All advertising materials mentioning features or use of this software
     19      1.1  gmcgarry  *    must display the following acknowledgement:
     20      1.1  gmcgarry  *	This product includes software developed by the NetBSD
     21      1.1  gmcgarry  *	Foundation, Inc. and its contributors.
     22      1.1  gmcgarry  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  gmcgarry  *    contributors may be used to endorse or promote products derived
     24      1.1  gmcgarry  *    from this software without specific prior written permission.
     25      1.1  gmcgarry  *
     26      1.1  gmcgarry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  gmcgarry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  gmcgarry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  gmcgarry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  gmcgarry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  gmcgarry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  gmcgarry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  gmcgarry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  gmcgarry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  gmcgarry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  gmcgarry  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  gmcgarry  */
     38      1.1  gmcgarry 
     39      1.1  gmcgarry /*
     40      1.1  gmcgarry  * Copyright (c) 1982, 1990, 1993
     41      1.1  gmcgarry  *	The Regents of the University of California.  All rights reserved.
     42      1.1  gmcgarry  *
     43      1.1  gmcgarry  * This code is derived from software contributed to Berkeley by
     44      1.1  gmcgarry  * the Systems Programming Group of the University of Utah Computer
     45      1.1  gmcgarry  * Science Department.
     46      1.1  gmcgarry  *
     47      1.1  gmcgarry  * Redistribution and use in source and binary forms, with or without
     48      1.1  gmcgarry  * modification, are permitted provided that the following conditions
     49      1.1  gmcgarry  * are met:
     50      1.1  gmcgarry  * 1. Redistributions of source code must retain the above copyright
     51      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer.
     52      1.1  gmcgarry  * 2. Redistributions in binary form must reproduce the above copyright
     53      1.1  gmcgarry  *    notice, this list of conditions and the following disclaimer in the
     54      1.1  gmcgarry  *    documentation and/or other materials provided with the distribution.
     55  1.1.2.1     skrll  * 3. Neither the name of the University nor the names of its contributors
     56  1.1.2.1     skrll  *    may be used to endorse or promote products derived from this software
     57  1.1.2.1     skrll  *    without specific prior written permission.
     58  1.1.2.1     skrll  *
     59  1.1.2.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1.2.1     skrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1.2.1     skrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1.2.1     skrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1.2.1     skrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1.2.1     skrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1.2.1     skrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1.2.1     skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1.2.1     skrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1.2.1     skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1.2.1     skrll  * SUCH DAMAGE.
     70  1.1.2.1     skrll  *
     71  1.1.2.1     skrll  * from: Utah $Hdr: rd.c 1.44 92/12/26$
     72  1.1.2.1     skrll  *
     73  1.1.2.1     skrll  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
     74  1.1.2.1     skrll  */
     75  1.1.2.1     skrll 
     76  1.1.2.1     skrll /*
     77  1.1.2.1     skrll  * Copyright (c) 1988 University of Utah.
     78  1.1.2.1     skrll  *
     79  1.1.2.1     skrll  * This code is derived from software contributed to Berkeley by
     80  1.1.2.1     skrll  * the Systems Programming Group of the University of Utah Computer
     81  1.1.2.1     skrll  * Science Department.
     82  1.1.2.1     skrll  *
     83  1.1.2.1     skrll  * Redistribution and use in source and binary forms, with or without
     84  1.1.2.1     skrll  * modification, are permitted provided that the following conditions
     85  1.1.2.1     skrll  * are met:
     86  1.1.2.1     skrll  * 1. Redistributions of source code must retain the above copyright
     87  1.1.2.1     skrll  *    notice, this list of conditions and the following disclaimer.
     88  1.1.2.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     89  1.1.2.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     90  1.1.2.1     skrll  *    documentation and/or other materials provided with the distribution.
     91      1.1  gmcgarry  * 3. All advertising materials mentioning features or use of this software
     92      1.1  gmcgarry  *    must display the following acknowledgement:
     93      1.1  gmcgarry  *	This product includes software developed by the University of
     94      1.1  gmcgarry  *	California, Berkeley and its contributors.
     95      1.1  gmcgarry  * 4. Neither the name of the University nor the names of its contributors
     96      1.1  gmcgarry  *    may be used to endorse or promote products derived from this software
     97      1.1  gmcgarry  *    without specific prior written permission.
     98      1.1  gmcgarry  *
     99      1.1  gmcgarry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    100      1.1  gmcgarry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    101      1.1  gmcgarry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    102      1.1  gmcgarry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    103      1.1  gmcgarry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    104      1.1  gmcgarry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    105      1.1  gmcgarry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    106      1.1  gmcgarry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    107      1.1  gmcgarry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    108      1.1  gmcgarry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    109      1.1  gmcgarry  * SUCH DAMAGE.
    110      1.1  gmcgarry  *
    111      1.1  gmcgarry  * from: Utah $Hdr: rd.c 1.44 92/12/26$
    112      1.1  gmcgarry  *
    113      1.1  gmcgarry  *	@(#)rd.c	8.2 (Berkeley) 5/19/94
    114      1.1  gmcgarry  */
    115      1.1  gmcgarry 
    116      1.1  gmcgarry /*
    117      1.1  gmcgarry  * CS80/SS80 disk driver
    118      1.1  gmcgarry  */
    119      1.1  gmcgarry 
    120      1.1  gmcgarry #include <sys/cdefs.h>
    121  1.1.2.1     skrll __KERNEL_RCSID(0, "$NetBSD: rd.c,v 1.1.2.1 2004/08/03 10:45:57 skrll Exp $");
    122      1.1  gmcgarry 
    123      1.1  gmcgarry #include "rnd.h"
    124      1.1  gmcgarry 
    125      1.1  gmcgarry #include <sys/param.h>
    126      1.1  gmcgarry #include <sys/systm.h>
    127      1.1  gmcgarry #include <sys/buf.h>
    128      1.1  gmcgarry #include <sys/callout.h>
    129      1.1  gmcgarry #include <sys/conf.h>
    130      1.1  gmcgarry #include <sys/device.h>
    131      1.1  gmcgarry #include <sys/disk.h>
    132      1.1  gmcgarry #include <sys/disklabel.h>
    133      1.1  gmcgarry #include <sys/endian.h>
    134      1.1  gmcgarry #include <sys/fcntl.h>
    135      1.1  gmcgarry #include <sys/ioctl.h>
    136      1.1  gmcgarry #include <sys/proc.h>
    137      1.1  gmcgarry #include <sys/stat.h>
    138      1.1  gmcgarry 
    139      1.1  gmcgarry #if NRND > 0
    140      1.1  gmcgarry #include <sys/rnd.h>
    141      1.1  gmcgarry #endif
    142      1.1  gmcgarry 
    143      1.1  gmcgarry #include <dev/gpib/gpibvar.h>
    144      1.1  gmcgarry #include <dev/gpib/cs80busvar.h>
    145      1.1  gmcgarry 
    146      1.1  gmcgarry #include <dev/gpib/rdreg.h>
    147      1.1  gmcgarry 
    148      1.1  gmcgarry #ifdef DEBUG
    149      1.1  gmcgarry int	rddebug = 0xff;
    150      1.1  gmcgarry #define RDB_FOLLOW	0x01
    151      1.1  gmcgarry #define RDB_STATUS	0x02
    152      1.1  gmcgarry #define RDB_IDENT	0x04
    153      1.1  gmcgarry #define RDB_IO		0x08
    154      1.1  gmcgarry #define RDB_ASYNC	0x10
    155      1.1  gmcgarry #define RDB_ERROR	0x80
    156      1.1  gmcgarry #define DPRINTF(mask, str)	if (rddebug & (mask)) printf str
    157      1.1  gmcgarry #else
    158      1.1  gmcgarry #define DPRINTF(mask, str)	/* nothing */
    159      1.1  gmcgarry #endif
    160      1.1  gmcgarry 
    161      1.1  gmcgarry struct	rd_softc {
    162      1.1  gmcgarry 	struct	device sc_dev;
    163      1.1  gmcgarry 	gpib_chipset_tag_t sc_ic;
    164      1.1  gmcgarry 	gpib_handle_t sc_hdl;
    165      1.1  gmcgarry 
    166      1.1  gmcgarry 	struct	disk sc_dk;
    167      1.1  gmcgarry 
    168      1.1  gmcgarry 	int	sc_slave;		/* GPIB slave */
    169      1.1  gmcgarry 	int	sc_punit;		/* physical unit on slave */
    170      1.1  gmcgarry 
    171      1.1  gmcgarry 	int	sc_flags;
    172      1.1  gmcgarry #define	RDF_ALIVE	0x01
    173      1.1  gmcgarry #define	RDF_SEEK	0x02
    174      1.1  gmcgarry #define RDF_SWAIT	0x04
    175      1.1  gmcgarry #define RDF_OPENING	0x08
    176      1.1  gmcgarry #define RDF_CLOSING	0x10
    177      1.1  gmcgarry #define RDF_WANTED	0x20
    178      1.1  gmcgarry #define RDF_WLABEL	0x40
    179      1.1  gmcgarry 
    180      1.1  gmcgarry 	u_int16_t sc_type;
    181      1.1  gmcgarry 	u_int8_t *sc_addr;
    182      1.1  gmcgarry 	int	sc_resid;
    183      1.1  gmcgarry 	struct	rd_iocmd sc_ioc;
    184      1.1  gmcgarry 	struct	bufq_state sc_tab;
    185      1.1  gmcgarry 	int	sc_active;
    186      1.1  gmcgarry 	int	sc_errcnt;
    187      1.1  gmcgarry 
    188      1.1  gmcgarry 	struct	callout sc_restart_ch;
    189      1.1  gmcgarry 
    190      1.1  gmcgarry #if NRND > 0
    191      1.1  gmcgarry 	rndsource_element_t rnd_source;
    192      1.1  gmcgarry #endif
    193      1.1  gmcgarry };
    194      1.1  gmcgarry 
    195      1.1  gmcgarry #define RDUNIT(dev)			DISKUNIT(dev)
    196      1.1  gmcgarry #define RDPART(dev)			DISKPART(dev)
    197      1.1  gmcgarry #define RDMAKEDEV(maj, unit, part)	MAKEDISKDEV(maj, unit, part)
    198      1.1  gmcgarry #define RDLABELDEV(dev)	(RDMAKEDEV(major(dev), RDUNIT(dev), RAW_PART))
    199      1.1  gmcgarry 
    200      1.1  gmcgarry #define	RDRETRY		5
    201      1.1  gmcgarry #define RDWAITC		1	/* min time for timeout in seconds */
    202      1.1  gmcgarry 
    203      1.1  gmcgarry int	rderrthresh = RDRETRY-1;	/* when to start reporting errors */
    204      1.1  gmcgarry 
    205      1.1  gmcgarry /*
    206      1.1  gmcgarry  * Misc. HW description, indexed by sc_type.
    207      1.1  gmcgarry  * Used for mapping 256-byte sectors for 512-byte sectors
    208      1.1  gmcgarry  */
    209      1.1  gmcgarry const struct rdidentinfo {
    210      1.1  gmcgarry 	u_int16_t ri_hwid;		/* 2 byte HW id */
    211      1.1  gmcgarry 	u_int16_t ri_maxunum;		/* maximum allowed unit number */
    212      1.1  gmcgarry 	char	*ri_desc;		/* drive type description */
    213      1.1  gmcgarry 	int	ri_nbpt;		/* DEV_BSIZE blocks per track */
    214      1.1  gmcgarry 	int	ri_ntpc;		/* tracks per cylinder */
    215      1.1  gmcgarry 	int	ri_ncyl;		/* cylinders per unit */
    216      1.1  gmcgarry 	int	ri_nblocks;		/* DEV_BSIZE blocks on disk */
    217      1.1  gmcgarry } rdidentinfo[] = {
    218      1.1  gmcgarry 	{ RD7946AID,	0,	"7945A",	NRD7945ABPT,
    219      1.1  gmcgarry 	  NRD7945ATRK,	968,	 108416 },
    220      1.1  gmcgarry 
    221      1.1  gmcgarry 	{ RD9134DID,	1,	"9134D",	NRD9134DBPT,
    222      1.1  gmcgarry 	  NRD9134DTRK,	303,	  29088 },
    223      1.1  gmcgarry 
    224      1.1  gmcgarry 	{ RD9134LID,	1,	"9122S",	NRD9122SBPT,
    225      1.1  gmcgarry 	  NRD9122STRK,	77,	   1232 },
    226      1.1  gmcgarry 
    227      1.1  gmcgarry 	{ RD7912PID,	0,	"7912P",	NRD7912PBPT,
    228      1.1  gmcgarry 	  NRD7912PTRK,	572,	 128128 },
    229      1.1  gmcgarry 
    230      1.1  gmcgarry 	{ RD7914PID,	0,	"7914P",	NRD7914PBPT,
    231      1.1  gmcgarry 	  NRD7914PTRK,	1152,	 258048 },
    232      1.1  gmcgarry 
    233      1.1  gmcgarry 	{ RD7958AID,	0,	"7958A",	NRD7958ABPT,
    234      1.1  gmcgarry 	  NRD7958ATRK,	1013,	 255276 },
    235      1.1  gmcgarry 
    236      1.1  gmcgarry 	{ RD7957AID,	0,	"7957A",	NRD7957ABPT,
    237      1.1  gmcgarry 	  NRD7957ATRK,	1036,	 159544 },
    238      1.1  gmcgarry 
    239      1.1  gmcgarry 	{ RD7933HID,	0,	"7933H",	NRD7933HBPT,
    240      1.1  gmcgarry 	  NRD7933HTRK,	1321,	 789958 },
    241      1.1  gmcgarry 
    242      1.1  gmcgarry 	{ RD9134LID,	1,	"9134L",	NRD9134LBPT,
    243      1.1  gmcgarry 	  NRD9134LTRK,	973,	  77840 },
    244      1.1  gmcgarry 
    245      1.1  gmcgarry 	{ RD7936HID,	0,	"7936H",	NRD7936HBPT,
    246      1.1  gmcgarry 	  NRD7936HTRK,	698,	 600978 },
    247      1.1  gmcgarry 
    248      1.1  gmcgarry 	{ RD7937HID,	0,	"7937H",	NRD7937HBPT,
    249      1.1  gmcgarry 	  NRD7937HTRK,	698,	1116102 },
    250      1.1  gmcgarry 
    251      1.1  gmcgarry 	{ RD7914CTID,	0,	"7914CT",	NRD7914PBPT,
    252      1.1  gmcgarry 	  NRD7914PTRK,	1152,	 258048 },
    253      1.1  gmcgarry 
    254      1.1  gmcgarry 	{ RD7946AID,	0,	"7946A",	NRD7945ABPT,
    255      1.1  gmcgarry 	  NRD7945ATRK,	968,	 108416 },
    256      1.1  gmcgarry 
    257      1.1  gmcgarry 	{ RD9134LID,	1,	"9122D",	NRD9122SBPT,
    258      1.1  gmcgarry 	  NRD9122STRK,	77,	   1232 },
    259      1.1  gmcgarry 
    260      1.1  gmcgarry 	{ RD7957BID,	0,	"7957B",	NRD7957BBPT,
    261      1.1  gmcgarry 	  NRD7957BTRK,	1269,	 159894 },
    262      1.1  gmcgarry 
    263      1.1  gmcgarry 	{ RD7958BID,	0,	"7958B",	NRD7958BBPT,
    264      1.1  gmcgarry 	  NRD7958BTRK,	786,	 297108 },
    265      1.1  gmcgarry 
    266      1.1  gmcgarry 	{ RD7959BID,	0,	"7959B",	NRD7959BBPT,
    267      1.1  gmcgarry 	  NRD7959BTRK,	1572,	 594216 },
    268      1.1  gmcgarry 
    269      1.1  gmcgarry 	{ RD2200AID,	0,	"2200A",	NRD2200ABPT,
    270      1.1  gmcgarry 	  NRD2200ATRK,	1449,	 654948 },
    271      1.1  gmcgarry 
    272      1.1  gmcgarry 	{ RD2203AID,	0,	"2203A",	NRD2203ABPT,
    273      1.1  gmcgarry 	  NRD2203ATRK,	1449,	1309896 }
    274      1.1  gmcgarry };
    275      1.1  gmcgarry int numrdidentinfo = sizeof(rdidentinfo) / sizeof(rdidentinfo[0]);
    276      1.1  gmcgarry 
    277      1.1  gmcgarry int	rdlookup(int, int, int);
    278      1.1  gmcgarry int	rdgetinfo(struct rd_softc *);
    279      1.1  gmcgarry void	rdrestart(void *);
    280      1.1  gmcgarry struct buf *rdfinish(struct rd_softc *, struct buf *);
    281      1.1  gmcgarry 
    282      1.1  gmcgarry void	rdgetcompatlabel(struct rd_softc *, struct disklabel *);
    283      1.1  gmcgarry void	rdgetdefaultlabel(struct rd_softc *, struct disklabel *);
    284      1.1  gmcgarry void	rdrestart(void *);
    285      1.1  gmcgarry void	rdustart(struct rd_softc *);
    286      1.1  gmcgarry struct buf *rdfinish(struct rd_softc *, struct buf *);
    287      1.1  gmcgarry void	rdcallback(void *, int);
    288      1.1  gmcgarry void	rdstart(struct rd_softc *);
    289      1.1  gmcgarry void	rdintr(struct rd_softc *);
    290      1.1  gmcgarry int	rderror(struct rd_softc *);
    291      1.1  gmcgarry 
    292      1.1  gmcgarry int	rdmatch(struct device *, struct cfdata *, void *);
    293      1.1  gmcgarry void	rdattach(struct device *, struct device *, void *);
    294      1.1  gmcgarry 
    295      1.1  gmcgarry CFATTACH_DECL(rd, sizeof(struct rd_softc),
    296      1.1  gmcgarry 	rdmatch, rdattach, NULL, NULL);
    297      1.1  gmcgarry 
    298      1.1  gmcgarry 
    299      1.1  gmcgarry dev_type_open(rdopen);
    300      1.1  gmcgarry dev_type_close(rdclose);
    301      1.1  gmcgarry dev_type_read(rdread);
    302      1.1  gmcgarry dev_type_write(rdwrite);
    303      1.1  gmcgarry dev_type_ioctl(rdioctl);
    304      1.1  gmcgarry dev_type_strategy(rdstrategy);
    305      1.1  gmcgarry dev_type_dump(rddump);
    306      1.1  gmcgarry dev_type_size(rdsize);
    307      1.1  gmcgarry 
    308      1.1  gmcgarry const struct bdevsw rd_bdevsw = {
    309      1.1  gmcgarry 	rdopen, rdclose, rdstrategy, rdioctl, rddump, rdsize, D_DISK
    310      1.1  gmcgarry };
    311      1.1  gmcgarry 
    312      1.1  gmcgarry const struct cdevsw rd_cdevsw = {
    313      1.1  gmcgarry 	rdopen, rdclose, rdread, rdwrite, rdioctl,
    314      1.1  gmcgarry 	nostop, notty, nopoll, nommap, nokqfilter, D_DISK
    315      1.1  gmcgarry };
    316      1.1  gmcgarry 
    317      1.1  gmcgarry extern struct cfdriver rd_cd;
    318      1.1  gmcgarry 
    319      1.1  gmcgarry int
    320      1.1  gmcgarry rdlookup(id, slave, punit)
    321      1.1  gmcgarry 	int id;
    322      1.1  gmcgarry 	int slave;
    323      1.1  gmcgarry 	int punit;
    324      1.1  gmcgarry {
    325      1.1  gmcgarry 	int i;
    326      1.1  gmcgarry 
    327      1.1  gmcgarry 	for (i = 0; i < numrdidentinfo; i++) {
    328      1.1  gmcgarry 		if (rdidentinfo[i].ri_hwid == id)
    329      1.1  gmcgarry 			break;
    330      1.1  gmcgarry 	}
    331      1.1  gmcgarry 	if (i == numrdidentinfo || punit > rdidentinfo[i].ri_maxunum)
    332      1.1  gmcgarry 		return (-1);
    333      1.1  gmcgarry 	return (i);
    334      1.1  gmcgarry }
    335      1.1  gmcgarry 
    336      1.1  gmcgarry int
    337      1.1  gmcgarry rdmatch(parent, match, aux)
    338      1.1  gmcgarry 	struct device *parent;
    339      1.1  gmcgarry 	struct cfdata *match;
    340      1.1  gmcgarry 	void *aux;
    341      1.1  gmcgarry {
    342      1.1  gmcgarry 	struct cs80bus_attach_args *ca = aux;
    343      1.1  gmcgarry 
    344      1.1  gmcgarry 	if (rdlookup(ca->ca_id, ca->ca_slave, ca->ca_punit) < 0)
    345      1.1  gmcgarry 		return (0);
    346      1.1  gmcgarry 	return (1);
    347      1.1  gmcgarry }
    348      1.1  gmcgarry 
    349      1.1  gmcgarry void
    350      1.1  gmcgarry rdattach(parent, self, aux)
    351      1.1  gmcgarry 	struct device *parent, *self;
    352      1.1  gmcgarry 	void *aux;
    353      1.1  gmcgarry {
    354      1.1  gmcgarry 	struct rd_softc *sc = (struct rd_softc *)self;
    355      1.1  gmcgarry 	struct cs80bus_attach_args *ca = aux;
    356      1.1  gmcgarry 	struct cs80_description csd;
    357      1.1  gmcgarry 	char name[7];
    358      1.1  gmcgarry 	int type, i, n;
    359      1.1  gmcgarry 
    360      1.1  gmcgarry 	sc->sc_ic = ca->ca_ic;
    361      1.1  gmcgarry 	sc->sc_slave = ca->ca_slave;
    362      1.1  gmcgarry 	sc->sc_punit = ca->ca_punit;
    363      1.1  gmcgarry 
    364      1.1  gmcgarry 	if ((type = rdlookup(ca->ca_id, ca->ca_slave, ca->ca_punit)) < 0)
    365      1.1  gmcgarry 		return;
    366      1.1  gmcgarry 
    367      1.1  gmcgarry 	if (cs80reset(parent, sc->sc_slave, sc->sc_punit)) {
    368      1.1  gmcgarry 		printf("\n%s: can't reset device\n", sc->sc_dev.dv_xname);
    369      1.1  gmcgarry 		return;
    370      1.1  gmcgarry 	}
    371      1.1  gmcgarry 
    372      1.1  gmcgarry 	if (cs80describe(parent, sc->sc_slave, sc->sc_punit, &csd)) {
    373      1.1  gmcgarry 		printf("\n%s: didn't respond to describe command\n",
    374      1.1  gmcgarry 		    sc->sc_dev.dv_xname);
    375      1.1  gmcgarry 		return;
    376      1.1  gmcgarry 	}
    377      1.1  gmcgarry 	memset(name, 0, sizeof(name));
    378      1.1  gmcgarry 	for (i=0, n=0; i<3; i++) {
    379      1.1  gmcgarry 		name[n++] = (csd.d_name[i] >> 4) + '0';
    380      1.1  gmcgarry 		name[n++] = (csd.d_name[i] & 0x0f) + '0';
    381      1.1  gmcgarry 	}
    382      1.1  gmcgarry 
    383      1.1  gmcgarry #ifdef DEBUG
    384      1.1  gmcgarry 	if (rddebug & RDB_IDENT) {
    385      1.1  gmcgarry 		printf("\n%s: name: ('%s')\n",
    386      1.1  gmcgarry 		    sc->sc_dev.dv_xname, name);
    387      1.1  gmcgarry 		printf("  iuw %x, maxxfr %d, ctype %d\n",
    388      1.1  gmcgarry 		    csd.d_iuw, csd.d_cmaxxfr, csd.d_ctype);
    389      1.1  gmcgarry 		printf("  utype %d, bps %d, blkbuf %d, burst %d, blktime %d\n",
    390      1.1  gmcgarry 		    csd.d_utype, csd.d_sectsize,
    391      1.1  gmcgarry 		    csd.d_blkbuf, csd.d_burstsize, csd.d_blocktime);
    392      1.1  gmcgarry 		printf("  avxfr %d, ort %d, atp %d, maxint %d, fv %x, rv %x\n",
    393      1.1  gmcgarry 		    csd.d_uavexfr, csd.d_retry, csd.d_access,
    394      1.1  gmcgarry 		    csd.d_maxint, csd.d_fvbyte, csd.d_rvbyte);
    395      1.1  gmcgarry 		printf("  maxcyl/head/sect %d/%d/%d, maxvsect %d, inter %d\n",
    396      1.1  gmcgarry 		    csd.d_maxcylhead >> 8, csd.d_maxcylhead & 0xff,
    397      1.1  gmcgarry 		    csd.d_maxsect, csd.d_maxvsectl, csd.d_interleave);
    398      1.1  gmcgarry 		printf("%s", sc->sc_dev.dv_xname);
    399      1.1  gmcgarry 	}
    400      1.1  gmcgarry #endif
    401      1.1  gmcgarry 
    402      1.1  gmcgarry 	/*
    403      1.1  gmcgarry 	 * Take care of a couple of anomolies:
    404      1.1  gmcgarry 	 * 1. 7945A and 7946A both return same HW id
    405      1.1  gmcgarry 	 * 2. 9122S and 9134D both return same HW id
    406      1.1  gmcgarry 	 * 3. 9122D and 9134L both return same HW id
    407      1.1  gmcgarry 	 */
    408      1.1  gmcgarry 	switch (ca->ca_id) {
    409      1.1  gmcgarry 	case RD7946AID:
    410      1.1  gmcgarry 		if (memcmp(name, "079450", 6) == 0)
    411      1.1  gmcgarry 			type = RD7945A;
    412      1.1  gmcgarry 		else
    413      1.1  gmcgarry 			type = RD7946A;
    414      1.1  gmcgarry 		break;
    415      1.1  gmcgarry 
    416      1.1  gmcgarry 	case RD9134LID:
    417      1.1  gmcgarry 		if (memcmp(name, "091340", 6) == 0)
    418      1.1  gmcgarry 			type = RD9134L;
    419      1.1  gmcgarry 		else
    420      1.1  gmcgarry 			type = RD9122D;
    421      1.1  gmcgarry 		break;
    422      1.1  gmcgarry 
    423      1.1  gmcgarry 	case RD9134DID:
    424      1.1  gmcgarry 		if (memcmp(name, "091220", 6) == 0)
    425      1.1  gmcgarry 			type = RD9122S;
    426      1.1  gmcgarry 		else
    427      1.1  gmcgarry 			type = RD9134D;
    428      1.1  gmcgarry 		break;
    429      1.1  gmcgarry 	}
    430      1.1  gmcgarry 
    431      1.1  gmcgarry 	sc->sc_type = type;
    432      1.1  gmcgarry 
    433      1.1  gmcgarry 	/*
    434      1.1  gmcgarry 	 * XXX We use DEV_BSIZE instead of the sector size value pulled
    435      1.1  gmcgarry 	 * XXX off the driver because all of this code assumes 512 byte
    436      1.1  gmcgarry 	 * XXX blocks.  ICK!
    437      1.1  gmcgarry 	 */
    438      1.1  gmcgarry 	printf(": %s\n", rdidentinfo[type].ri_desc);
    439      1.1  gmcgarry 	printf("%s: %d cylinders, %d heads, %d blocks, %d bytes/block\n",
    440      1.1  gmcgarry 	    sc->sc_dev.dv_xname, rdidentinfo[type].ri_ncyl,
    441      1.1  gmcgarry 	    rdidentinfo[type].ri_ntpc, rdidentinfo[type].ri_nblocks,
    442      1.1  gmcgarry 	    DEV_BSIZE);
    443      1.1  gmcgarry 
    444      1.1  gmcgarry 	bufq_alloc(&sc->sc_tab, BUFQ_FCFS);
    445      1.1  gmcgarry 
    446      1.1  gmcgarry 	/*
    447      1.1  gmcgarry 	 * Initialize and attach the disk structure.
    448      1.1  gmcgarry 	 */
    449      1.1  gmcgarry 	memset(&sc->sc_dk, 0, sizeof(sc->sc_dk));
    450      1.1  gmcgarry 	sc->sc_dk.dk_name = sc->sc_dev.dv_xname;
    451      1.1  gmcgarry 	disk_attach(&sc->sc_dk);
    452      1.1  gmcgarry 
    453      1.1  gmcgarry 	callout_init(&sc->sc_restart_ch);
    454      1.1  gmcgarry 
    455      1.1  gmcgarry 	if (gpibregister(sc->sc_ic, sc->sc_slave, rdcallback, sc,
    456      1.1  gmcgarry 	    &sc->sc_hdl)) {
    457      1.1  gmcgarry 		printf("%s: can't register callback\n", sc->sc_dev.dv_xname);
    458      1.1  gmcgarry 		return;
    459      1.1  gmcgarry 	}
    460      1.1  gmcgarry 
    461      1.1  gmcgarry 	sc->sc_flags = RDF_ALIVE;
    462      1.1  gmcgarry #ifdef DEBUG
    463      1.1  gmcgarry 	/* always report errors */
    464      1.1  gmcgarry 	if (rddebug & RDB_ERROR)
    465      1.1  gmcgarry 		rderrthresh = 0;
    466      1.1  gmcgarry #endif
    467      1.1  gmcgarry #if NRND > 0
    468      1.1  gmcgarry 	/*
    469      1.1  gmcgarry 	 * attach the device into the random source list
    470      1.1  gmcgarry 	 */
    471      1.1  gmcgarry 	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
    472      1.1  gmcgarry 			  RND_TYPE_DISK, 0);
    473      1.1  gmcgarry #endif
    474      1.1  gmcgarry }
    475      1.1  gmcgarry 
    476      1.1  gmcgarry /*
    477      1.1  gmcgarry  * Read or constuct a disklabel
    478      1.1  gmcgarry  */
    479      1.1  gmcgarry int
    480      1.1  gmcgarry rdgetinfo(sc)
    481      1.1  gmcgarry 	struct rd_softc *sc;
    482      1.1  gmcgarry {
    483      1.1  gmcgarry 	struct disklabel *lp = sc->sc_dk.dk_label;
    484      1.1  gmcgarry 	struct partition *pi;
    485      1.1  gmcgarry 	const char *msg;
    486      1.1  gmcgarry 
    487      1.1  gmcgarry 	memset(sc->sc_dk.dk_cpulabel, 0, sizeof(struct cpu_disklabel));
    488      1.1  gmcgarry 
    489      1.1  gmcgarry 	rdgetdefaultlabel(sc, lp);
    490      1.1  gmcgarry 
    491      1.1  gmcgarry 	/*
    492      1.1  gmcgarry 	 * Call the generic disklabel extraction routine
    493      1.1  gmcgarry 	 */
    494      1.1  gmcgarry 	msg = readdisklabel(RDMAKEDEV(0, sc->sc_dev.dv_unit, RAW_PART),
    495      1.1  gmcgarry 	    rdstrategy, lp, NULL);
    496      1.1  gmcgarry 	if (msg == NULL)
    497      1.1  gmcgarry 		return (0);
    498      1.1  gmcgarry 
    499      1.1  gmcgarry 	pi = lp->d_partitions;
    500      1.1  gmcgarry 	printf("%s: WARNING: %s, ", sc->sc_dev.dv_xname, msg);
    501      1.1  gmcgarry #ifdef COMPAT_NOLABEL
    502      1.1  gmcgarry 	printf("using old default partitioning\n");
    503      1.1  gmcgarry 	rdgetcompatlabel(sc, lp);
    504      1.1  gmcgarry #else
    505      1.1  gmcgarry 	printf("defining '%c' partition as entire disk\n", 'a' + RAW_PART);
    506      1.1  gmcgarry 	pi[RAW_PART].p_size = rdidentinfo[sc->sc_type].ri_nblocks;
    507      1.1  gmcgarry 	lp->d_npartitions = RAW_PART+1;
    508      1.1  gmcgarry 	pi[0].p_size = 0;
    509      1.1  gmcgarry #endif
    510      1.1  gmcgarry 	return (0);
    511      1.1  gmcgarry }
    512      1.1  gmcgarry 
    513      1.1  gmcgarry int
    514      1.1  gmcgarry rdopen(dev, flags, mode, p)
    515      1.1  gmcgarry 	dev_t dev;
    516      1.1  gmcgarry 	int flags, mode;
    517      1.1  gmcgarry 	struct proc *p;
    518      1.1  gmcgarry {
    519      1.1  gmcgarry 	struct rd_softc *sc;
    520      1.1  gmcgarry 	int error, mask, part;
    521      1.1  gmcgarry 
    522      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(dev));
    523      1.1  gmcgarry 	if (sc == NULL || (sc->sc_flags & RDF_ALIVE) ==0)
    524      1.1  gmcgarry 		return (ENXIO);
    525      1.1  gmcgarry 
    526      1.1  gmcgarry 	/*
    527      1.1  gmcgarry 	 * Wait for any pending opens/closes to complete
    528      1.1  gmcgarry 	 */
    529      1.1  gmcgarry 	while (sc->sc_flags & (RDF_OPENING | RDF_CLOSING))
    530      1.1  gmcgarry 		(void) tsleep(sc, PRIBIO, "rdopen", 0);
    531      1.1  gmcgarry 
    532      1.1  gmcgarry 	/*
    533      1.1  gmcgarry 	 * On first open, get label and partition info.
    534      1.1  gmcgarry 	 * We may block reading the label, so be careful
    535      1.1  gmcgarry 	 * to stop any other opens.
    536      1.1  gmcgarry 	 */
    537      1.1  gmcgarry 	if (sc->sc_dk.dk_openmask == 0) {
    538      1.1  gmcgarry 		sc->sc_flags |= RDF_OPENING;
    539      1.1  gmcgarry 		error = rdgetinfo(sc);
    540      1.1  gmcgarry 		sc->sc_flags &= ~RDF_OPENING;
    541      1.1  gmcgarry 		wakeup((caddr_t)sc);
    542      1.1  gmcgarry 		if (error)
    543      1.1  gmcgarry 			return (error);
    544      1.1  gmcgarry 	}
    545      1.1  gmcgarry 
    546      1.1  gmcgarry 	part = RDPART(dev);
    547      1.1  gmcgarry 	mask = 1 << part;
    548      1.1  gmcgarry 
    549      1.1  gmcgarry 	/* Check that the partition exists. */
    550      1.1  gmcgarry 	if (part != RAW_PART && (part > sc->sc_dk.dk_label->d_npartitions ||
    551      1.1  gmcgarry 	    sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED))
    552      1.1  gmcgarry 		return (ENXIO);
    553      1.1  gmcgarry 
    554      1.1  gmcgarry 	/* Ensure only one open at a time. */
    555      1.1  gmcgarry 	switch (mode) {
    556      1.1  gmcgarry 	case S_IFCHR:
    557      1.1  gmcgarry 		sc->sc_dk.dk_copenmask |= mask;
    558      1.1  gmcgarry 		break;
    559      1.1  gmcgarry 	case S_IFBLK:
    560      1.1  gmcgarry 		sc->sc_dk.dk_bopenmask |= mask;
    561      1.1  gmcgarry 		break;
    562      1.1  gmcgarry 	}
    563      1.1  gmcgarry 	sc->sc_dk.dk_openmask =
    564      1.1  gmcgarry 	    sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
    565      1.1  gmcgarry 
    566      1.1  gmcgarry 	return (0);
    567      1.1  gmcgarry }
    568      1.1  gmcgarry 
    569      1.1  gmcgarry int
    570      1.1  gmcgarry rdclose(dev, flag, mode, p)
    571      1.1  gmcgarry 	dev_t dev;
    572      1.1  gmcgarry 	int flag, mode;
    573      1.1  gmcgarry 	struct proc *p;
    574      1.1  gmcgarry {
    575      1.1  gmcgarry 	struct rd_softc *sc;
    576      1.1  gmcgarry 	struct disk *dk;
    577      1.1  gmcgarry 	int mask, s;
    578      1.1  gmcgarry 
    579      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(dev));
    580      1.1  gmcgarry 	if (sc == NULL)
    581      1.1  gmcgarry 		return (ENXIO);
    582      1.1  gmcgarry 
    583      1.1  gmcgarry 	dk = &sc->sc_dk;
    584      1.1  gmcgarry 
    585      1.1  gmcgarry 	mask = 1 << RDPART(dev);
    586      1.1  gmcgarry 	if (mode == S_IFCHR)
    587      1.1  gmcgarry 		dk->dk_copenmask &= ~mask;
    588      1.1  gmcgarry 	else
    589      1.1  gmcgarry 		dk->dk_bopenmask &= ~mask;
    590      1.1  gmcgarry 	dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
    591      1.1  gmcgarry 	/*
    592      1.1  gmcgarry 	 * On last close, we wait for all activity to cease since
    593      1.1  gmcgarry 	 * the label/parition info will become invalid.  Since we
    594      1.1  gmcgarry 	 * might sleep, we must block any opens while we are here.
    595      1.1  gmcgarry 	 * Note we don't have to about other closes since we know
    596      1.1  gmcgarry 	 * we are the last one.
    597      1.1  gmcgarry 	 */
    598      1.1  gmcgarry 	if (dk->dk_openmask == 0) {
    599      1.1  gmcgarry 		sc->sc_flags |= RDF_CLOSING;
    600      1.1  gmcgarry 		s = splbio();
    601      1.1  gmcgarry 		while (sc->sc_active) {
    602      1.1  gmcgarry 			sc->sc_flags |= RDF_WANTED;
    603      1.1  gmcgarry 			(void) tsleep(&sc->sc_tab, PRIBIO, "rdclose", 0);
    604      1.1  gmcgarry 		}
    605      1.1  gmcgarry 		splx(s);
    606      1.1  gmcgarry 		sc->sc_flags &= ~(RDF_CLOSING | RDF_WLABEL);
    607      1.1  gmcgarry 		wakeup((caddr_t)sc);
    608      1.1  gmcgarry 	}
    609      1.1  gmcgarry 	return (0);
    610      1.1  gmcgarry }
    611      1.1  gmcgarry 
    612      1.1  gmcgarry void
    613      1.1  gmcgarry rdstrategy(bp)
    614      1.1  gmcgarry 	struct buf *bp;
    615      1.1  gmcgarry {
    616      1.1  gmcgarry 	struct rd_softc *sc;
    617      1.1  gmcgarry 	struct partition *pinfo;
    618      1.1  gmcgarry 	daddr_t bn;
    619      1.1  gmcgarry 	int sz, s;
    620      1.1  gmcgarry 	int offset;
    621      1.1  gmcgarry 
    622      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(bp->b_dev));
    623      1.1  gmcgarry 
    624      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW,
    625      1.1  gmcgarry 	    ("rdstrategy(%p): dev %x, bn %" PRId64 ", bcount %ld, %c\n",
    626      1.1  gmcgarry 	    bp, bp->b_dev, bp->b_blkno, bp->b_bcount,
    627      1.1  gmcgarry 	    (bp->b_flags & B_READ) ? 'R' : 'W'));
    628      1.1  gmcgarry 
    629      1.1  gmcgarry 	bn = bp->b_blkno;
    630      1.1  gmcgarry 	sz = howmany(bp->b_bcount, DEV_BSIZE);
    631      1.1  gmcgarry 	pinfo = &sc->sc_dk.dk_label->d_partitions[RDPART(bp->b_dev)];
    632      1.1  gmcgarry 
    633      1.1  gmcgarry 	/* Don't perform partition translation on RAW_PART. */
    634      1.1  gmcgarry 	offset = (RDPART(bp->b_dev) == RAW_PART) ? 0 : pinfo->p_offset;
    635      1.1  gmcgarry 
    636      1.1  gmcgarry 	if (RDPART(bp->b_dev) != RAW_PART) {
    637      1.1  gmcgarry 		/*
    638      1.1  gmcgarry 		 * XXX This block of code belongs in
    639      1.1  gmcgarry 		 * XXX bounds_check_with_label()
    640      1.1  gmcgarry 		 */
    641      1.1  gmcgarry 
    642      1.1  gmcgarry 		if (bn < 0 || bn + sz > pinfo->p_size) {
    643      1.1  gmcgarry 			sz = pinfo->p_size - bn;
    644      1.1  gmcgarry 			if (sz == 0) {
    645      1.1  gmcgarry 				bp->b_resid = bp->b_bcount;
    646      1.1  gmcgarry 				goto done;
    647      1.1  gmcgarry 			}
    648      1.1  gmcgarry 			if (sz < 0) {
    649      1.1  gmcgarry 				bp->b_error = EINVAL;
    650      1.1  gmcgarry 				goto bad;
    651      1.1  gmcgarry 			}
    652      1.1  gmcgarry 			bp->b_bcount = dbtob(sz);
    653      1.1  gmcgarry 		}
    654      1.1  gmcgarry 		/*
    655      1.1  gmcgarry 		 * Check for write to write protected label
    656      1.1  gmcgarry 		 */
    657      1.1  gmcgarry 		if (bn + offset <= LABELSECTOR &&
    658      1.1  gmcgarry #if LABELSECTOR != 0
    659      1.1  gmcgarry 		    bn + offset + sz > LABELSECTOR &&
    660      1.1  gmcgarry #endif
    661      1.1  gmcgarry 		    !(bp->b_flags & B_READ) && !(sc->sc_flags & RDF_WLABEL)) {
    662      1.1  gmcgarry 			bp->b_error = EROFS;
    663      1.1  gmcgarry 			goto bad;
    664      1.1  gmcgarry 		}
    665      1.1  gmcgarry 	}
    666      1.1  gmcgarry 	bp->b_rawblkno = bn + offset;
    667      1.1  gmcgarry 	s = splbio();
    668      1.1  gmcgarry 	BUFQ_PUT(&sc->sc_tab, bp);
    669      1.1  gmcgarry 	if (sc->sc_active == 0) {
    670      1.1  gmcgarry 		sc->sc_active = 1;
    671      1.1  gmcgarry 		rdustart(sc);
    672      1.1  gmcgarry 	}
    673      1.1  gmcgarry 	splx(s);
    674      1.1  gmcgarry 	return;
    675      1.1  gmcgarry bad:
    676      1.1  gmcgarry 	bp->b_flags |= B_ERROR;
    677      1.1  gmcgarry done:
    678      1.1  gmcgarry 	biodone(bp);
    679      1.1  gmcgarry }
    680      1.1  gmcgarry 
    681      1.1  gmcgarry /*
    682      1.1  gmcgarry  * Called from timeout() when handling maintenance releases
    683      1.1  gmcgarry  * callout from timeouts
    684      1.1  gmcgarry  */
    685      1.1  gmcgarry void
    686      1.1  gmcgarry rdrestart(arg)
    687      1.1  gmcgarry 	void *arg;
    688      1.1  gmcgarry {
    689      1.1  gmcgarry 	int s = splbio();
    690      1.1  gmcgarry 	rdustart((struct rd_softc *)arg);
    691      1.1  gmcgarry 	splx(s);
    692      1.1  gmcgarry }
    693      1.1  gmcgarry 
    694      1.1  gmcgarry 
    695      1.1  gmcgarry /* called by rdstrategy() to start a block transfer */
    696      1.1  gmcgarry /* called by rdrestart() when handingly timeouts */
    697      1.1  gmcgarry /* called by rdintr() */
    698      1.1  gmcgarry void
    699      1.1  gmcgarry rdustart(sc)
    700      1.1  gmcgarry 	struct rd_softc *sc;
    701      1.1  gmcgarry {
    702      1.1  gmcgarry 	struct buf *bp;
    703      1.1  gmcgarry 
    704      1.1  gmcgarry 	bp = BUFQ_PEEK(&sc->sc_tab);
    705      1.1  gmcgarry 	sc->sc_addr = bp->b_data;
    706      1.1  gmcgarry 	sc->sc_resid = bp->b_bcount;
    707      1.1  gmcgarry 	if (gpibrequest(sc->sc_ic, sc->sc_hdl))
    708      1.1  gmcgarry 		rdstart(sc);
    709      1.1  gmcgarry }
    710      1.1  gmcgarry 
    711      1.1  gmcgarry struct buf *
    712      1.1  gmcgarry rdfinish(sc, bp)
    713      1.1  gmcgarry 	struct rd_softc *sc;
    714      1.1  gmcgarry 	struct buf *bp;
    715      1.1  gmcgarry {
    716      1.1  gmcgarry 
    717      1.1  gmcgarry 	sc->sc_errcnt = 0;
    718      1.1  gmcgarry 	(void)BUFQ_GET(&sc->sc_tab);
    719      1.1  gmcgarry 	bp->b_resid = 0;
    720      1.1  gmcgarry 	biodone(bp);
    721      1.1  gmcgarry 	gpibrelease(sc->sc_ic, sc->sc_hdl);
    722      1.1  gmcgarry 	if ((bp = BUFQ_PEEK(&sc->sc_tab)) != NULL)
    723      1.1  gmcgarry 		return (bp);
    724      1.1  gmcgarry 	sc->sc_active = 0;
    725      1.1  gmcgarry 	if (sc->sc_flags & RDF_WANTED) {
    726      1.1  gmcgarry 		sc->sc_flags &= ~RDF_WANTED;
    727      1.1  gmcgarry 		wakeup((caddr_t)&sc->sc_tab);
    728      1.1  gmcgarry 	}
    729      1.1  gmcgarry 	return (NULL);
    730      1.1  gmcgarry }
    731      1.1  gmcgarry 
    732      1.1  gmcgarry void
    733      1.1  gmcgarry rdcallback(v, action)
    734      1.1  gmcgarry 	void *v;
    735      1.1  gmcgarry 	int action;
    736      1.1  gmcgarry {
    737      1.1  gmcgarry 	struct rd_softc *sc = v;
    738      1.1  gmcgarry 
    739      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rdcallback: v=%p, action=%d\n", v, action));
    740      1.1  gmcgarry 
    741      1.1  gmcgarry 	switch (action) {
    742      1.1  gmcgarry 	case GPIBCBF_START:
    743      1.1  gmcgarry 		rdstart(sc);
    744      1.1  gmcgarry 		break;
    745      1.1  gmcgarry 	case GPIBCBF_INTR:
    746      1.1  gmcgarry 		rdintr(sc);
    747      1.1  gmcgarry 		break;
    748      1.1  gmcgarry #ifdef DEBUG
    749      1.1  gmcgarry 	default:
    750      1.1  gmcgarry 		DPRINTF(RDB_ERROR, ("rdcallback: unknown action %d\n",
    751      1.1  gmcgarry 		    action));
    752      1.1  gmcgarry 		break;
    753      1.1  gmcgarry #endif
    754      1.1  gmcgarry 	}
    755      1.1  gmcgarry }
    756      1.1  gmcgarry 
    757      1.1  gmcgarry 
    758      1.1  gmcgarry /* called from rdustart() to start a transfer */
    759      1.1  gmcgarry /* called from gpib interface as the initiator */
    760      1.1  gmcgarry void
    761      1.1  gmcgarry rdstart(sc)
    762      1.1  gmcgarry 	struct rd_softc *sc;
    763      1.1  gmcgarry {
    764      1.1  gmcgarry 	struct buf *bp = BUFQ_PEEK(&sc->sc_tab);
    765      1.1  gmcgarry 	int part, slave, punit;
    766      1.1  gmcgarry 
    767      1.1  gmcgarry 	slave = sc->sc_slave;
    768      1.1  gmcgarry 	punit = sc->sc_punit;
    769      1.1  gmcgarry 
    770      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rdstart(%s): bp %p, %c\n",
    771      1.1  gmcgarry 	    sc->sc_dev.dv_xname, bp, (bp->b_flags & B_READ) ? 'R' : 'W'));
    772      1.1  gmcgarry 
    773      1.1  gmcgarry again:
    774      1.1  gmcgarry 
    775      1.1  gmcgarry 	part = RDPART(bp->b_dev);
    776      1.1  gmcgarry 	sc->sc_flags |= RDF_SEEK;
    777      1.1  gmcgarry 	sc->sc_ioc.c_unit = CS80CMD_SUNIT(punit);
    778      1.1  gmcgarry 	sc->sc_ioc.c_volume = CS80CMD_SVOL(0);
    779      1.1  gmcgarry 	sc->sc_ioc.c_saddr = CS80CMD_SADDR;
    780      1.1  gmcgarry 	sc->sc_ioc.c_hiaddr = htobe16(0);
    781      1.1  gmcgarry 	sc->sc_ioc.c_addr = htobe32(RDBTOS(bp->b_rawblkno));
    782      1.1  gmcgarry 	sc->sc_ioc.c_nop2 = CS80CMD_NOP;
    783      1.1  gmcgarry 	sc->sc_ioc.c_slen = CS80CMD_SLEN;
    784      1.1  gmcgarry 	sc->sc_ioc.c_len = htobe32(sc->sc_resid);
    785      1.1  gmcgarry 	sc->sc_ioc.c_cmd = bp->b_flags & B_READ ? CS80CMD_READ : CS80CMD_WRITE;
    786      1.1  gmcgarry 
    787      1.1  gmcgarry 	if (gpibsend(sc->sc_ic, slave, CS80CMD_SCMD, &sc->sc_ioc.c_unit,
    788      1.1  gmcgarry 	    sizeof(sc->sc_ioc)-1) == sizeof(sc->sc_ioc)-1) {
    789      1.1  gmcgarry 		/* Instrumentation. */
    790      1.1  gmcgarry 		disk_busy(&sc->sc_dk);
    791      1.1  gmcgarry 		sc->sc_dk.dk_seek++;
    792      1.1  gmcgarry 		gpibawait(sc->sc_ic);
    793      1.1  gmcgarry 		return;
    794      1.1  gmcgarry 	}
    795      1.1  gmcgarry 	/*
    796      1.1  gmcgarry 	 * Experience has shown that the gpibwait in this gpibsend will
    797      1.1  gmcgarry 	 * occasionally timeout.  It appears to occur mostly on old 7914
    798      1.1  gmcgarry 	 * drives with full maintenance tracks.  We should probably
    799      1.1  gmcgarry 	 * integrate this with the backoff code in rderror.
    800      1.1  gmcgarry 	 */
    801      1.1  gmcgarry 
    802      1.1  gmcgarry 	DPRINTF(RDB_ERROR,
    803      1.1  gmcgarry 	    ("rdstart: cmd %x adr %ul blk %" PRId64 " len %d ecnt %d\n",
    804      1.1  gmcgarry 	    sc->sc_ioc.c_cmd, sc->sc_ioc.c_addr, bp->b_blkno, sc->sc_resid,
    805      1.1  gmcgarry 	     sc->sc_errcnt));
    806      1.1  gmcgarry 
    807      1.1  gmcgarry 	sc->sc_flags &= ~RDF_SEEK;
    808      1.1  gmcgarry 	cs80reset(sc->sc_dev.dv_parent, slave, punit);
    809      1.1  gmcgarry 	if (sc->sc_errcnt++ < RDRETRY)
    810      1.1  gmcgarry 		goto again;
    811      1.1  gmcgarry 	printf("%s: rdstart err: cmd 0x%x sect %uld blk %" PRId64 " len %d\n",
    812      1.1  gmcgarry 	       sc->sc_dev.dv_xname, sc->sc_ioc.c_cmd, sc->sc_ioc.c_addr,
    813      1.1  gmcgarry 	       bp->b_blkno, sc->sc_resid);
    814      1.1  gmcgarry 	bp->b_flags |= B_ERROR;
    815      1.1  gmcgarry 	bp->b_error = EIO;
    816      1.1  gmcgarry 	bp = rdfinish(sc, bp);
    817      1.1  gmcgarry 	if (bp) {
    818      1.1  gmcgarry 		sc->sc_addr = bp->b_data;
    819      1.1  gmcgarry 		sc->sc_resid = bp->b_bcount;
    820      1.1  gmcgarry 		if (gpibrequest(sc->sc_ic, sc->sc_hdl))
    821      1.1  gmcgarry 			goto again;
    822      1.1  gmcgarry 	}
    823      1.1  gmcgarry }
    824      1.1  gmcgarry 
    825      1.1  gmcgarry void
    826      1.1  gmcgarry rdintr(sc)
    827      1.1  gmcgarry 	struct rd_softc *sc;
    828      1.1  gmcgarry {
    829      1.1  gmcgarry 	struct buf *bp;
    830      1.1  gmcgarry 	u_int8_t stat = 13;	/* in case gpibrecv fails */
    831      1.1  gmcgarry 	int rv, dir, restart, slave;
    832      1.1  gmcgarry 
    833      1.1  gmcgarry 	slave = sc->sc_slave;
    834      1.1  gmcgarry 	bp = BUFQ_PEEK(&sc->sc_tab);
    835      1.1  gmcgarry 
    836      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rdintr(%s): bp %p, %c, flags %x\n",
    837      1.1  gmcgarry 	    sc->sc_dev.dv_xname, bp, (bp->b_flags & B_READ) ? 'R' : 'W',
    838      1.1  gmcgarry 	    sc->sc_flags));
    839      1.1  gmcgarry 
    840      1.1  gmcgarry 	disk_unbusy(&sc->sc_dk, (bp->b_bcount - bp->b_resid),
    841      1.1  gmcgarry 		(bp->b_flags & B_READ));
    842      1.1  gmcgarry 
    843      1.1  gmcgarry 	if (sc->sc_flags & RDF_SEEK) {
    844      1.1  gmcgarry 		sc->sc_flags &= ~RDF_SEEK;
    845      1.1  gmcgarry 		dir = (bp->b_flags & B_READ ? GPIB_READ : GPIB_WRITE);
    846      1.1  gmcgarry 		gpibxfer(sc->sc_ic, slave, CS80CMD_EXEC, sc->sc_addr,
    847      1.1  gmcgarry 		    sc->sc_resid, dir, dir == GPIB_READ);
    848      1.1  gmcgarry 		disk_busy(&sc->sc_dk);
    849      1.1  gmcgarry 		return;
    850      1.1  gmcgarry 	}
    851      1.1  gmcgarry 	if ((sc->sc_flags & RDF_SWAIT) == 0) {
    852      1.1  gmcgarry 		if (gpibpptest(sc->sc_ic, slave) == 0) {
    853      1.1  gmcgarry 			/* Instrumentation. */
    854      1.1  gmcgarry 			disk_busy(&sc->sc_dk);
    855      1.1  gmcgarry 			sc->sc_flags |= RDF_SWAIT;
    856      1.1  gmcgarry 			gpibawait(sc->sc_ic);
    857      1.1  gmcgarry 			return;
    858      1.1  gmcgarry 		}
    859      1.1  gmcgarry 	} else
    860      1.1  gmcgarry 		sc->sc_flags &= ~RDF_SWAIT;
    861      1.1  gmcgarry 	rv = gpibrecv(sc->sc_ic, slave, CS80CMD_QSTAT, &stat, 1);
    862      1.1  gmcgarry 	if (rv != 1 || stat) {
    863      1.1  gmcgarry 		DPRINTF(RDB_ERROR,
    864      1.1  gmcgarry 		    ("rdintr: receive failed (rv=%d) or bad stat %d\n", rv,
    865      1.1  gmcgarry 		     stat));
    866      1.1  gmcgarry 		restart = rderror(sc);
    867      1.1  gmcgarry 		if (sc->sc_errcnt++ < RDRETRY) {
    868      1.1  gmcgarry 			if (restart)
    869      1.1  gmcgarry 				rdstart(sc);
    870      1.1  gmcgarry 			return;
    871      1.1  gmcgarry 		}
    872      1.1  gmcgarry 		bp->b_flags |= B_ERROR;
    873      1.1  gmcgarry 		bp->b_error = EIO;
    874      1.1  gmcgarry 	}
    875      1.1  gmcgarry 	if (rdfinish(sc, bp) != NULL)
    876      1.1  gmcgarry 		rdustart(sc);
    877      1.1  gmcgarry #if NRND > 0
    878      1.1  gmcgarry 	rnd_add_uint32(&sc->rnd_source, bp->b_blkno);
    879      1.1  gmcgarry #endif
    880      1.1  gmcgarry }
    881      1.1  gmcgarry 
    882      1.1  gmcgarry /*
    883      1.1  gmcgarry  * Deal with errors.
    884      1.1  gmcgarry  * Returns 1 if request should be restarted,
    885      1.1  gmcgarry  * 0 if we should just quietly give up.
    886      1.1  gmcgarry  */
    887      1.1  gmcgarry int
    888      1.1  gmcgarry rderror(sc)
    889      1.1  gmcgarry 	struct rd_softc *sc;
    890      1.1  gmcgarry {
    891      1.1  gmcgarry 	struct cs80_stat css;
    892      1.1  gmcgarry 	struct buf *bp;
    893      1.1  gmcgarry 	daddr_t hwbn, pbn;
    894      1.1  gmcgarry 
    895      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rderror: sc=%p\n", sc));
    896      1.1  gmcgarry 
    897      1.1  gmcgarry 	if (cs80status(sc->sc_dev.dv_parent, sc->sc_slave,
    898      1.1  gmcgarry 	    sc->sc_punit, &css)) {
    899      1.1  gmcgarry 		cs80reset(sc->sc_dev.dv_parent, sc->sc_slave, sc->sc_punit);
    900      1.1  gmcgarry 		return (1);
    901      1.1  gmcgarry 	}
    902      1.1  gmcgarry #ifdef DEBUG
    903      1.1  gmcgarry 	if (rddebug & RDB_ERROR) {			/* status info */
    904      1.1  gmcgarry 		printf("\n    volume: %d, unit: %d\n",
    905      1.1  gmcgarry 		       (css.c_vu>>4)&0xF, css.c_vu&0xF);
    906      1.1  gmcgarry 		printf("    reject 0x%x\n", css.c_ref);
    907      1.1  gmcgarry 		printf("    fault 0x%x\n", css.c_fef);
    908      1.1  gmcgarry 		printf("    access 0x%x\n", css.c_aef);
    909      1.1  gmcgarry 		printf("    info 0x%x\n", css.c_ief);
    910      1.1  gmcgarry 		printf("    block,  P1-P10: ");
    911      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&css.c_raw[0]);
    912      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&css.c_raw[4]);
    913      1.1  gmcgarry 		printf("0x%x\n", *(u_int16_t *)&css.c_raw[8]);
    914      1.1  gmcgarry 	}
    915      1.1  gmcgarry #endif
    916      1.1  gmcgarry 	if (css.c_fef & FEF_REXMT)
    917      1.1  gmcgarry 		return (1);
    918      1.1  gmcgarry 	if (css.c_fef & FEF_PF) {
    919      1.1  gmcgarry 		cs80reset(sc->sc_dev.dv_parent, sc->sc_slave, sc->sc_punit);
    920      1.1  gmcgarry 		return (1);
    921      1.1  gmcgarry 	}
    922      1.1  gmcgarry 	/*
    923      1.1  gmcgarry 	 * Unit requests release for internal maintenance.
    924      1.1  gmcgarry 	 * We just delay awhile and try again later.  Use expontially
    925      1.1  gmcgarry 	 * increasing backoff ala ethernet drivers since we don't really
    926      1.1  gmcgarry 	 * know how long the maintenance will take.  With RDWAITC and
    927      1.1  gmcgarry 	 * RDRETRY as defined, the range is 1 to 32 seconds.
    928      1.1  gmcgarry 	 */
    929      1.1  gmcgarry 	if (css.c_fef & FEF_IMR) {
    930      1.1  gmcgarry 		extern int hz;
    931      1.1  gmcgarry 		int rdtimo = RDWAITC << sc->sc_errcnt;
    932      1.1  gmcgarry 		DPRINTF(RDB_STATUS,
    933      1.1  gmcgarry 		    ("%s: internal maintenance, %d-second timeout\n",
    934      1.1  gmcgarry 		    sc->sc_dev.dv_xname, rdtimo));
    935      1.1  gmcgarry 		gpibrelease(sc->sc_ic, sc->sc_hdl);
    936      1.1  gmcgarry 		callout_reset(&sc->sc_restart_ch, rdtimo * hz, rdrestart, sc);
    937      1.1  gmcgarry 		return (0);
    938      1.1  gmcgarry 	}
    939      1.1  gmcgarry 	/*
    940      1.1  gmcgarry 	 * Only report error if we have reached the error reporting
    941      1.1  gmcgarry 	 * threshhold.  By default, this will only report after the
    942      1.1  gmcgarry 	 * retry limit has been exceeded.
    943      1.1  gmcgarry 	 */
    944      1.1  gmcgarry 	if (sc->sc_errcnt < rderrthresh)
    945      1.1  gmcgarry 		return (1);
    946      1.1  gmcgarry 
    947      1.1  gmcgarry 	/*
    948      1.1  gmcgarry 	 * First conjure up the block number at which the error occurred.
    949      1.1  gmcgarry  	 */
    950      1.1  gmcgarry 	bp = BUFQ_PEEK(&sc->sc_tab);
    951      1.1  gmcgarry 	pbn = sc->sc_dk.dk_label->d_partitions[RDPART(bp->b_dev)].p_offset;
    952      1.1  gmcgarry 	if ((css.c_fef & FEF_CU) || (css.c_fef & FEF_DR) ||
    953      1.1  gmcgarry 	    (css.c_ief & IEF_RRMASK)) {
    954      1.1  gmcgarry 		/*
    955      1.1  gmcgarry 		 * Not all errors report a block number, just use b_blkno.
    956      1.1  gmcgarry 		 */
    957      1.1  gmcgarry 		hwbn = RDBTOS(pbn + bp->b_blkno);
    958      1.1  gmcgarry 		pbn = bp->b_blkno;
    959      1.1  gmcgarry 	} else {
    960      1.1  gmcgarry 		hwbn = css.c_blk;
    961      1.1  gmcgarry 		pbn = RDSTOB(hwbn) - pbn;
    962      1.1  gmcgarry 	}
    963      1.1  gmcgarry #ifdef DEBUG
    964      1.1  gmcgarry 	if (rddebug & RDB_ERROR) {			/* status info */
    965      1.1  gmcgarry 		printf("\n    volume: %d, unit: %d\n",
    966      1.1  gmcgarry 		       (css.c_vu>>4)&0xF, css.c_vu&0xF);
    967      1.1  gmcgarry 		printf("    reject 0x%x\n", css.c_ref);
    968      1.1  gmcgarry 		printf("    fault 0x%x\n", css.c_fef);
    969      1.1  gmcgarry 		printf("    access 0x%x\n", css.c_aef);
    970      1.1  gmcgarry 		printf("    info 0x%x\n", css.c_ief);
    971      1.1  gmcgarry 		printf("    block,  P1-P10: ");
    972      1.1  gmcgarry 		printf("    block: %" PRId64 ", P1-P10: ", hwbn);
    973      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&css.c_raw[0]);
    974      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&css.c_raw[4]);
    975      1.1  gmcgarry 		printf("0x%x\n", *(u_int16_t *)&css.c_raw[8]);
    976      1.1  gmcgarry 	}
    977      1.1  gmcgarry #endif
    978      1.1  gmcgarry #ifdef DEBUG
    979      1.1  gmcgarry 	if (rddebug & RDB_ERROR) {			/* command */
    980      1.1  gmcgarry 		printf("    ioc: ");
    981      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&sc->sc_ioc.c_pad);
    982      1.1  gmcgarry 		printf("0x%x", *(u_int16_t *)&sc->sc_ioc.c_hiaddr);
    983      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&sc->sc_ioc.c_addr);
    984      1.1  gmcgarry 		printf("0x%x", *(u_int16_t *)&sc->sc_ioc.c_nop2);
    985      1.1  gmcgarry 		printf("0x%x", *(u_int32_t *)&sc->sc_ioc.c_len);
    986      1.1  gmcgarry 		printf("0x%x\n", *(u_int16_t *)&sc->sc_ioc.c_cmd);
    987      1.1  gmcgarry 		return (1);
    988      1.1  gmcgarry 	}
    989      1.1  gmcgarry #endif
    990      1.1  gmcgarry 	/*
    991      1.1  gmcgarry 	 * Now output a generic message suitable for badsect.
    992      1.1  gmcgarry 	 * Note that we don't use harderr because it just prints
    993      1.1  gmcgarry 	 * out b_blkno which is just the beginning block number
    994      1.1  gmcgarry 	 * of the transfer, not necessary where the error occurred.
    995      1.1  gmcgarry 	 */
    996      1.1  gmcgarry 	printf("%s%c: hard error, sector number %" PRId64 "\n",
    997      1.1  gmcgarry 	    sc->sc_dev.dv_xname, 'a'+RDPART(bp->b_dev), pbn);
    998      1.1  gmcgarry 	/*
    999      1.1  gmcgarry 	 * Now report the status as returned by the hardware with
   1000      1.1  gmcgarry 	 * attempt at interpretation.
   1001      1.1  gmcgarry 	 */
   1002      1.1  gmcgarry 	printf("%s %s error:", sc->sc_dev.dv_xname,
   1003      1.1  gmcgarry 	    (bp->b_flags & B_READ) ? "read" : "write");
   1004      1.1  gmcgarry 	printf(" unit %d, volume %d R0x%x F0x%x A0x%x I0x%x\n",
   1005      1.1  gmcgarry 	       css.c_vu&0xF, (css.c_vu>>4)&0xF,
   1006      1.1  gmcgarry 	       css.c_ref, css.c_fef, css.c_aef, css.c_ief);
   1007      1.1  gmcgarry 	printf("P1-P10: ");
   1008      1.1  gmcgarry 	printf("0x%x ", *(u_int32_t *)&css.c_raw[0]);
   1009      1.1  gmcgarry 	printf("0x%x ", *(u_int32_t *)&css.c_raw[4]);
   1010      1.1  gmcgarry 	printf("0x%x\n", *(u_int16_t *)&css.c_raw[8]);
   1011      1.1  gmcgarry 
   1012      1.1  gmcgarry 	return (1);
   1013      1.1  gmcgarry }
   1014      1.1  gmcgarry 
   1015      1.1  gmcgarry int
   1016      1.1  gmcgarry rdread(dev, uio, flags)
   1017      1.1  gmcgarry 	dev_t dev;
   1018      1.1  gmcgarry 	struct uio *uio;
   1019      1.1  gmcgarry 	int flags;
   1020      1.1  gmcgarry {
   1021      1.1  gmcgarry 
   1022      1.1  gmcgarry 	return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
   1023      1.1  gmcgarry }
   1024      1.1  gmcgarry 
   1025      1.1  gmcgarry int
   1026      1.1  gmcgarry rdwrite(dev, uio, flags)
   1027      1.1  gmcgarry 	dev_t dev;
   1028      1.1  gmcgarry 	struct uio *uio;
   1029      1.1  gmcgarry 	int flags;
   1030      1.1  gmcgarry {
   1031      1.1  gmcgarry 
   1032      1.1  gmcgarry 	return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
   1033      1.1  gmcgarry }
   1034      1.1  gmcgarry 
   1035      1.1  gmcgarry int
   1036      1.1  gmcgarry rdioctl(dev, cmd, data, flag, p)
   1037      1.1  gmcgarry 	dev_t dev;
   1038      1.1  gmcgarry 	u_long cmd;
   1039      1.1  gmcgarry 	caddr_t data;
   1040      1.1  gmcgarry 	int flag;
   1041      1.1  gmcgarry 	struct proc *p;
   1042      1.1  gmcgarry {
   1043      1.1  gmcgarry 	struct rd_softc *sc;
   1044      1.1  gmcgarry 	struct disklabel *lp;
   1045      1.1  gmcgarry 	int error, flags;
   1046      1.1  gmcgarry 
   1047      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(dev));
   1048      1.1  gmcgarry 	if (sc == NULL)
   1049      1.1  gmcgarry 		return (ENXIO);
   1050      1.1  gmcgarry 	lp = sc->sc_dk.dk_label;
   1051      1.1  gmcgarry 
   1052      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rdioctl: sc=%p\n", sc));
   1053      1.1  gmcgarry 
   1054      1.1  gmcgarry 	switch (cmd) {
   1055      1.1  gmcgarry 	case DIOCGDINFO:
   1056      1.1  gmcgarry 		*(struct disklabel *)data = *lp;
   1057      1.1  gmcgarry 		return (0);
   1058      1.1  gmcgarry 
   1059      1.1  gmcgarry 	case DIOCGPART:
   1060      1.1  gmcgarry 		((struct partinfo *)data)->disklab = lp;
   1061      1.1  gmcgarry 		((struct partinfo *)data)->part =
   1062      1.1  gmcgarry 		    &lp->d_partitions[RDPART(dev)];
   1063      1.1  gmcgarry 		return (0);
   1064      1.1  gmcgarry 
   1065      1.1  gmcgarry 	case DIOCWLABEL:
   1066      1.1  gmcgarry 		if ((flag & FWRITE) == 0)
   1067      1.1  gmcgarry 			return (EBADF);
   1068      1.1  gmcgarry 		if (*(int *)data)
   1069      1.1  gmcgarry 			sc->sc_flags |= RDF_WLABEL;
   1070      1.1  gmcgarry 		else
   1071      1.1  gmcgarry 			sc->sc_flags &= ~RDF_WLABEL;
   1072      1.1  gmcgarry 		return (0);
   1073      1.1  gmcgarry 
   1074      1.1  gmcgarry 	case DIOCSDINFO:
   1075      1.1  gmcgarry 		if ((flag & FWRITE) == 0)
   1076      1.1  gmcgarry 			return (EBADF);
   1077      1.1  gmcgarry 		return (setdisklabel(lp, (struct disklabel *)data,
   1078      1.1  gmcgarry 		    (sc->sc_flags & RDF_WLABEL) ? 0 : sc->sc_dk.dk_openmask,
   1079      1.1  gmcgarry 		    (struct cpu_disklabel *)0));
   1080      1.1  gmcgarry 
   1081      1.1  gmcgarry 	case DIOCWDINFO:
   1082      1.1  gmcgarry 		if ((flag & FWRITE) == 0)
   1083      1.1  gmcgarry 			return (EBADF);
   1084      1.1  gmcgarry 		error = setdisklabel(lp, (struct disklabel *)data,
   1085      1.1  gmcgarry 		    (sc->sc_flags & RDF_WLABEL) ? 0 : sc->sc_dk.dk_openmask,
   1086      1.1  gmcgarry 		    (struct cpu_disklabel *)0);
   1087      1.1  gmcgarry 		if (error)
   1088      1.1  gmcgarry 			return (error);
   1089      1.1  gmcgarry 		flags = sc->sc_flags;
   1090      1.1  gmcgarry 		sc->sc_flags = RDF_ALIVE | RDF_WLABEL;
   1091      1.1  gmcgarry 		error = writedisklabel(RDLABELDEV(dev), rdstrategy, lp,
   1092      1.1  gmcgarry 		    (struct cpu_disklabel *)0);
   1093      1.1  gmcgarry 		sc->sc_flags = flags;
   1094      1.1  gmcgarry 		return (error);
   1095      1.1  gmcgarry 
   1096      1.1  gmcgarry 	case DIOCGDEFLABEL:
   1097      1.1  gmcgarry 		rdgetdefaultlabel(sc, (struct disklabel *)data);
   1098      1.1  gmcgarry 		return (0);
   1099      1.1  gmcgarry 	}
   1100      1.1  gmcgarry 	return (EINVAL);
   1101      1.1  gmcgarry }
   1102      1.1  gmcgarry 
   1103      1.1  gmcgarry void
   1104      1.1  gmcgarry rdgetdefaultlabel(sc, lp)
   1105      1.1  gmcgarry 	struct rd_softc *sc;
   1106      1.1  gmcgarry 	struct disklabel *lp;
   1107      1.1  gmcgarry {
   1108      1.1  gmcgarry 	int type = sc->sc_type;
   1109      1.1  gmcgarry 
   1110      1.1  gmcgarry 	memset((caddr_t)lp, 0, sizeof(struct disklabel));
   1111      1.1  gmcgarry 
   1112      1.1  gmcgarry 	lp->d_type = DTYPE_GPIB;
   1113      1.1  gmcgarry 	lp->d_secsize = DEV_BSIZE;
   1114      1.1  gmcgarry 	lp->d_nsectors = rdidentinfo[type].ri_nbpt;
   1115      1.1  gmcgarry 	lp->d_ntracks = rdidentinfo[type].ri_ntpc;
   1116      1.1  gmcgarry 	lp->d_ncylinders = rdidentinfo[type].ri_ncyl;
   1117      1.1  gmcgarry 	lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
   1118      1.1  gmcgarry 	lp->d_secperunit = lp->d_ncylinders * lp->d_secpercyl;
   1119      1.1  gmcgarry 
   1120      1.1  gmcgarry 	strncpy(lp->d_typename, rdidentinfo[type].ri_desc, 16);
   1121      1.1  gmcgarry 	strncpy(lp->d_packname, "fictitious", 16);
   1122      1.1  gmcgarry 	lp->d_rpm = 3000;
   1123      1.1  gmcgarry 	lp->d_interleave = 1;
   1124      1.1  gmcgarry 	lp->d_flags = 0;
   1125      1.1  gmcgarry 
   1126      1.1  gmcgarry 	lp->d_partitions[RAW_PART].p_offset = 0;
   1127      1.1  gmcgarry 	lp->d_partitions[RAW_PART].p_size =
   1128      1.1  gmcgarry 	    lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
   1129      1.1  gmcgarry 	lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
   1130      1.1  gmcgarry 	lp->d_npartitions = RAW_PART + 1;
   1131      1.1  gmcgarry 
   1132      1.1  gmcgarry 	lp->d_magic = DISKMAGIC;
   1133      1.1  gmcgarry 	lp->d_magic2 = DISKMAGIC;
   1134      1.1  gmcgarry 	lp->d_checksum = dkcksum(lp);
   1135      1.1  gmcgarry }
   1136      1.1  gmcgarry 
   1137      1.1  gmcgarry int
   1138      1.1  gmcgarry rdsize(dev)
   1139      1.1  gmcgarry 	dev_t dev;
   1140      1.1  gmcgarry {
   1141      1.1  gmcgarry 	struct rd_softc *sc;
   1142      1.1  gmcgarry 	int psize, didopen = 0;
   1143      1.1  gmcgarry 
   1144      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(dev));
   1145      1.1  gmcgarry 	if (sc == NULL || (sc->sc_flags & RDF_ALIVE) == 0)
   1146      1.1  gmcgarry 		return (-1);
   1147      1.1  gmcgarry 
   1148      1.1  gmcgarry 	/*
   1149      1.1  gmcgarry 	 * We get called very early on (via swapconf)
   1150      1.1  gmcgarry 	 * without the device being open so we may need
   1151      1.1  gmcgarry 	 * to handle it here.
   1152      1.1  gmcgarry 	 */
   1153      1.1  gmcgarry 	if (sc->sc_dk.dk_openmask == 0) {
   1154      1.1  gmcgarry 		if (rdopen(dev, FREAD | FWRITE, S_IFBLK, NULL))
   1155      1.1  gmcgarry 			return (-1);
   1156      1.1  gmcgarry 		didopen = 1;
   1157      1.1  gmcgarry 	}
   1158      1.1  gmcgarry 	psize = sc->sc_dk.dk_label->d_partitions[RDPART(dev)].p_size *
   1159      1.1  gmcgarry 	    (sc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
   1160      1.1  gmcgarry 	if (didopen)
   1161      1.1  gmcgarry 		(void) rdclose(dev, FREAD | FWRITE, S_IFBLK, NULL);
   1162      1.1  gmcgarry 	return (psize);
   1163      1.1  gmcgarry }
   1164      1.1  gmcgarry 
   1165      1.1  gmcgarry 
   1166      1.1  gmcgarry static int rddoingadump;	/* simple mutex */
   1167      1.1  gmcgarry 
   1168      1.1  gmcgarry /*
   1169      1.1  gmcgarry  * Non-interrupt driven, non-dma dump routine.
   1170      1.1  gmcgarry  */
   1171      1.1  gmcgarry int
   1172      1.1  gmcgarry rddump(dev, blkno, va, size)
   1173      1.1  gmcgarry 	dev_t dev;
   1174      1.1  gmcgarry 	daddr_t blkno;
   1175      1.1  gmcgarry 	caddr_t va;
   1176      1.1  gmcgarry 	size_t size;
   1177      1.1  gmcgarry {
   1178      1.1  gmcgarry 	struct rd_softc *sc;
   1179      1.1  gmcgarry 	int sectorsize;		/* size of a disk sector */
   1180      1.1  gmcgarry 	int nsects;		/* number of sectors in partition */
   1181      1.1  gmcgarry 	int sectoff;		/* sector offset of partition */
   1182      1.1  gmcgarry 	int totwrt;		/* total number of sectors left to write */
   1183      1.1  gmcgarry 	int nwrt;		/* current number of sectors to write */
   1184      1.1  gmcgarry 	int slave;
   1185      1.1  gmcgarry 	struct disklabel *lp;
   1186      1.1  gmcgarry 	u_int8_t stat;
   1187      1.1  gmcgarry 
   1188      1.1  gmcgarry 	/* Check for recursive dump; if so, punt. */
   1189      1.1  gmcgarry 	if (rddoingadump)
   1190      1.1  gmcgarry 		return (EFAULT);
   1191      1.1  gmcgarry 	rddoingadump = 1;
   1192      1.1  gmcgarry 
   1193      1.1  gmcgarry 	sc = device_lookup(&rd_cd, RDUNIT(dev));
   1194      1.1  gmcgarry 	if (sc == NULL || (sc->sc_flags & RDF_ALIVE) == 0)
   1195      1.1  gmcgarry 		return (ENXIO);
   1196      1.1  gmcgarry 
   1197      1.1  gmcgarry 	DPRINTF(RDB_FOLLOW, ("rddump: sc=%p\n", sc));
   1198      1.1  gmcgarry 
   1199      1.1  gmcgarry 	slave = sc->sc_slave;
   1200      1.1  gmcgarry 
   1201      1.1  gmcgarry 	/*
   1202      1.1  gmcgarry 	 * Convert to disk sectors.  Request must be a multiple of size.
   1203      1.1  gmcgarry 	 */
   1204      1.1  gmcgarry 	lp = sc->sc_dk.dk_label;
   1205      1.1  gmcgarry 	sectorsize = lp->d_secsize;
   1206      1.1  gmcgarry 	if ((size % sectorsize) != 0)
   1207      1.1  gmcgarry 		return (EFAULT);
   1208      1.1  gmcgarry 	totwrt = size / sectorsize;
   1209      1.1  gmcgarry 	blkno = dbtob(blkno) / sectorsize;	/* blkno in DEV_BSIZE units */
   1210      1.1  gmcgarry 
   1211      1.1  gmcgarry 	nsects = lp->d_partitions[RDPART(dev)].p_size;
   1212      1.1  gmcgarry 	sectoff = lp->d_partitions[RDPART(dev)].p_offset;
   1213      1.1  gmcgarry 
   1214      1.1  gmcgarry 	/* Check transfer bounds against partition size. */
   1215      1.1  gmcgarry 	if ((blkno < 0) || (blkno + totwrt) > nsects)
   1216      1.1  gmcgarry 		return (EINVAL);
   1217      1.1  gmcgarry 
   1218      1.1  gmcgarry 	/* Offset block number to start of partition. */
   1219      1.1  gmcgarry 	blkno += sectoff;
   1220      1.1  gmcgarry 
   1221      1.1  gmcgarry 	while (totwrt > 0) {
   1222      1.1  gmcgarry 		nwrt = totwrt;		/* XXX */
   1223      1.1  gmcgarry #ifndef RD_DUMP_NOT_TRUSTED
   1224      1.1  gmcgarry 		/*
   1225      1.1  gmcgarry 		 * Fill out and send GPIB command.
   1226      1.1  gmcgarry 		 */
   1227      1.1  gmcgarry 		sc->sc_ioc.c_unit = CS80CMD_SUNIT(sc->sc_punit);
   1228      1.1  gmcgarry 		sc->sc_ioc.c_volume = CS80CMD_SVOL(0);
   1229      1.1  gmcgarry 		sc->sc_ioc.c_saddr = CS80CMD_SADDR;
   1230      1.1  gmcgarry 		sc->sc_ioc.c_hiaddr = 0;
   1231      1.1  gmcgarry 		sc->sc_ioc.c_addr = RDBTOS(blkno);
   1232      1.1  gmcgarry 		sc->sc_ioc.c_nop2 = CS80CMD_NOP;
   1233      1.1  gmcgarry 		sc->sc_ioc.c_slen = CS80CMD_SLEN;
   1234      1.1  gmcgarry 		sc->sc_ioc.c_len = nwrt * sectorsize;
   1235      1.1  gmcgarry 		sc->sc_ioc.c_cmd = CS80CMD_WRITE;
   1236      1.1  gmcgarry 		(void) gpibsend(sc->sc_ic, slave, CS80CMD_SCMD,
   1237      1.1  gmcgarry 		    &sc->sc_ioc.c_unit, sizeof(sc->sc_ioc)-3);
   1238      1.1  gmcgarry 		if (gpibswait(sc->sc_ic, slave))
   1239      1.1  gmcgarry 			return (EIO);
   1240      1.1  gmcgarry 		/*
   1241      1.1  gmcgarry 		 * Send the data.
   1242      1.1  gmcgarry 		 */
   1243      1.1  gmcgarry 		(void) gpibsend(sc->sc_ic, slave, CS80CMD_EXEC, va,
   1244      1.1  gmcgarry 		    nwrt * sectorsize);
   1245      1.1  gmcgarry 		(void) gpibswait(sc->sc_ic, slave);
   1246      1.1  gmcgarry 		(void) gpibrecv(sc->sc_ic, slave, CS80CMD_QSTAT, &stat, 1);
   1247      1.1  gmcgarry 		if (stat)
   1248      1.1  gmcgarry 			return (EIO);
   1249      1.1  gmcgarry #else /* RD_DUMP_NOT_TRUSTED */
   1250      1.1  gmcgarry 		/* Let's just talk about this first... */
   1251      1.1  gmcgarry 		printf("%s: dump addr %p, blk %d\n", sc->sc_dev.dv_xname,
   1252      1.1  gmcgarry 		    va, blkno);
   1253      1.1  gmcgarry 		delay(500 * 1000);	/* half a second */
   1254      1.1  gmcgarry #endif /* RD_DUMP_NOT_TRUSTED */
   1255      1.1  gmcgarry 
   1256      1.1  gmcgarry 		/* update block count */
   1257      1.1  gmcgarry 		totwrt -= nwrt;
   1258      1.1  gmcgarry 		blkno += nwrt;
   1259      1.1  gmcgarry 		va += sectorsize * nwrt;
   1260      1.1  gmcgarry 	}
   1261      1.1  gmcgarry 	rddoingadump = 0;
   1262      1.1  gmcgarry 	return (0);
   1263      1.1  gmcgarry }
   1264      1.1  gmcgarry 
   1265      1.1  gmcgarry #ifdef COMPAT_NOLABEL
   1266      1.1  gmcgarry 
   1267      1.1  gmcgarry /*
   1268      1.1  gmcgarry  * CS/80 partitions.  We reserve the first cylinder for a LIF
   1269      1.1  gmcgarry  * style boot directory (the 8k allowed in the BSD filesystem
   1270      1.1  gmcgarry  * is just way too small).  This boot area is outside of all but
   1271      1.1  gmcgarry  * the C partition.  This implies that you cannot use the C
   1272      1.1  gmcgarry  * partition on a bootable disk since the filesystem would overlay
   1273      1.1  gmcgarry  * the boot area.  You must use the A partition.
   1274      1.1  gmcgarry  *
   1275      1.1  gmcgarry  * These maps support four basic layouts:
   1276      1.1  gmcgarry  *
   1277      1.1  gmcgarry  *	A/B/G:   This is the "traditional" setup for a bootable disk.
   1278      1.1  gmcgarry  *	         A is the root partition, B the swap, and G a user partition.
   1279      1.1  gmcgarry  *	A/D/H:   This is a setup for bootable systems requiring more swap
   1280      1.1  gmcgarry  *		 (e.g. those who use HPCL).  It has A as the root, D as a
   1281      1.1  gmcgarry  *		 larger swap, and H as a smaller user partition.
   1282      1.1  gmcgarry  *	A/D/E/F: Similar to A/D/H with E and F breaking H into two partitions.
   1283      1.1  gmcgarry  *		 E could be used for /usr and F for users.
   1284      1.1  gmcgarry  *	C:       This gives a single, non-bootable, large user filesystem.
   1285      1.1  gmcgarry  *	         Good for second drives on a machine (e.g. /usr/src).
   1286      1.1  gmcgarry  */
   1287      1.1  gmcgarry struct	size {
   1288      1.1  gmcgarry 	daddr_t	nblocks;
   1289      1.1  gmcgarry 	int	cyloff;
   1290      1.1  gmcgarry } rd7945A_sizes[8] = {
   1291      1.1  gmcgarry 	{ RDSZ(15904),	1	},	/* A=cyl 1 thru 142 */
   1292      1.1  gmcgarry 	{ RDSZ(20160),	143	},	/* B=cyl 143 thru 322 */
   1293      1.1  gmcgarry 	{ RDSZ(108416),	0	},	/* C=cyl 0 thru 967 */
   1294      1.1  gmcgarry 	{ RDSZ(40320),	143	},	/* D=cyl 143 thru 502 */
   1295      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* E=<undefined> */
   1296      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* F=<undefined> */
   1297      1.1  gmcgarry 	{ RDSZ(72240),	323	},	/* G=cyl 323 thru 967 */
   1298      1.1  gmcgarry 	{ RDSZ(52080),	503	},	/* H=cyl 503 thru 967 */
   1299      1.1  gmcgarry }, rd9134D_sizes[8] = {
   1300      1.1  gmcgarry 	{ RDSZ(15936),	1	},	/* A=cyl 1 thru 166 */
   1301      1.1  gmcgarry 	{ RDSZ(13056),	167	},	/* B=cyl 167 thru 302 */
   1302      1.1  gmcgarry 	{ RDSZ(29088),	0	},	/* C=cyl 0 thru 302 */
   1303      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* D=<undefined> */
   1304      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* E=<undefined> */
   1305      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* F=<undefined> */
   1306      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* G=<undefined> */
   1307      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* H=<undefined> */
   1308      1.1  gmcgarry }, rd9122S_sizes[8] = {
   1309      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* A=<undefined> */
   1310      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* B=<undefined> */
   1311      1.1  gmcgarry 	{ RDSZ(1232),	0	},	/* C=cyl 0 thru 76 */
   1312      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* D=<undefined> */
   1313      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* E=<undefined> */
   1314      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* F=<undefined> */
   1315      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* G=<undefined> */
   1316      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* H=<undefined> */
   1317      1.1  gmcgarry }, rd7912P_sizes[8] = {
   1318      1.1  gmcgarry 	{ RDSZ(15904),	0	},	/* A=cyl 1 thru 71 */
   1319      1.1  gmcgarry 	{ RDSZ(22400),	72	},	/* B=cyl 72 thru 171 */
   1320      1.1  gmcgarry 	{ RDSZ(128128),	0	},	/* C=cyl 0 thru 571 */
   1321      1.1  gmcgarry 	{ RDSZ(42560),	72	},	/* D=cyl 72 thru 261 */
   1322      1.1  gmcgarry 	{ RDSZ(0),	292	},	/* E=<undefined> */
   1323      1.1  gmcgarry 	{ RDSZ(0),	542	},	/* F=<undefined> */
   1324      1.1  gmcgarry 	{ RDSZ(89600),	172	},	/* G=cyl 221 thru 571 */
   1325      1.1  gmcgarry 	{ RDSZ(69440),	262	},	/* H=cyl 262 thru 571 */
   1326      1.1  gmcgarry }, rd7914P_sizes[8] = {
   1327      1.1  gmcgarry 	{ RDSZ(15904),	1	},	/* A=cyl 1 thru 71 */
   1328      1.1  gmcgarry 	{ RDSZ(40320),	72	},	/* B=cyl 72 thru 251 */
   1329      1.1  gmcgarry 	{ RDSZ(258048),	0	},	/* C=cyl 0 thru 1151 */
   1330      1.1  gmcgarry 	{ RDSZ(64960),	72	},	/* D=cyl 72 thru 361 */
   1331      1.1  gmcgarry 	{ RDSZ(98560),	362	},	/* E=cyl 362 thru 801 */
   1332      1.1  gmcgarry 	{ RDSZ(78400),	802	},	/* F=cyl 802 thru 1151 */
   1333      1.1  gmcgarry 	{ RDSZ(201600),	252	},	/* G=cyl 221 thru 1151 */
   1334      1.1  gmcgarry 	{ RDSZ(176960),	362	},	/* H=cyl 362 thru 1151 */
   1335      1.1  gmcgarry }, rd7933H_sizes[8] = {
   1336      1.1  gmcgarry 	{ RDSZ(16146),	1	},	/* A=cyl 1 thru 27 */
   1337      1.1  gmcgarry 	{ RDSZ(66976),	28	},	/* B=cyl 28 thru 139 */
   1338      1.1  gmcgarry 	{ RDSZ(789958),	0	},	/* C=cyl 0 thru 1320 */
   1339      1.1  gmcgarry 	{ RDSZ(16146),	140	},	/* D=cyl 140 thru 166 */
   1340      1.1  gmcgarry 	{ RDSZ(165646),	167	},	/* E=cyl 167 thru 443 */
   1341      1.1  gmcgarry 	{ RDSZ(165646),	444	},	/* F=cyl 444 thru 720 */
   1342      1.1  gmcgarry 	{ RDSZ(706238),	140	},	/* G=cyl 140 thru 1320 */
   1343      1.1  gmcgarry 	{ RDSZ(358800),	721	},	/* H=cyl 721 thru 1320 */
   1344      1.1  gmcgarry }, rd9134L_sizes[8] = {
   1345      1.1  gmcgarry 	{ RDSZ(15920),	1	},	/* A=cyl 1 thru 199 */
   1346      1.1  gmcgarry 	{ RDSZ(20000),	200	},	/* B=cyl 200 thru 449 */
   1347      1.1  gmcgarry 	{ RDSZ(77840),	0	},	/* C=cyl 0 thru 972 */
   1348      1.1  gmcgarry 	{ RDSZ(32000),	200	},	/* D=cyl 200 thru 599 */
   1349      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* E=<undefined> */
   1350      1.1  gmcgarry 	{ RDSZ(0),	0	},	/* F=<undefined> */
   1351      1.1  gmcgarry 	{ RDSZ(41840),	450	},	/* G=cyl 450 thru 972 */
   1352      1.1  gmcgarry 	{ RDSZ(29840),	600	},	/* H=cyl 600 thru 972 */
   1353      1.1  gmcgarry }, rd7957A_sizes[8] = {
   1354      1.1  gmcgarry 	{ RDSZ(16016),	1	},	/* A=cyl 1 thru 104 */
   1355      1.1  gmcgarry 	{ RDSZ(24640),	105	},	/* B=cyl 105 thru 264 */
   1356      1.1  gmcgarry 	{ RDSZ(159544),	0	},	/* C=cyl 0 thru 1035 */
   1357      1.1  gmcgarry 	{ RDSZ(42350),	105	},	/* D=cyl 105 thru 379 */
   1358      1.1  gmcgarry 	{ RDSZ(54824),	380	},	/* E=cyl 380 thru 735 */
   1359      1.1  gmcgarry 	{ RDSZ(46200),	736	},	/* F=cyl 736 thru 1035 */
   1360      1.1  gmcgarry 	{ RDSZ(118734),	265	},	/* G=cyl 265 thru 1035 */
   1361      1.1  gmcgarry 	{ RDSZ(101024),	380	},	/* H=cyl 380 thru 1035 */
   1362      1.1  gmcgarry }, rd7958A_sizes[8] = {
   1363      1.1  gmcgarry 	{ RDSZ(16128),	1	},	/* A=cyl 1 thru 64 */
   1364      1.1  gmcgarry 	{ RDSZ(32256),	65	},	/* B=cyl 65 thru 192 */
   1365      1.1  gmcgarry 	{ RDSZ(255276),	0	},	/* C=cyl 0 thru 1012 */
   1366      1.1  gmcgarry 	{ RDSZ(48384),	65	},	/* D=cyl 65 thru 256 */
   1367      1.1  gmcgarry 	{ RDSZ(100800),	257	},	/* E=cyl 257 thru 656 */
   1368      1.1  gmcgarry 	{ RDSZ(89712),	657	},	/* F=cyl 657 thru 1012 */
   1369      1.1  gmcgarry 	{ RDSZ(206640),	193	},	/* G=cyl 193 thru 1012 */
   1370      1.1  gmcgarry 	{ RDSZ(190512),	257	},	/* H=cyl 257 thru 1012 */
   1371      1.1  gmcgarry }, rd7957B_sizes[8] = {
   1372      1.1  gmcgarry 	{ RDSZ(16002),	1	},	/* A=cyl 1 thru 127 */
   1373      1.1  gmcgarry 	{ RDSZ(32760),	128	},	/* B=cyl 128 thru 387 */
   1374      1.1  gmcgarry 	{ RDSZ(159894),	0	},	/* C=cyl 0 thru 1268 */
   1375      1.1  gmcgarry 	{ RDSZ(49140),	128	},	/* D=cyl 128 thru 517 */
   1376      1.1  gmcgarry 	{ RDSZ(50400),	518	},	/* E=cyl 518 thru 917 */
   1377      1.1  gmcgarry 	{ RDSZ(44226),	918	},	/* F=cyl 918 thru 1268 */
   1378      1.1  gmcgarry 	{ RDSZ(111006),	388	},	/* G=cyl 388 thru 1268 */
   1379      1.1  gmcgarry 	{ RDSZ(94626),	518	},	/* H=cyl 518 thru 1268 */
   1380      1.1  gmcgarry }, rd7958B_sizes[8] = {
   1381      1.1  gmcgarry 	{ RDSZ(16254),	1	},	/* A=cyl 1 thru 43 */
   1382      1.1  gmcgarry 	{ RDSZ(32886),	44	},	/* B=cyl 44 thru 130 */
   1383      1.1  gmcgarry 	{ RDSZ(297108),	0	},	/* C=cyl 0 thru 785 */
   1384      1.1  gmcgarry 	{ RDSZ(49140),	44	},	/* D=cyl 44 thru 173 */
   1385      1.1  gmcgarry 	{ RDSZ(121716),	174	},	/* E=cyl 174 thru 495 */
   1386      1.1  gmcgarry 	{ RDSZ(109620),	496	},	/* F=cyl 496 thru 785 */
   1387      1.1  gmcgarry 	{ RDSZ(247590),	131	},	/* G=cyl 131 thru 785 */
   1388      1.1  gmcgarry 	{ RDSZ(231336),	174	},	/* H=cyl 174 thru 785 */
   1389      1.1  gmcgarry }, rd7959B_sizes[8] = {
   1390      1.1  gmcgarry 	{ RDSZ(16254),	1	},	/* A=cyl 1 thru 43 */
   1391      1.1  gmcgarry 	{ RDSZ(49140),	44	},	/* B=cyl 44 thru 173 */
   1392      1.1  gmcgarry 	{ RDSZ(594216),	0	},	/* C=cyl 0 thru 1571 */
   1393      1.1  gmcgarry 	{ RDSZ(65772),	44	},	/* D=cyl 44 thru 217 */
   1394      1.1  gmcgarry 	{ RDSZ(303912),	218	},	/* E=cyl 218 thru 1021 */
   1395      1.1  gmcgarry 	{ RDSZ(207900),	1022	},	/* F=cyl 1022 thru 1571 */
   1396      1.1  gmcgarry 	{ RDSZ(528444),	174	},	/* G=cyl 174 thru 1571 */
   1397      1.1  gmcgarry 	{ RDSZ(511812),	218	},	/* H=cyl 218 thru 1571 */
   1398      1.1  gmcgarry }, rd2200A_sizes[8] = {
   1399      1.1  gmcgarry 	{ RDSZ(16272),	1	},	/* A=cyl 1 thru 36 */
   1400      1.1  gmcgarry 	{ RDSZ(49720),	37	},	/* B=cyl 37 thru 146 */
   1401      1.1  gmcgarry 	{ RDSZ(654948),	0	},	/* C=cyl 0 thru 1448 */
   1402      1.1  gmcgarry 	{ RDSZ(65992),	37	},	/* D=cyl 37 thru 182 */
   1403      1.1  gmcgarry 	{ RDSZ(304648),	183	},	/* E=cyl 183 thru 856 */
   1404      1.1  gmcgarry 	{ RDSZ(267584),	857	},	/* F=cyl 857 thru 1448 */
   1405      1.1  gmcgarry 	{ RDSZ(588504),	147	},	/* G=cyl 147 thru 1448 */
   1406      1.1  gmcgarry 	{ RDSZ(572232),	183	},	/* H=cyl 183 thru 1448 */
   1407      1.1  gmcgarry }, rd2203A_sizes[8] = {
   1408      1.1  gmcgarry 	/* modelled after the 7937; i.e. bogus */
   1409      1.1  gmcgarry 	{ RDSZ(16272),	1	},	/* A=cyl 1 thru 18 */
   1410      1.1  gmcgarry 	{ RDSZ(67800),	19	},	/* B=cyl 19 thru 93 */
   1411      1.1  gmcgarry 	{ RDSZ(1309896), 0	},	/* C=cyl 0 thru 1448 */
   1412      1.1  gmcgarry 	{ RDSZ(16272),	94	},	/* D=cyl 19 thru 111 */
   1413      1.1  gmcgarry 	{ RDSZ(305552),	112	},	/* E=cyl 112 thru 449 */
   1414      1.1  gmcgarry 	{ RDSZ(305552),	450	},	/* F=cyl 450 thru 787 */
   1415      1.1  gmcgarry 	{ RDSZ(1224920), 94	},	/* G=cyl 94 thru 1448 */
   1416      1.1  gmcgarry 	{ RDSZ(597544),	788	},	/* H=cyl 788 thru 1448 */
   1417      1.1  gmcgarry }, rd7936H_sizes[8] = {
   1418      1.1  gmcgarry 	{ RDSZ(16359),	1	},	/* A=cyl 1 thru 19 */
   1419      1.1  gmcgarry 	{ RDSZ(67158),	20	},	/* B=cyl 20 thru 97 */
   1420      1.1  gmcgarry 	{ RDSZ(600978),	0	},	/* C=cyl 0 thru 697 */
   1421      1.1  gmcgarry 	{ RDSZ(16359),	98	},	/* D=cyl 98 thru 116 */
   1422      1.1  gmcgarry 	{ RDSZ(120540),	117	},	/* E=cyl 117 thru 256 */
   1423      1.1  gmcgarry 	{ RDSZ(120540),	256	},	/* F=cyl 256 thru 396 */
   1424      1.1  gmcgarry 	{ RDSZ(516600),	98	},	/* G=cyl 98 thru 697 */
   1425      1.1  gmcgarry 	{ RDSZ(259161),	397	},	/* H=cyl 397 thru 697 */
   1426      1.1  gmcgarry }, rd7937H_sizes[8] = {
   1427      1.1  gmcgarry 	{ RDSZ(15990),	1	},	/* A=cyl 1 thru 10 */
   1428      1.1  gmcgarry 	{ RDSZ(67158),	11	},	/* B=cyl 11 thru 52 */
   1429      1.1  gmcgarry 	{ RDSZ(1116102), 0	},	/* C=cyl 0 thru 697 */
   1430      1.1  gmcgarry 	{ RDSZ(124722),	53	},	/* D=cyl 53 thru 130 */
   1431      1.1  gmcgarry 	{ RDSZ(163098),	131	},	/* E=cyl 131 thru 232 */
   1432      1.1  gmcgarry 	{ RDSZ(287820),	233	},	/* F=cyl 233 thru 412 */
   1433      1.1  gmcgarry 	{ RDSZ(1031355), 53	},	/* G=cyl 53 thru 697 */
   1434      1.1  gmcgarry 	{ RDSZ(455715),	413	},	/* H=cyl 413 thru 697 */
   1435      1.1  gmcgarry };
   1436      1.1  gmcgarry 
   1437      1.1  gmcgarry /*
   1438      1.1  gmcgarry  * Indexed the same as rdidentinfo array.
   1439      1.1  gmcgarry  */
   1440      1.1  gmcgarry struct rdcompatinfo {
   1441      1.1  gmcgarry 	struct size *sizes;	/* partition info */
   1442      1.1  gmcgarry } rdcompatinfo[] = {
   1443      1.1  gmcgarry 	{ rd7945A_sizes },
   1444      1.1  gmcgarry 	{ rd9134D_sizes },
   1445      1.1  gmcgarry 	{ rd9122S_sizes },
   1446      1.1  gmcgarry 	{ rd7912P_sizes },
   1447      1.1  gmcgarry 	{ rd7914P_sizes },
   1448      1.1  gmcgarry 	{ rd7958A_sizes },
   1449      1.1  gmcgarry 	{ rd7957A_sizes },
   1450      1.1  gmcgarry 	{ rd7933H_sizes },
   1451      1.1  gmcgarry 	{ rd9134L_sizes },
   1452      1.1  gmcgarry 	{ rd7936H_sizes },
   1453      1.1  gmcgarry 	{ rd7937H_sizes },
   1454      1.1  gmcgarry 	{ rd7914P_sizes },
   1455      1.1  gmcgarry 	{ rd7945A_sizes },
   1456      1.1  gmcgarry 	{ rd9122S_sizes },
   1457      1.1  gmcgarry 	{ rd7957B_sizes },
   1458      1.1  gmcgarry 	{ rd7958B_sizes },
   1459      1.1  gmcgarry 	{ rd7959B_sizes },
   1460      1.1  gmcgarry 	{ rd2200A_sizes },
   1461      1.1  gmcgarry 	{ rd2203A_sizes },
   1462      1.1  gmcgarry };
   1463      1.1  gmcgarry int nrdcompatinfo = sizeof(rdcompatinfo) / sizeof(rdcompatinfo[0]);
   1464      1.1  gmcgarry 
   1465      1.1  gmcgarry void
   1466      1.1  gmcgarry rdgetcompatlabel(sc, lp)
   1467      1.1  gmcgarry 	struct rd_softc *sc;
   1468      1.1  gmcgarry 	struct disklabel *lp;
   1469      1.1  gmcgarry {
   1470      1.1  gmcgarry 	struct rdcompatinfo *ci = &rdcompatinfo[sc->sc_type];
   1471      1.1  gmcgarry 	const struct rdidentinfo *ri = &rdidentinfo[sc->sc_type];
   1472      1.1  gmcgarry 	struct partition *pi;
   1473      1.1  gmcgarry 	int dcount;
   1474      1.1  gmcgarry 
   1475      1.1  gmcgarry 	rdgetdefaultlabel(sc, lp);
   1476      1.1  gmcgarry 
   1477      1.1  gmcgarry 	lp->d_npartitions = 8;
   1478      1.1  gmcgarry 	pi = lp->d_partitions;
   1479      1.1  gmcgarry 	for (dcount = 0; dcount < lp->d_npartitions; dcount++) {
   1480      1.1  gmcgarry 		pi->p_size = ci->sizes[dcount].nblocks;
   1481      1.1  gmcgarry 		pi->p_offset = ci->sizes[dcount].cyloff * lp->d_secpercyl;
   1482      1.1  gmcgarry 		pi->p_fsize = 1024;
   1483      1.1  gmcgarry 		if (dcount == 1 || dcount == 3)
   1484      1.1  gmcgarry 			pi->p_fstype = FS_SWAP;
   1485      1.1  gmcgarry 		else if (dcount == 2)
   1486      1.1  gmcgarry 			pi->p_fstype = FS_BOOT;
   1487      1.1  gmcgarry 		else
   1488      1.1  gmcgarry 			pi->p_fstype = FS_BSDFFS;
   1489      1.1  gmcgarry 		pi->p_frag = 8;
   1490      1.1  gmcgarry 		pi++;
   1491      1.1  gmcgarry 	}
   1492      1.1  gmcgarry }
   1493      1.1  gmcgarry 
   1494      1.1  gmcgarry #endif /* COMPAT_NOLABEL */
   1495