Home | History | Annotate | Line # | Download | only in common
rd.c revision 1.1.60.4
      1  1.1.60.4    skrll /*	$NetBSD: rd.c,v 1.1.60.4 2004/09/21 13:15:27 skrll Exp $	*/
      2       1.1  thorpej 
      3       1.1  thorpej /*
      4       1.1  thorpej  * Copyright (c) 1982, 1990, 1993
      5       1.1  thorpej  *	The Regents of the University of California.  All rights reserved.
      6       1.1  thorpej  *
      7       1.1  thorpej  * This code is derived from software contributed to Berkeley by
      8       1.1  thorpej  * the Systems Programming Group of the University of Utah Computer
      9       1.1  thorpej  * Science Department.
     10       1.1  thorpej  *
     11       1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     12       1.1  thorpej  * modification, are permitted provided that the following conditions
     13       1.1  thorpej  * are met:
     14       1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     15       1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     16       1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     18       1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1.60.1    skrll  * 3. Neither the name of the University nor the names of its contributors
     20  1.1.60.1    skrll  *    may be used to endorse or promote products derived from this software
     21  1.1.60.1    skrll  *    without specific prior written permission.
     22  1.1.60.1    skrll  *
     23  1.1.60.1    skrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1.60.1    skrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1.60.1    skrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1.60.1    skrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1.60.1    skrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1.60.1    skrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1.60.1    skrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1.60.1    skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1.60.1    skrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1.60.1    skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1.60.1    skrll  * SUCH DAMAGE.
     34  1.1.60.1    skrll  *
     35  1.1.60.1    skrll  * from: Utah Hdr: rd.c 1.20 92/12/21
     36  1.1.60.1    skrll  *
     37  1.1.60.1    skrll  *	@(#)rd.c	8.1 (Berkeley) 7/15/93
     38  1.1.60.1    skrll  */
     39  1.1.60.1    skrll /*
     40  1.1.60.1    skrll  * Copyright (c) 1988 University of Utah.
     41  1.1.60.1    skrll  *
     42  1.1.60.1    skrll  * This code is derived from software contributed to Berkeley by
     43  1.1.60.1    skrll  * the Systems Programming Group of the University of Utah Computer
     44  1.1.60.1    skrll  * Science Department.
     45  1.1.60.1    skrll  *
     46  1.1.60.1    skrll  * Redistribution and use in source and binary forms, with or without
     47  1.1.60.1    skrll  * modification, are permitted provided that the following conditions
     48  1.1.60.1    skrll  * are met:
     49  1.1.60.1    skrll  * 1. Redistributions of source code must retain the above copyright
     50  1.1.60.1    skrll  *    notice, this list of conditions and the following disclaimer.
     51  1.1.60.1    skrll  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1.60.1    skrll  *    notice, this list of conditions and the following disclaimer in the
     53  1.1.60.1    skrll  *    documentation and/or other materials provided with the distribution.
     54       1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     55       1.1  thorpej  *    must display the following acknowledgement:
     56       1.1  thorpej  *	This product includes software developed by the University of
     57       1.1  thorpej  *	California, Berkeley and its contributors.
     58       1.1  thorpej  * 4. Neither the name of the University nor the names of its contributors
     59       1.1  thorpej  *    may be used to endorse or promote products derived from this software
     60       1.1  thorpej  *    without specific prior written permission.
     61       1.1  thorpej  *
     62       1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63       1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64       1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65       1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66       1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67       1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68       1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69       1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70       1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71       1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72       1.1  thorpej  * SUCH DAMAGE.
     73       1.1  thorpej  *
     74       1.1  thorpej  * from: Utah Hdr: rd.c 1.20 92/12/21
     75       1.1  thorpej  *
     76       1.1  thorpej  *	@(#)rd.c	8.1 (Berkeley) 7/15/93
     77       1.1  thorpej  */
     78       1.1  thorpej 
     79       1.1  thorpej /*
     80       1.1  thorpej  * CS80/SS80 disk driver
     81       1.1  thorpej  */
     82       1.1  thorpej #include <sys/param.h>
     83       1.1  thorpej #include <sys/disklabel.h>
     84       1.1  thorpej 
     85  1.1.60.1    skrll #include <machine/stdarg.h>
     86  1.1.60.1    skrll 
     87       1.1  thorpej #include <lib/libsa/stand.h>
     88       1.1  thorpej 
     89       1.1  thorpej #include <hp300/dev/rdreg.h>
     90       1.1  thorpej 
     91  1.1.60.1    skrll #include <hp300/stand/common/conf.h>
     92  1.1.60.1    skrll #include <hp300/stand/common/hpibvar.h>
     93       1.1  thorpej #include <hp300/stand/common/samachdep.h>
     94       1.1  thorpej 
     95       1.1  thorpej struct	rd_iocmd rd_ioc;
     96       1.1  thorpej struct	rd_rscmd rd_rsc;
     97       1.1  thorpej struct	rd_stat rd_stat;
     98       1.1  thorpej struct	rd_ssmcmd rd_ssmc;
     99       1.1  thorpej 
    100       1.1  thorpej struct	disklabel rdlabel;
    101       1.1  thorpej 
    102       1.1  thorpej struct	rdminilabel {
    103       1.1  thorpej 	u_short	npart;
    104       1.1  thorpej 	u_long	offset[MAXPARTITIONS];
    105       1.1  thorpej };
    106       1.1  thorpej 
    107       1.1  thorpej struct	rd_softc {
    108       1.1  thorpej 	int	sc_ctlr;
    109       1.1  thorpej 	int	sc_unit;
    110       1.1  thorpej 	int	sc_part;
    111       1.1  thorpej 	char	sc_retry;
    112       1.1  thorpej 	char	sc_alive;
    113       1.1  thorpej 	short	sc_type;
    114       1.1  thorpej 	struct	rdminilabel sc_pinfo;
    115  1.1.60.1    skrll };
    116       1.1  thorpej 
    117       1.1  thorpej #define	RDRETRY		5
    118       1.1  thorpej 
    119       1.1  thorpej struct	rdidentinfo {
    120       1.1  thorpej 	short	ri_hwid;
    121       1.1  thorpej 	short	ri_maxunum;
    122       1.1  thorpej 	int	ri_nblocks;
    123  1.1.60.1    skrll };
    124  1.1.60.1    skrll 
    125  1.1.60.1    skrll static int rdinit(int, int);
    126  1.1.60.1    skrll static int rdident(int, int);
    127  1.1.60.1    skrll static void rdreset(int, int);
    128  1.1.60.1    skrll static int rdgetinfo(struct rd_softc *);
    129  1.1.60.1    skrll static int rderror(int, int, int);
    130  1.1.60.1    skrll 
    131  1.1.60.1    skrll struct rd_softc rd_softc[NHPIB][NRD];
    132  1.1.60.1    skrll 
    133  1.1.60.1    skrll struct rdidentinfo rdidentinfo[] = {
    134       1.1  thorpej 	{ RD7946AID,	0,	 108416 },
    135       1.1  thorpej 	{ RD9134DID,	1,	  29088 },
    136       1.1  thorpej 	{ RD9134LID,	1,	   1232 },
    137       1.1  thorpej 	{ RD7912PID,	0,	 128128 },
    138       1.1  thorpej 	{ RD7914PID,	0,	 258048 },
    139       1.1  thorpej 	{ RD7958AID,	0,	 255276 },
    140       1.1  thorpej 	{ RD7957AID,	0,	 159544 },
    141       1.1  thorpej 	{ RD7933HID,	0,	 789958 },
    142       1.1  thorpej 	{ RD9134LID,	1,	  77840 },
    143       1.1  thorpej 	{ RD7936HID,	0,	 600978 },
    144       1.1  thorpej 	{ RD7937HID,	0,	1116102 },
    145       1.1  thorpej 	{ RD7914CTID,	0,	 258048 },
    146       1.1  thorpej 	{ RD7946AID,	0,	 108416 },
    147       1.1  thorpej 	{ RD9134LID,	1,	   1232 },
    148       1.1  thorpej 	{ RD7957BID,	0,	 159894 },
    149       1.1  thorpej 	{ RD7958BID,	0,	 297108 },
    150       1.1  thorpej 	{ RD7959BID,	0,	 594216 },
    151       1.1  thorpej 	{ RD2200AID,	0,	 654948 },
    152       1.1  thorpej 	{ RD2203AID,	0,	1309896 }
    153       1.1  thorpej };
    154       1.1  thorpej int numrdidentinfo = sizeof(rdidentinfo) / sizeof(rdidentinfo[0]);
    155       1.1  thorpej 
    156  1.1.60.1    skrll int
    157       1.1  thorpej rdinit(ctlr, unit)
    158       1.1  thorpej 	int ctlr, unit;
    159       1.1  thorpej {
    160  1.1.60.1    skrll 	struct rd_softc *rs = &rd_softc[ctlr][unit];
    161       1.1  thorpej 
    162       1.1  thorpej 	rs->sc_type = rdident(ctlr, unit);
    163       1.1  thorpej 	if (rs->sc_type < 0)
    164  1.1.60.1    skrll 		return 0;
    165       1.1  thorpej 	rs->sc_alive = 1;
    166  1.1.60.1    skrll 	return 1;
    167       1.1  thorpej }
    168       1.1  thorpej 
    169  1.1.60.1    skrll static void
    170       1.1  thorpej rdreset(ctlr, unit)
    171  1.1.60.1    skrll 	int ctlr, unit;
    172       1.1  thorpej {
    173       1.1  thorpej 	u_char stat;
    174       1.1  thorpej 
    175       1.1  thorpej 	rd_ssmc.c_unit = C_SUNIT(0);
    176       1.1  thorpej 	rd_ssmc.c_cmd = C_SSM;
    177       1.1  thorpej 	rd_ssmc.c_refm = REF_MASK;
    178       1.1  thorpej 	rd_ssmc.c_fefm = FEF_MASK;
    179       1.1  thorpej 	rd_ssmc.c_aefm = AEF_MASK;
    180       1.1  thorpej 	rd_ssmc.c_iefm = IEF_MASK;
    181  1.1.60.1    skrll 	hpibsend(ctlr, unit, C_CMD, (char *)&rd_ssmc, sizeof(rd_ssmc));
    182       1.1  thorpej 	hpibswait(ctlr, unit);
    183       1.1  thorpej 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
    184       1.1  thorpej }
    185       1.1  thorpej 
    186  1.1.60.1    skrll static int
    187       1.1  thorpej rdident(ctlr, unit)
    188  1.1.60.1    skrll 	int ctlr, unit;
    189       1.1  thorpej {
    190       1.1  thorpej 	struct rd_describe desc;
    191       1.1  thorpej 	u_char stat, cmd[3];
    192       1.1  thorpej 	char name[7];
    193  1.1.60.1    skrll 	int id, i;
    194       1.1  thorpej 
    195       1.1  thorpej 	id = hpibid(ctlr, unit);
    196       1.1  thorpej 	if ((id & 0x200) == 0)
    197  1.1.60.1    skrll 		return -1;
    198       1.1  thorpej 	for (i = 0; i < numrdidentinfo; i++)
    199       1.1  thorpej 		if (id == rdidentinfo[i].ri_hwid)
    200       1.1  thorpej 			break;
    201       1.1  thorpej 	if (i == numrdidentinfo)
    202  1.1.60.1    skrll 		return -1;
    203       1.1  thorpej 	id = i;
    204       1.1  thorpej 	rdreset(ctlr, unit);
    205       1.1  thorpej 	cmd[0] = C_SUNIT(0);
    206       1.1  thorpej 	cmd[1] = C_SVOL(0);
    207       1.1  thorpej 	cmd[2] = C_DESC;
    208       1.1  thorpej 	hpibsend(ctlr, unit, C_CMD, cmd, sizeof(cmd));
    209  1.1.60.1    skrll 	hpibrecv(ctlr, unit, C_EXEC, (char *)&desc, 37);
    210       1.1  thorpej 	hpibrecv(ctlr, unit, C_QSTAT, &stat, sizeof(stat));
    211  1.1.60.1    skrll 	memset(name, 0, sizeof(name));
    212       1.1  thorpej 	if (!stat) {
    213  1.1.60.1    skrll 		int n = desc.d_name;
    214       1.1  thorpej 		for (i = 5; i >= 0; i--) {
    215       1.1  thorpej 			name[i] = (n & 0xf) + '0';
    216       1.1  thorpej 			n >>= 4;
    217       1.1  thorpej 		}
    218       1.1  thorpej 	}
    219       1.1  thorpej 	/*
    220       1.1  thorpej 	 * Take care of a couple of anomolies:
    221       1.1  thorpej 	 * 1. 7945A and 7946A both return same HW id
    222       1.1  thorpej 	 * 2. 9122S and 9134D both return same HW id
    223       1.1  thorpej 	 * 3. 9122D and 9134L both return same HW id
    224       1.1  thorpej 	 */
    225       1.1  thorpej 	switch (rdidentinfo[id].ri_hwid) {
    226       1.1  thorpej 	case RD7946AID:
    227  1.1.60.1    skrll 		if (memcmp(name, "079450", 6) == 0)
    228       1.1  thorpej 			id = RD7945A;
    229       1.1  thorpej 		else
    230       1.1  thorpej 			id = RD7946A;
    231       1.1  thorpej 		break;
    232       1.1  thorpej 
    233       1.1  thorpej 	case RD9134LID:
    234  1.1.60.1    skrll 		if (memcmp(name, "091340", 6) == 0)
    235       1.1  thorpej 			id = RD9134L;
    236       1.1  thorpej 		else
    237       1.1  thorpej 			id = RD9122D;
    238       1.1  thorpej 		break;
    239       1.1  thorpej 
    240       1.1  thorpej 	case RD9134DID:
    241  1.1.60.1    skrll 		if (memcmp(name, "091220", 6) == 0)
    242       1.1  thorpej 			id = RD9122S;
    243       1.1  thorpej 		else
    244       1.1  thorpej 			id = RD9134D;
    245       1.1  thorpej 		break;
    246       1.1  thorpej 	}
    247  1.1.60.1    skrll 	return id;
    248       1.1  thorpej }
    249       1.1  thorpej 
    250       1.1  thorpej char io_buf[MAXBSIZE];
    251       1.1  thorpej 
    252  1.1.60.1    skrll static int
    253       1.1  thorpej rdgetinfo(rs)
    254  1.1.60.1    skrll 	struct rd_softc *rs;
    255       1.1  thorpej {
    256  1.1.60.1    skrll 	struct rdminilabel *pi = &rs->sc_pinfo;
    257  1.1.60.1    skrll 	struct disklabel *lp = &rdlabel;
    258  1.1.60.1    skrll 	char *msg;
    259  1.1.60.1    skrll 	int err, savepart;
    260       1.1  thorpej 	size_t i;
    261       1.1  thorpej 
    262  1.1.60.1    skrll 	memset((caddr_t)lp, 0, sizeof *lp);
    263       1.1  thorpej 	lp->d_secsize = DEV_BSIZE;
    264       1.1  thorpej 
    265       1.1  thorpej 	/* Disklabel is always from RAW_PART. */
    266       1.1  thorpej 	savepart = rs->sc_part;
    267       1.1  thorpej 	rs->sc_part = RAW_PART;
    268       1.1  thorpej 	err = rdstrategy(rs, F_READ, LABELSECTOR,
    269       1.1  thorpej 	    lp->d_secsize ? lp->d_secsize : DEV_BSIZE, io_buf, &i);
    270       1.1  thorpej 	rs->sc_part = savepart;
    271       1.1  thorpej 
    272       1.1  thorpej 	if (err) {
    273       1.1  thorpej 		printf("rdgetinfo: rdstrategy error %d\n", err);
    274  1.1.60.1    skrll 		return 0;
    275       1.1  thorpej 	}
    276       1.1  thorpej 
    277       1.1  thorpej 	msg = getdisklabel(io_buf, lp);
    278       1.1  thorpej 	if (msg) {
    279  1.1.60.2    skrll 		printf("rd(%d,%d,%d): WARNING: %s\n",
    280       1.1  thorpej 		       rs->sc_ctlr, rs->sc_unit, rs->sc_part, msg);
    281       1.1  thorpej 		pi->npart = 3;
    282       1.1  thorpej 		pi->offset[0] = pi->offset[1] = -1;
    283       1.1  thorpej 		pi->offset[2] = 0;
    284       1.1  thorpej 	} else {
    285       1.1  thorpej 		pi->npart = lp->d_npartitions;
    286       1.1  thorpej 		for (i = 0; i < pi->npart; i++)
    287       1.1  thorpej 			pi->offset[i] = lp->d_partitions[i].p_size == 0 ?
    288       1.1  thorpej 				-1 : lp->d_partitions[i].p_offset;
    289       1.1  thorpej 	}
    290  1.1.60.1    skrll 	return 1;
    291       1.1  thorpej }
    292       1.1  thorpej 
    293  1.1.60.1    skrll int
    294  1.1.60.1    skrll rdopen(struct open_file *f, ...)
    295       1.1  thorpej {
    296  1.1.60.1    skrll 	va_list ap;
    297  1.1.60.1    skrll 	int ctlr, unit, part;
    298  1.1.60.1    skrll 	struct rd_softc *rs;
    299  1.1.60.1    skrll 
    300  1.1.60.1    skrll 	va_start(ap, f);
    301  1.1.60.1    skrll 	ctlr = va_arg(ap, int);
    302  1.1.60.1    skrll 	unit = va_arg(ap, int);
    303  1.1.60.1    skrll 	part = va_arg(ap, int);
    304  1.1.60.1    skrll 	va_end(ap);
    305       1.1  thorpej 
    306       1.1  thorpej 	if (ctlr >= NHPIB || hpibalive(ctlr) == 0)
    307  1.1.60.1    skrll 		return EADAPT;
    308       1.1  thorpej 	if (unit >= NRD)
    309  1.1.60.1    skrll 		return ECTLR;
    310       1.1  thorpej 	rs = &rd_softc[ctlr][unit];
    311       1.1  thorpej 	rs->sc_part = part;
    312       1.1  thorpej 	rs->sc_unit = unit;
    313       1.1  thorpej 	rs->sc_ctlr = ctlr;
    314       1.1  thorpej 	if (rs->sc_alive == 0) {
    315       1.1  thorpej 		if (rdinit(ctlr, unit) == 0)
    316  1.1.60.1    skrll 			return ENXIO;
    317       1.1  thorpej 		if (rdgetinfo(rs) == 0)
    318  1.1.60.1    skrll 			return ERDLAB;
    319       1.1  thorpej 	}
    320       1.1  thorpej 	if (part != RAW_PART &&     /* always allow RAW_PART to be opened */
    321       1.1  thorpej 	    (part >= rs->sc_pinfo.npart || rs->sc_pinfo.offset[part] == -1))
    322  1.1.60.1    skrll 		return EPART;
    323       1.1  thorpej 	f->f_devdata = (void *)rs;
    324  1.1.60.1    skrll 	return 0;
    325       1.1  thorpej }
    326       1.1  thorpej 
    327  1.1.60.1    skrll int
    328       1.1  thorpej rdclose(f)
    329       1.1  thorpej 	struct open_file *f;
    330       1.1  thorpej {
    331       1.1  thorpej 	struct rd_softc *rs = f->f_devdata;
    332       1.1  thorpej 
    333       1.1  thorpej 	/*
    334       1.1  thorpej 	 * Mark the disk `not alive' so that the disklabel
    335       1.1  thorpej 	 * will be re-loaded at next open.
    336       1.1  thorpej 	 */
    337  1.1.60.1    skrll 	memset(rs, 0, sizeof(struct rd_softc));
    338       1.1  thorpej 	f->f_devdata = NULL;
    339       1.1  thorpej 
    340  1.1.60.1    skrll 	return 0;
    341       1.1  thorpej }
    342       1.1  thorpej 
    343  1.1.60.1    skrll int
    344       1.1  thorpej rdstrategy(devdata, func, dblk, size, v_buf, rsize)
    345       1.1  thorpej 	void *devdata;
    346       1.1  thorpej 	int func;
    347       1.1  thorpej 	daddr_t dblk;
    348       1.1  thorpej 	size_t size;
    349       1.1  thorpej 	void *v_buf;
    350       1.1  thorpej 	size_t *rsize;
    351       1.1  thorpej {
    352       1.1  thorpej 	char *buf = v_buf;
    353       1.1  thorpej 	struct rd_softc *rs = devdata;
    354  1.1.60.1    skrll 	int ctlr = rs->sc_ctlr;
    355  1.1.60.1    skrll 	int unit = rs->sc_unit;
    356       1.1  thorpej 	daddr_t blk;
    357       1.1  thorpej 	char stat;
    358       1.1  thorpej 
    359       1.1  thorpej 	if (size == 0)
    360  1.1.60.1    skrll 		return 0;
    361       1.1  thorpej 
    362       1.1  thorpej 	/*
    363       1.1  thorpej 	 * Don't do partition translation on the `raw partition'.
    364       1.1  thorpej 	 */
    365       1.1  thorpej 	blk = (dblk + ((rs->sc_part == RAW_PART) ? 0 :
    366       1.1  thorpej 	    rs->sc_pinfo.offset[rs->sc_part]));
    367       1.1  thorpej 
    368       1.1  thorpej 	rs->sc_retry = 0;
    369       1.1  thorpej 	rd_ioc.c_unit = C_SUNIT(0);
    370       1.1  thorpej 	rd_ioc.c_volume = C_SVOL(0);
    371       1.1  thorpej 	rd_ioc.c_saddr = C_SADDR;
    372       1.1  thorpej 	rd_ioc.c_hiaddr = 0;
    373       1.1  thorpej 	rd_ioc.c_addr = RDBTOS(blk);
    374       1.1  thorpej 	rd_ioc.c_nop2 = C_NOP;
    375       1.1  thorpej 	rd_ioc.c_slen = C_SLEN;
    376       1.1  thorpej 	rd_ioc.c_len = size;
    377       1.1  thorpej 	rd_ioc.c_cmd = func == F_READ ? C_READ : C_WRITE;
    378       1.1  thorpej retry:
    379       1.1  thorpej 	hpibsend(ctlr, unit, C_CMD, &rd_ioc.c_unit, sizeof(rd_ioc)-2);
    380       1.1  thorpej 	hpibswait(ctlr, unit);
    381       1.1  thorpej 	hpibgo(ctlr, unit, C_EXEC, buf, size, func);
    382       1.1  thorpej 	hpibswait(ctlr, unit);
    383       1.1  thorpej 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
    384       1.1  thorpej 	if (stat) {
    385       1.1  thorpej 		if (rderror(ctlr, unit, rs->sc_part) == 0)
    386  1.1.60.1    skrll 			return EIO;
    387       1.1  thorpej 		if (++rs->sc_retry > RDRETRY)
    388  1.1.60.1    skrll 			return EIO;
    389       1.1  thorpej 		goto retry;
    390       1.1  thorpej 	}
    391       1.1  thorpej 	*rsize = size;
    392       1.1  thorpej 
    393  1.1.60.1    skrll 	return 0;
    394       1.1  thorpej }
    395       1.1  thorpej 
    396  1.1.60.1    skrll static int
    397       1.1  thorpej rderror(ctlr, unit, part)
    398  1.1.60.1    skrll 	int ctlr, unit;
    399       1.1  thorpej 	int part;
    400       1.1  thorpej {
    401       1.1  thorpej 	char stat;
    402       1.1  thorpej 
    403       1.1  thorpej 	rd_rsc.c_unit = C_SUNIT(0);
    404       1.1  thorpej 	rd_rsc.c_sram = C_SRAM;
    405       1.1  thorpej 	rd_rsc.c_ram = C_RAM;
    406       1.1  thorpej 	rd_rsc.c_cmd = C_STATUS;
    407  1.1.60.1    skrll 	hpibsend(ctlr, unit, C_CMD, (char *)&rd_rsc, sizeof(rd_rsc));
    408  1.1.60.1    skrll 	hpibrecv(ctlr, unit, C_EXEC, (char *)&rd_stat, sizeof(rd_stat));
    409       1.1  thorpej 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
    410       1.1  thorpej 	if (stat) {
    411       1.1  thorpej 		printf("rd(%d,%d,0,%d): request status fail %d\n",
    412       1.1  thorpej 		       ctlr, unit, part, stat);
    413  1.1.60.1    skrll 		return 0;
    414       1.1  thorpej 	}
    415       1.1  thorpej 	printf("rd(%d,%d,0,%d) err: vu 0x%x",
    416       1.1  thorpej 	       ctlr, unit, part, rd_stat.c_vu);
    417       1.1  thorpej 	if ((rd_stat.c_aef & AEF_UD) || (rd_stat.c_ief & (IEF_MD|IEF_RD)))
    418  1.1.60.1    skrll 		printf(", block %ld", rd_stat.c_blk);
    419       1.1  thorpej 	printf(", R0x%x F0x%x A0x%x I0x%x\n",
    420       1.1  thorpej 	       rd_stat.c_ref, rd_stat.c_fef, rd_stat.c_aef, rd_stat.c_ief);
    421  1.1.60.1    skrll 	return 1;
    422       1.1  thorpej }
    423