xref: /original-bsd/sys/hp300/dev/rd.c (revision 3a8172c6)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: rd.c 1.38 90/10/12$
13  *
14  *	@(#)rd.c	7.9 (Berkeley) 05/07/91
15  */
16 
17 /*
18  * CS80/SS80 disk driver
19  */
20 #include "rd.h"
21 #if NRD > 0
22 
23 #include "sys/param.h"
24 #include "sys/systm.h"
25 #include "sys/errno.h"
26 #include "sys/dkstat.h"
27 #include "sys/disklabel.h"
28 #include "sys/buf.h"
29 #include "sys/uio.h"
30 
31 #include "device.h"
32 #include "rdreg.h"
33 
34 #include "vm/vm_param.h"
35 #include "vm/lock.h"
36 #include "vm/vm_statistics.h"
37 #include "vm/pmap.h"
38 #include "vm/vm_prot.h"
39 
40 int	rdinit(), rdstart(), rdgo(), rdintr();
41 struct	driver rddriver = {
42 	rdinit, "rd", rdstart, rdgo, rdintr,
43 };
44 
45 struct	rd_softc {
46 	struct	hp_device *sc_hd;
47 	int	sc_flags;
48 	short	sc_type;
49 	short	sc_punit;
50 	char	*sc_addr;
51 	int	sc_resid;
52 	u_int	sc_wpms;
53 	struct	rdinfo *sc_info;
54 	struct	devqueue sc_dq;
55 	struct	rd_iocmd sc_ioc;
56 	struct	rd_rscmd sc_rsc;
57 	struct	rd_stat sc_stat;
58 	struct	rd_ssmcmd sc_ssmc;
59 	struct	rd_srcmd sc_src;
60 	struct	rd_clearcmd sc_clear;
61 } rd_softc[NRD];
62 
63 /* sc_flags values */
64 #define	RDF_ALIVE	0x1
65 #define	RDF_SEEK	0x2
66 #define RDF_SWAIT	0x4
67 
68 struct	size {
69 	daddr_t	nblocks;
70 	int	cyloff;
71 };
72 
73 #ifdef DEBUG
74 int rddebug = 0x80;
75 #define RDB_FOLLOW	0x01
76 #define RDB_STATUS	0x02
77 #define RDB_IDENT	0x04
78 #define RDB_IO		0x08
79 #define RDB_ASYNC	0x10
80 #define RDB_ERROR	0x80
81 #define RDB_DUMP	0x80000000
82 
83 struct rdstats {
84 	long	rdretries;
85 	long	rdresets;
86 	long	rdtimeouts;
87 	long	rdpolltries;
88 	long	rdpollwaits;
89 } rdstats[NRD];
90 
91 /* error message tables */
92 char *err_reject[] = {
93 	0, 0,
94 	"channel parity error",		/* 0x2000 */
95 	0, 0,
96 	"illegal opcode",		/* 0x0400 */
97 	"module addressing",		/* 0x0200 */
98 	"address bounds",		/* 0x0100 */
99 	"parameter bounds",		/* 0x0080 */
100 	"illegal parameter",		/* 0x0040 */
101 	"message sequence",		/* 0x0020 */
102 	0,
103 	"message length",		/* 0x0008 */
104 	0, 0, 0
105 };
106 
107 char *err_fault[] = {
108 	0,
109 	"cross unit",			/* 0x4000 */
110 	0,
111 	"controller fault",		/* 0x1000 */
112 	0, 0,
113 	"unit fault",			/* 0x0200 */
114 	0,
115 	"diagnostic result",		/* 0x0080 */
116 	0,
117 	"operator release request",	/* 0x0020 */
118 	"diagnostic release request",	/* 0x0010 */
119 	"internal maintenance release request",	/* 0x0008 */
120 	0,
121 	"power fail",			/* 0x0002 */
122 	"retransmit"			/* 0x0001 */
123 };
124 
125 char *err_access[] = {
126 	"illegal parallel operation",	/* 0x8000 */
127 	"uninitialized media",		/* 0x4000 */
128 	"no spares available",		/* 0x2000 */
129 	"not ready",			/* 0x1000 */
130 	"write protect",		/* 0x0800 */
131 	"no data found",		/* 0x0400 */
132 	0, 0,
133 	"unrecoverable data overflow",	/* 0x0080 */
134 	"unrecoverable data",		/* 0x0040 */
135 	0,
136 	"end of file",			/* 0x0010 */
137 	"end of volume",		/* 0x0008 */
138 	0, 0, 0
139 };
140 
141 char *err_info[] = {
142 	"operator release request",	/* 0x8000 */
143 	"diagnostic release request",	/* 0x4000 */
144 	"internal maintenance release request",	/* 0x2000 */
145 	"media wear",			/* 0x1000 */
146 	"latency induced",		/* 0x0800 */
147 	0, 0,
148 	"auto sparing invoked",		/* 0x0100 */
149 	0,
150 	"recoverable data overflow",	/* 0x0040 */
151 	"marginal data",		/* 0x0020 */
152 	"recoverable data",		/* 0x0010 */
153 	0,
154 	"maintenance track overflow",	/* 0x0004 */
155 	0, 0
156 };
157 #endif
158 
159 /*
160  * CS/80 partitions.  We reserve the first cylinder for a LIF
161  * style boot directory (the 8k allowed in the BSD filesystem
162  * is just way too small).  This boot area is outside of all but
163  * the C partition.  This implies that you cannot use the C
164  * partition on a bootable disk since the filesystem would overlay
165  * the boot area.  You must use the A partition.
166  *
167  * These maps support four basic layouts:
168  *
169  *	A/B/G:   This is the "traditional" setup for a bootable disk.
170  *	         A is the root partition, B the swap, and G a user partition.
171  *	A/D/H:   This is a setup for bootable systems requiring more swap
172  *		 (e.g. those who use HPCL).  It has A as the root, D as a
173  *		 larger swap, and H as a smaller user partition.
174  *	A/D/E/F: Similar to A/D/H with E and F breaking H into two partitions.
175  *		 E could be used for /usr and F for users.
176  *	C:       This gives a single, non-bootable, large user filesystem.
177  *	         Good for second drives on a machine (e.g. /usr/src).
178  */
179 struct size rd7945A_sizes[8] = {
180 	RDSZ(15904),	1,		/* A=cyl 1 thru 142 */
181 	RDSZ(20160),	143,		/* B=cyl 143 thru 322 */
182 	RDSZ(108416),	0,		/* C=cyl 0 thru 967 */
183 	RDSZ(40320),	143,		/* D=cyl 143 thru 502 */
184 	RDSZ(0),	0,		/* E=<undefined> */
185 	RDSZ(0),	0,		/* F=<undefined> */
186 	RDSZ(72240),	323,		/* G=cyl 323 thru 967 */
187 	RDSZ(52080),	503,		/* H=cyl 503 thru 967 */
188 }, rd9134D_sizes[8] = {
189 	RDSZ(15936),	1,		/* A=cyl 1 thru 166 */
190 	RDSZ(13056),	167,		/* B=cyl 167 thru 302 */
191 	RDSZ(29088),	0,		/* C=cyl 0 thru 302 */
192 	RDSZ(0),	0,		/* D=<undefined> */
193 	RDSZ(0),	0,		/* E=<undefined> */
194 	RDSZ(0),	0,		/* F=<undefined> */
195 	RDSZ(0),	0,		/* G=<undefined> */
196 	RDSZ(0),	0,		/* H=<undefined> */
197 }, rd9122S_sizes[8] = {
198 	RDSZ(0),	0,		/* A=<undefined> */
199 	RDSZ(0),	0,		/* B=<undefined> */
200 	RDSZ(1232),	0,		/* C=cyl 0 thru 76 */
201 	RDSZ(0),	0,		/* D=<undefined> */
202 	RDSZ(0),	0,		/* E=<undefined> */
203 	RDSZ(0),	0,		/* F=<undefined> */
204 	RDSZ(0),	0,		/* G=<undefined> */
205 	RDSZ(0),	0,		/* H=<undefined> */
206 }, rd7912P_sizes[8] = {
207 	RDSZ(15904),	0,		/* A=cyl 1 thru 71 */
208 	RDSZ(22400),	72,		/* B=cyl 72 thru 171 */
209 	RDSZ(128128),	0,		/* C=cyl 0 thru 571 */
210 	RDSZ(42560),	72,		/* D=cyl 72 thru 261 */
211 	RDSZ(0),	292,		/* E=<undefined> */
212 	RDSZ(0),	542,		/* F=<undefined> */
213 	RDSZ(89600),	172,		/* G=cyl 221 thru 571 */
214 	RDSZ(69440),	262,		/* H=cyl 262 thru 571 */
215 }, rd7914P_sizes[8] = {
216 	RDSZ(15904),	1,		/* A=cyl 1 thru 71 */
217 	RDSZ(40320),	72,		/* B=cyl 72 thru 251 */
218 	RDSZ(258048),	0,		/* C=cyl 0 thru 1151 */
219 	RDSZ(64960),	72,		/* D=cyl 72 thru 361 */
220 	RDSZ(98560),	362,		/* E=cyl 362 thru 801 */
221 	RDSZ(78400),	802,		/* F=cyl 802 thru 1151 */
222 	RDSZ(201600),	252,		/* G=cyl 221 thru 1151 */
223 	RDSZ(176960),	362,		/* H=cyl 362 thru 1151 */
224 }, rd7933H_sizes[8] = {
225 	RDSZ(16146),	1,		/* A=cyl 1 thru 27 */
226 	RDSZ(66976),	28,		/* B=cyl 28 thru 139 */
227 	RDSZ(789958),	0,		/* C=cyl 0 thru 1320 */
228 	RDSZ(16146),	140,		/* D=cyl 140 thru 166 */
229 	RDSZ(165646),	167,		/* E=cyl 167 thru 443 */
230 	RDSZ(165646),	444,		/* F=cyl 444 thru 720 */
231 	RDSZ(706238),	140,		/* G=cyl 140 thru 1320 */
232 	RDSZ(358800),	721,		/* H=cyl 721 thru 1320 */
233 }, rd9134L_sizes[8] = {
234 	RDSZ(15920),	1,		/* A=cyl 1 thru 199 */
235 	RDSZ(20000),	200,		/* B=cyl 200 thru 449 */
236 	RDSZ(77840),	0,		/* C=cyl 0 thru 972 */
237 	RDSZ(32000),	200,		/* D=cyl 200 thru 599 */
238 	RDSZ(0),	0,		/* E=<undefined> */
239 	RDSZ(0),	0,		/* F=<undefined> */
240 	RDSZ(41840),	450,		/* G=cyl 450 thru 972 */
241 	RDSZ(29840),	600,		/* H=cyl 600 thru 972 */
242 }, rd7957A_sizes[8] = {
243 	RDSZ(16016),	1,		/* A=cyl 1 thru 104 */
244 	RDSZ(24640),	105,		/* B=cyl 105 thru 264 */
245 	RDSZ(159544),	0,		/* C=cyl 0 thru 1035 */
246 	RDSZ(42350),	105,		/* D=cyl 105 thru 379 */
247 	RDSZ(54824),	380,		/* E=cyl 380 thru 735 */
248 	RDSZ(46200),	736,		/* F=cyl 736 thru 1035 */
249 	RDSZ(118734),	265,		/* G=cyl 265 thru 1035 */
250 	RDSZ(101024),	380,		/* H=cyl 380 thru 1035 */
251 }, rd7958A_sizes[8] = {
252 	RDSZ(16128),	1,		/* A=cyl 1 thru 64 */
253 	RDSZ(32256),	65,		/* B=cyl 65 thru 192 */
254 	RDSZ(255276),	0,		/* C=cyl 0 thru 1012 */
255 	RDSZ(48384),	65,		/* D=cyl 65 thru 256 */
256 	RDSZ(100800),	257,		/* E=cyl 257 thru 656 */
257 	RDSZ(89712),	657,		/* F=cyl 657 thru 1012 */
258 	RDSZ(206640),	193,		/* G=cyl 193 thru 1012 */
259 	RDSZ(190512),	257,		/* H=cyl 257 thru 1012 */
260 }, rd7957B_sizes[8] = {
261 	RDSZ(16002),	1,		/* A=cyl 1 thru 127 */
262 	RDSZ(32760),	128,		/* B=cyl 128 thru 387 */
263 	RDSZ(159894),	0,		/* C=cyl 0 thru 1268 */
264 	RDSZ(49140),	128,		/* D=cyl 128 thru 517 */
265 	RDSZ(50400),	518,		/* E=cyl 518 thru 917 */
266 	RDSZ(44226),	918,		/* F=cyl 918 thru 1268 */
267 	RDSZ(111006),	388,		/* G=cyl 388 thru 1268 */
268 	RDSZ(94626),	518,		/* H=cyl 518 thru 1268 */
269 }, rd7958B_sizes[8] = {
270 	RDSZ(16254),	1,		/* A=cyl 1 thru 43 */
271 	RDSZ(32886),	44,		/* B=cyl 44 thru 130 */
272 	RDSZ(297108),	0,		/* C=cyl 0 thru 785 */
273 	RDSZ(49140),	44,		/* D=cyl 44 thru 173 */
274 	RDSZ(121716),	174,		/* E=cyl 174 thru 495 */
275 	RDSZ(109620),	496,		/* F=cyl 496 thru 785 */
276 	RDSZ(247590),	131,		/* G=cyl 131 thru 785 */
277 	RDSZ(231336),	174,		/* H=cyl 174 thru 785 */
278 }, rd7959B_sizes[8] = {
279 	RDSZ(16254),	1,		/* A=cyl 1 thru 43 */
280 	RDSZ(49140),	44,		/* B=cyl 44 thru 173 */
281 	RDSZ(594216),	0,		/* C=cyl 0 thru 1571 */
282 	RDSZ(65772),	44,		/* D=cyl 44 thru 217 */
283 	RDSZ(303912),	218,		/* E=cyl 218 thru 1021 */
284 	RDSZ(207900),	1022,		/* F=cyl 1022 thru 1571 */
285 	RDSZ(528444),	174,		/* G=cyl 174 thru 1571 */
286 	RDSZ(511812),	218,		/* H=cyl 218 thru 1571 */
287 }, rd2200A_sizes[8] = {
288 	RDSZ(16272),	1,		/* A=cyl 1 thru 36 */
289 	RDSZ(49720),	37,		/* B=cyl 37 thru 146 */
290 	RDSZ(654948),	0,		/* C=cyl 0 thru 1448 */
291 	RDSZ(65992),	37,		/* D=cyl 37 thru 182 */
292 	RDSZ(304648),	183,		/* E=cyl 183 thru 856 */
293 	RDSZ(267584),	857,		/* F=cyl 857 thru 1448 */
294 	RDSZ(588504),	147,		/* G=cyl 147 thru 1448 */
295 	RDSZ(572232),	183,		/* H=cyl 183 thru 1448 */
296 }, rd2203A_sizes[8] = {
297 	/* modelled after the 7937; i.e. bogus */
298 	RDSZ(16272),	1,		/* A=cyl 1 thru 18 */
299 	RDSZ(67800),	19,		/* B=cyl 19 thru 93 */
300 	RDSZ(1309896),	0,		/* C=cyl 0 thru 1448 */
301 	RDSZ(16272),	94,		/* D=cyl 19 thru 111 */
302 	RDSZ(305552),	112,		/* E=cyl 112 thru 449 */
303 	RDSZ(305552),	450,		/* F=cyl 450 thru 787 */
304 	RDSZ(1224920),	94,		/* G=cyl 94 thru 1448 */
305 	RDSZ(597544),	788,		/* H=cyl 788 thru 1448 */
306 
307 #if DEV_BSIZE == 512
308 /*
309  * These values would not work for 1k,
310  * since the number of cylinders would be different.
311  */
312 }, rd7936H_sizes[8] = {
313 	RDSZ(16359),	1,		/* A=cyl 1 thru 19 */
314 	RDSZ(67158),	20,		/* B=cyl 20 thru 97 */
315 	RDSZ(600978),	0,		/* C=cyl 0 thru 697 */
316 	RDSZ(16359),	98,		/* D=cyl 98 thru 116 */
317 	RDSZ(120540),	117,		/* E=cyl 117 thru 256 */
318 	RDSZ(120540),	256,		/* F=cyl 256 thru 396 */
319 	RDSZ(516600),	98,		/* G=cyl 98 thru 697 */
320 	RDSZ(259161),	397,		/* H=cyl 397 thru 697 */
321 }, rd7937H_sizes[8] = {
322 #ifdef UTAH
323 	RDSZ(15990),	1,		/* A=cyl 1 thru 10 */
324 	RDSZ(67158),	11,		/* B=cyl 11 thru 52 */
325 	RDSZ(1116102),	0,		/* C=cyl 0 thru 697 */
326 	RDSZ(124722),	53,		/* D=cyl 53 thru 130 */
327 	RDSZ(163098),	131,		/* E=cyl 131 thru 232 */
328 	RDSZ(287820),	233,		/* F=cyl 233 thru 412 */
329 	RDSZ(1031355),	53,		/* G=cyl 53 thru 697 */
330 	RDSZ(455715),	413,		/* H=cyl 413 thru 697 */
331 #else
332 	RDSZ(15990),	1,		/* A=cyl 1 thru 10 */
333 	RDSZ(67158),	11,		/* B=cyl 11 thru 52 */
334 	RDSZ(1116102),	0,		/* C=cyl 0 thru 697 */
335 	RDSZ(15990),	53,		/* D=cyl 53 thru 62 */
336 	RDSZ(246246),	63,		/* E=cyl 63 thru 216 */
337 	RDSZ(246246),	217,		/* F=cyl 217 thru 370 */
338 	RDSZ(1031355),	53,		/* G=cyl 53 thru 697 */
339 	RDSZ(522873),	371,		/* H=cyl 371 thru 697 */
340 #endif
341 #endif
342 };
343 
344 struct	rdinfo {
345 	int	nbpt;		/* DEV_BSIZE blocks per track */
346 	int	ntpc;		/* tracks per cylinder */
347 	int	nbpc;		/* blocks per cylinder */
348 	struct	size *sizes;	/* default partition info (if no disklabel) */
349 	short	hwid;		/* 2 byte HW id */
350 	short	maxunum;	/* maximum allowed unit number */
351 	char	*desc;		/* drive type description */
352 };
353 
354 struct rdinfo rdinfo[] = {
355 	NRD7945ABPT,	NRD7945ATRK,	NRD7945ABPT * NRD7945ATRK,
356 	rd7945A_sizes,	RD7946AID,	0,	"7945A",
357 	NRD9134DBPT,	NRD9134DTRK,	NRD9134DBPT * NRD9134DTRK,
358 	rd9134D_sizes,	RD9134DID,	1,	"9134D",
359 	NRD9122SBPT,	NRD9122STRK,	NRD9122SBPT * NRD9122STRK,
360 	rd9122S_sizes,	RD9134LID,	1,	"9122S",
361 	NRD7912PBPT,	NRD7912PTRK,	NRD7912PBPT * NRD7912PTRK,
362 	rd7912P_sizes,	RD7912PID,	0,	"7912P",
363 	NRD7914PBPT,	NRD7914PTRK,	NRD7914PBPT * NRD7914PTRK,
364 	rd7914P_sizes,	RD7914PID,	0,	"7914P",
365 	NRD7958ABPT,	NRD7958ATRK,	NRD7958ABPT * NRD7958ATRK,
366 	rd7958A_sizes,	RD7958AID,	0,	"7958A",
367 	NRD7957ABPT,	NRD7957ATRK,	NRD7957ABPT * NRD7957ATRK,
368 	rd7957A_sizes,	RD7957AID,	0,	"7957A",
369 	NRD7933HBPT,	NRD7933HTRK,	NRD7933HBPT * NRD7933HTRK,
370 	rd7933H_sizes,	RD7933HID,	0,	"7933H",
371 	NRD9134LBPT,	NRD9134LTRK,	NRD9134LBPT * NRD9134LTRK,
372 	rd9134L_sizes,	RD9134LID,	1,	"9134L",
373 	NRD7936HBPT,	NRD7936HTRK,	NRD7936HBPT * NRD7936HTRK,
374 	rd7936H_sizes,	RD7936HID,	0,	"7936H",
375 	NRD7937HBPT,	NRD7937HTRK,	NRD7937HBPT * NRD7937HTRK,
376 	rd7937H_sizes,	RD7937HID,	0,	"7937H",
377 	NRD7914PBPT,	NRD7914PTRK,	NRD7914PBPT * NRD7914PTRK,
378 	rd7914P_sizes,	RD7914CTID,	0,	"7914CT",
379 	NRD7945ABPT,	NRD7945ATRK,	NRD7945ABPT * NRD7945ATRK,
380 	rd7945A_sizes,	RD7946AID,	0,	"7946A",
381 	NRD9122SBPT,	NRD9122STRK,	NRD9122SBPT * NRD9122STRK,
382 	rd9122S_sizes,	RD9134LID,	1,	"9122D",
383 	NRD7957BBPT,	NRD7957BTRK,	NRD7957BBPT * NRD7957BTRK,
384 	rd7957B_sizes,	RD7957BID,	0,	"7957B",
385 	NRD7958BBPT,	NRD7958BTRK,	NRD7958BBPT * NRD7958BTRK,
386 	rd7958B_sizes,	RD7958BID,	0,	"7958B",
387 	NRD7959BBPT,	NRD7959BTRK,	NRD7959BBPT * NRD7959BTRK,
388 	rd7959B_sizes,	RD7959BID,	0,	"7959B",
389 	NRD2200ABPT,	NRD2200ATRK,	NRD2200ABPT * NRD2200ATRK,
390 	rd2200A_sizes,	RD2200AID,	0,	"2200A",
391 	NRD2203ABPT,	NRD2203ATRK,	NRD2203ABPT * NRD2203ATRK,
392 	rd2203A_sizes,	RD2203AID,	0,	"2203A",
393 };
394 int nrdinfo = sizeof(rdinfo) / sizeof(rdinfo[0]);
395 
396 struct	buf rdtab[NRD];
397 
398 #define	rdunit(x)	(minor(x) >> 3)
399 #define rdpart(x)	(minor(x) & 0x7)
400 #define	rdpunit(x)	((x) & 7)
401 #define	b_cylin		b_resid
402 #define	RDRETRY		5
403 #define RDWAITC		1	/* min time for timeout in seconds */
404 
405 int rderrthresh = RDRETRY-1;	/* when to start reporting errors */
406 
407 rdinit(hd)
408 	register struct hp_device *hd;
409 {
410 	register struct rd_softc *rs = &rd_softc[hd->hp_unit];
411 
412 	rs->sc_hd = hd;
413 	rs->sc_punit = rdpunit(hd->hp_flags);
414 	rs->sc_type = rdident(rs, hd);
415 	if (rs->sc_type < 0)
416 		return(0);
417 	rs->sc_dq.dq_ctlr = hd->hp_ctlr;
418 	rs->sc_dq.dq_unit = hd->hp_unit;
419 	rs->sc_dq.dq_slave = hd->hp_slave;
420 	rs->sc_dq.dq_driver = &rddriver;
421 	rs->sc_info = &rdinfo[rs->sc_type];
422 	rs->sc_flags = RDF_ALIVE;
423 #ifdef DEBUG
424 	/* always report errors */
425 	if (rddebug & RDB_ERROR)
426 		rderrthresh = 0;
427 #endif
428 	return(1);
429 }
430 
431 rdident(rs, hd)
432 	struct rd_softc *rs;
433 	struct hp_device *hd;
434 {
435 	struct rd_describe desc;
436 	u_char stat, cmd[3];
437 	int unit, lunit;
438 	char name[7];
439 	register int ctlr, slave, id, i;
440 
441 	ctlr = hd->hp_ctlr;
442 	slave = hd->hp_slave;
443 	unit = rs->sc_punit;
444 	lunit = hd->hp_unit;
445 
446 	/*
447 	 * Grab device id and make sure:
448 	 * 1. It is a CS80 device.
449 	 * 2. It is one of the types we support.
450 	 * 3. If it is a 7946, we are accessing the disk unit (0)
451 	 */
452 	id = hpibid(ctlr, slave);
453 #ifdef DEBUG
454 	if (rddebug & RDB_IDENT)
455 		printf("hpibid(%d, %d) -> %x\n", ctlr, slave, id);
456 #endif
457 	if ((id & 0x200) == 0)
458 		return(-1);
459 	for (i = 0; i < nrdinfo; i++)
460 		if (id == rdinfo[i].hwid)
461 			break;
462 	if (i == nrdinfo || unit > rdinfo[i].maxunum)
463 		return(-1);
464 	id = i;
465 
466 	/*
467 	 * Reset drive and collect device description.
468 	 * Don't really use the description info right now but
469 	 * might come in handy in the future (for disk labels).
470 	 */
471 	rdreset(rs, hd);
472 	cmd[0] = C_SUNIT(unit);
473 	cmd[1] = C_SVOL(0);
474 	cmd[2] = C_DESC;
475 	hpibsend(ctlr, slave, C_CMD, cmd, sizeof(cmd));
476 	hpibrecv(ctlr, slave, C_EXEC, &desc, 37);
477 	hpibrecv(ctlr, slave, C_QSTAT, &stat, sizeof(stat));
478 	bzero(name, sizeof(name));
479 	if (!stat) {
480 		register int n = desc.d_name;
481 		for (i = 5; i >= 0; i--) {
482 			name[i] = (n & 0xf) + '0';
483 			n >>= 4;
484 		}
485 		/* use drive characteristics to calculate xfer rate */
486 		rs->sc_wpms = 1000000 * (desc.d_sectsize/2) / desc.d_blocktime;
487 	}
488 #ifdef DEBUG
489 	if (rddebug & RDB_IDENT) {
490 		printf("rd%d: name: %x ('%s')\n",
491 		       lunit, desc.d_name, name);
492 		printf("  iuw %x, maxxfr %d, ctype %d\n",
493 		       desc.d_iuw, desc.d_cmaxxfr, desc.d_ctype);
494 		printf("  utype %d, bps %d, blkbuf %d, burst %d, blktime %d\n",
495 		       desc.d_utype, desc.d_sectsize,
496 		       desc.d_blkbuf, desc.d_burstsize, desc.d_blocktime);
497 		printf("  avxfr %d, ort %d, atp %d, maxint %d, fv %x, rv %x\n",
498 		       desc.d_uavexfr, desc.d_retry, desc.d_access,
499 		       desc.d_maxint, desc.d_fvbyte, desc.d_rvbyte);
500 		printf("  maxcyl/head/sect %d/%d/%d, maxvsect %d, inter %d\n",
501 		       desc.d_maxcyl, desc.d_maxhead, desc.d_maxsect,
502 		       desc.d_maxvsectl, desc.d_interleave);
503 	}
504 #endif
505 	/*
506 	 * Take care of a couple of anomolies:
507 	 * 1. 7945A and 7946A both return same HW id
508 	 * 2. 9122S and 9134D both return same HW id
509 	 * 3. 9122D and 9134L both return same HW id
510 	 */
511 	switch (rdinfo[id].hwid) {
512 	case RD7946AID:
513 		if (bcmp(name, "079450", 6) == 0)
514 			id = RD7945A;
515 		else
516 			id = RD7946A;
517 		break;
518 
519 	case RD9134LID:
520 		if (bcmp(name, "091340", 6) == 0)
521 			id = RD9134L;
522 		else
523 			id = RD9122D;
524 		break;
525 
526 	case RD9134DID:
527 		if (bcmp(name, "091220", 6) == 0)
528 			id = RD9122S;
529 		else
530 			id = RD9134D;
531 		break;
532 	}
533 	printf("rd%d: %s\n", lunit, rdinfo[id].desc);
534 	return(id);
535 }
536 
537 rdreset(rs, hd)
538 	register struct rd_softc *rs;
539 	register struct hp_device *hd;
540 {
541 	u_char stat;
542 
543 	rs->sc_clear.c_unit = C_SUNIT(rs->sc_punit);
544 	rs->sc_clear.c_cmd = C_CLEAR;
545 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_TCMD, &rs->sc_clear,
546 		sizeof(rs->sc_clear));
547 	hpibswait(hd->hp_ctlr, hd->hp_slave);
548 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
549 	rs->sc_src.c_unit = C_SUNIT(RDCTLR);
550 	rs->sc_src.c_nop = C_NOP;
551 	rs->sc_src.c_cmd = C_SREL;
552 	rs->sc_src.c_param = C_REL;
553 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_src,
554 		sizeof(rs->sc_src));
555 	hpibswait(hd->hp_ctlr, hd->hp_slave);
556 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
557 	rs->sc_ssmc.c_unit = C_SUNIT(rs->sc_punit);
558 	rs->sc_ssmc.c_cmd = C_SSM;
559 	rs->sc_ssmc.c_refm = REF_MASK;
560 	rs->sc_ssmc.c_fefm = FEF_MASK;
561 	rs->sc_ssmc.c_aefm = AEF_MASK;
562 	rs->sc_ssmc.c_iefm = IEF_MASK;
563 	hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_ssmc,
564 		sizeof(rs->sc_ssmc));
565 	hpibswait(hd->hp_ctlr, hd->hp_slave);
566 	hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat));
567 #ifdef DEBUG
568 	rdstats[hd->hp_unit].rdresets++;
569 #endif
570 }
571 
572 int
573 rdopen(dev, flags, mode, p)
574 	dev_t dev;
575 	int flags, mode;
576 	struct proc *p;
577 {
578 	register int unit = rdunit(dev);
579 	register struct rd_softc *rs = &rd_softc[unit];
580 
581 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
582 		return(ENXIO);
583 	if (rs->sc_hd->hp_dk >= 0) {
584 		/* guess at xfer rate based on 3600 rpm (60 rps) */
585 		if (rs->sc_wpms == 0)
586 			rs->sc_wpms = 60 * rs->sc_info->nbpt * DEV_BSIZE / 2;
587 		dk_wpms[rs->sc_hd->hp_dk] = rs->sc_wpms;
588 	}
589 	return(0);
590 }
591 
592 rdstrategy(bp)
593 	register struct buf *bp;
594 {
595 	register int unit = rdunit(bp->b_dev);
596 	register struct rd_softc *rs = &rd_softc[unit];
597 	register struct size *pinfo = &rs->sc_info->sizes[rdpart(bp->b_dev)];
598 	register struct buf *dp = &rdtab[unit];
599 	register daddr_t bn;
600 	register int sz, s;
601 
602 #ifdef DEBUG
603 	if (rddebug & RDB_FOLLOW)
604 		printf("rdstrategy(%x): dev %x, bn %x, bcount %x, %c\n",
605 		       bp, bp->b_dev, bp->b_blkno, bp->b_bcount,
606 		       (bp->b_flags & B_READ) ? 'R' : 'W');
607 #endif
608 	bn = bp->b_blkno;
609 	sz = howmany(bp->b_bcount, DEV_BSIZE);
610 	if (bn < 0 || bn + sz > pinfo->nblocks) {
611 		sz = pinfo->nblocks - bn;
612 		if (sz == 0) {
613 			bp->b_resid = bp->b_bcount;
614 			goto done;
615 		}
616 		if (sz < 0) {
617 			bp->b_error = EINVAL;
618 			bp->b_flags |= B_ERROR;
619 			goto done;
620 		}
621 		bp->b_bcount = dbtob(sz);
622 	}
623 	bp->b_cylin = bn / rs->sc_info->nbpc + pinfo->cyloff;
624 	s = splbio();
625 	disksort(dp, bp);
626 	if (dp->b_active == 0) {
627 		dp->b_active = 1;
628 		rdustart(unit);
629 	}
630 	splx(s);
631 	return;
632 done:
633 	biodone(bp);
634 }
635 
636 /*
637  * Called from timeout() when handling maintenance releases
638  */
639 rdrestart(unit)
640 	int unit;
641 {
642 	int s = splbio();
643 	rdustart(unit);
644 	splx(s);
645 }
646 
647 rdustart(unit)
648 	register int unit;
649 {
650 	register struct buf *bp;
651 	register struct rd_softc *rs = &rd_softc[unit];
652 
653 	bp = rdtab[unit].b_actf;
654 	rs->sc_addr = bp->b_un.b_addr;
655 	rs->sc_resid = bp->b_bcount;
656 	if (hpibreq(&rs->sc_dq))
657 		rdstart(unit);
658 }
659 
660 rdstart(unit)
661 	register int unit;
662 {
663 	register struct rd_softc *rs = &rd_softc[unit];
664 	register struct buf *bp = rdtab[unit].b_actf;
665 	register struct hp_device *hp = rs->sc_hd;
666 	register int part;
667 
668 again:
669 #ifdef DEBUG
670 	if (rddebug & RDB_FOLLOW)
671 		printf("rdstart(%d): bp %x, %c\n", unit, bp,
672 		       (bp->b_flags & B_READ) ? 'R' : 'W');
673 #endif
674 	part = rdpart(bp->b_dev);
675 	rs->sc_flags |= RDF_SEEK;
676 	rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit);
677 	rs->sc_ioc.c_volume = C_SVOL(0);
678 	rs->sc_ioc.c_saddr = C_SADDR;
679 	rs->sc_ioc.c_hiaddr = 0;
680 	rs->sc_ioc.c_addr = RDBTOS(bp->b_blkno + rs->sc_info->nbpc *
681 		rs->sc_info->sizes[part].cyloff);
682 	rs->sc_ioc.c_nop2 = C_NOP;
683 	rs->sc_ioc.c_slen = C_SLEN;
684 	rs->sc_ioc.c_len = rs->sc_resid;
685 	rs->sc_ioc.c_cmd = bp->b_flags & B_READ ? C_READ : C_WRITE;
686 #ifdef DEBUG
687 	if (rddebug & RDB_IO)
688 		printf("rdstart: hpibsend(%x, %x, %x, %x, %x)\n",
689 		       hp->hp_ctlr, hp->hp_slave, C_CMD,
690 		       &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2);
691 #endif
692 	if (hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD, &rs->sc_ioc.c_unit,
693 		     sizeof(rs->sc_ioc)-2) == sizeof(rs->sc_ioc)-2) {
694 		if (hp->hp_dk >= 0) {
695 			dk_busy |= 1 << hp->hp_dk;
696 			dk_seek[hp->hp_dk]++;
697 		}
698 #ifdef DEBUG
699 		if (rddebug & RDB_IO)
700 			printf("rdstart: hpibawait(%x)\n", hp->hp_ctlr);
701 #endif
702 		hpibawait(hp->hp_ctlr);
703 		return;
704 	}
705 	/*
706 	 * Experience has shown that the hpibwait in this hpibsend will
707 	 * occasionally timeout.  It appears to occur mostly on old 7914
708 	 * drives with full maintenance tracks.  We should probably
709 	 * integrate this with the backoff code in rderror.
710 	 */
711 #ifdef DEBUG
712 	if (rddebug & RDB_ERROR)
713 		printf("rd%d: rdstart: cmd %x adr %d blk %d len %d ecnt %d\n",
714 		       unit, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr,
715 		       bp->b_blkno, rs->sc_resid, rdtab[unit].b_errcnt);
716 	rdstats[unit].rdretries++;
717 #endif
718 	rs->sc_flags &= ~RDF_SEEK;
719 	rdreset(rs, hp);
720 	if (rdtab[unit].b_errcnt++ < RDRETRY)
721 		goto again;
722 	printf("rd%d: rdstart err: cmd 0x%x sect %d blk %d len %d\n",
723 	       unit, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr,
724 	       bp->b_blkno, rs->sc_resid);
725 	rdtab[unit].b_errcnt = 0;
726 	rdtab[unit].b_actf = bp->b_actf;
727 	bp->b_flags |= B_ERROR;
728 	bp->b_error = EIO;
729 	bp->b_resid = 0;
730 	biodone(bp);
731 	hpibfree(&rs->sc_dq);
732 	bp = rdtab[unit].b_actf;
733 	if (bp == NULL) {
734 		rdtab[unit].b_active = 0;
735 		return;
736 	}
737 	rs->sc_addr = bp->b_un.b_addr;
738 	rs->sc_resid = bp->b_bcount;
739 	if (hpibreq(&rs->sc_dq))
740 		goto again;
741 }
742 
743 rdgo(unit)
744 	register int unit;
745 {
746 	register struct rd_softc *rs = &rd_softc[unit];
747 	register struct hp_device *hp = rs->sc_hd;
748 	struct buf *bp = rdtab[unit].b_actf;
749 
750 	if (hp->hp_dk >= 0) {
751 		dk_busy |= 1 << hp->hp_dk;
752 		dk_xfer[hp->hp_dk]++;
753 		dk_wds[hp->hp_dk] += rs->sc_resid >> 6;
754 	}
755 	hpibgo(hp->hp_ctlr, hp->hp_slave, C_EXEC,
756 	       rs->sc_addr, rs->sc_resid, bp->b_flags & B_READ);
757 }
758 
759 rdintr(unit)
760 	register int unit;
761 {
762 	register struct rd_softc *rs = &rd_softc[unit];
763 	register struct buf *bp = rdtab[unit].b_actf;
764 	register struct hp_device *hp = rs->sc_hd;
765 	u_char stat = 13;	/* in case hpibrecv fails */
766 	int rv, restart;
767 
768 #ifdef DEBUG
769 	if (rddebug & RDB_FOLLOW)
770 		printf("rdintr(%d): bp %x, %c, flags %x\n", unit, bp,
771 		       (bp->b_flags & B_READ) ? 'R' : 'W', rs->sc_flags);
772 	if (bp == NULL) {
773 		printf("rd%d: bp == NULL\n", unit);
774 		return;
775 	}
776 #endif
777 	if (hp->hp_dk >= 0)
778 		dk_busy &= ~(1 << hp->hp_dk);
779 	if (rs->sc_flags & RDF_SEEK) {
780 		rs->sc_flags &= ~RDF_SEEK;
781 		if (hpibustart(hp->hp_ctlr))
782 			rdgo(unit);
783 		return;
784 	}
785 	if ((rs->sc_flags & RDF_SWAIT) == 0) {
786 #ifdef DEBUG
787 		rdstats[unit].rdpolltries++;
788 #endif
789 		if (hpibpptest(hp->hp_ctlr, hp->hp_slave) == 0) {
790 #ifdef DEBUG
791 			rdstats[unit].rdpollwaits++;
792 #endif
793 			if (hp->hp_dk >= 0)
794 				dk_busy |= 1 << hp->hp_dk;
795 			rs->sc_flags |= RDF_SWAIT;
796 			hpibawait(hp->hp_ctlr);
797 			return;
798 		}
799 	} else
800 		rs->sc_flags &= ~RDF_SWAIT;
801 	rv = hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1);
802 	if (rv != 1 || stat) {
803 #ifdef DEBUG
804 		if (rddebug & RDB_ERROR)
805 			printf("rdintr: recv failed or bad stat %d\n", stat);
806 #endif
807 		restart = rderror(unit);
808 #ifdef DEBUG
809 		rdstats[unit].rdretries++;
810 #endif
811 		if (rdtab[unit].b_errcnt++ < RDRETRY) {
812 			if (restart)
813 				rdstart(unit);
814 			return;
815 		}
816 		bp->b_flags |= B_ERROR;
817 		bp->b_error = EIO;
818 	}
819 	rdtab[unit].b_errcnt = 0;
820 	rdtab[unit].b_actf = bp->b_actf;
821 	bp->b_resid = 0;
822 	biodone(bp);
823 	hpibfree(&rs->sc_dq);
824 	if (rdtab[unit].b_actf)
825 		rdustart(unit);
826 	else
827 		rdtab[unit].b_active = 0;
828 }
829 
830 rdstatus(rs)
831 	register struct rd_softc *rs;
832 {
833 	register int c, s;
834 	u_char stat;
835 	int rv;
836 
837 	c = rs->sc_hd->hp_ctlr;
838 	s = rs->sc_hd->hp_slave;
839 	rs->sc_rsc.c_unit = C_SUNIT(rs->sc_punit);
840 	rs->sc_rsc.c_sram = C_SRAM;
841 	rs->sc_rsc.c_ram = C_RAM;
842 	rs->sc_rsc.c_cmd = C_STATUS;
843 	bzero((caddr_t)&rs->sc_stat, sizeof(rs->sc_stat));
844 	rv = hpibsend(c, s, C_CMD, &rs->sc_rsc, sizeof(rs->sc_rsc));
845 	if (rv != sizeof(rs->sc_rsc)) {
846 #ifdef DEBUG
847 		if (rddebug & RDB_STATUS)
848 			printf("rdstatus: send C_CMD failed %d != %d\n",
849 			       rv, sizeof(rs->sc_rsc));
850 #endif
851 		return(1);
852 	}
853 	rv = hpibrecv(c, s, C_EXEC, &rs->sc_stat, sizeof(rs->sc_stat));
854 	if (rv != sizeof(rs->sc_stat)) {
855 #ifdef DEBUG
856 		if (rddebug & RDB_STATUS)
857 			printf("rdstatus: send C_EXEC failed %d != %d\n",
858 			       rv, sizeof(rs->sc_stat));
859 #endif
860 		return(1);
861 	}
862 	rv = hpibrecv(c, s, C_QSTAT, &stat, 1);
863 	if (rv != 1 || stat) {
864 #ifdef DEBUG
865 		if (rddebug & RDB_STATUS)
866 			printf("rdstatus: recv failed %d or bad stat %d\n",
867 			       rv, stat);
868 #endif
869 		return(1);
870 	}
871 	return(0);
872 }
873 
874 /*
875  * Deal with errors.
876  * Returns 1 if request should be restarted,
877  * 0 if we should just quietly give up.
878  */
879 rderror(unit)
880 	int unit;
881 {
882 	struct rd_softc *rs = &rd_softc[unit];
883 	register struct rd_stat *sp;
884 	struct buf *bp;
885 	daddr_t hwbn, pbn;
886 
887 	if (rdstatus(rs)) {
888 #ifdef DEBUG
889 		printf("rd%d: couldn't get status\n", unit);
890 #endif
891 		rdreset(rs, rs->sc_hd);
892 		return(1);
893 	}
894 	sp = &rs->sc_stat;
895 	if (sp->c_fef & FEF_REXMT)
896 		return(1);
897 	if (sp->c_fef & FEF_PF) {
898 		rdreset(rs, rs->sc_hd);
899 		return(1);
900 	}
901 	/*
902 	 * Unit requests release for internal maintenance.
903 	 * We just delay awhile and try again later.  Use expontially
904 	 * increasing backoff ala ethernet drivers since we don't really
905 	 * know how long the maintenance will take.  With RDWAITC and
906 	 * RDRETRY as defined, the range is 1 to 32 seconds.
907 	 */
908 	if (sp->c_fef & FEF_IMR) {
909 		extern int hz;
910 		int rdtimo = RDWAITC << rdtab[unit].b_errcnt;
911 #ifdef DEBUG
912 		printf("rd%d: internal maintenance, %d second timeout\n",
913 		       unit, rdtimo);
914 		rdstats[unit].rdtimeouts++;
915 #endif
916 		hpibfree(&rs->sc_dq);
917 		timeout(rdrestart, unit, rdtimo*hz);
918 		return(0);
919 	}
920 	/*
921 	 * Only report error if we have reached the error reporting
922 	 * threshhold.  By default, this will only report after the
923 	 * retry limit has been exceeded.
924 	 */
925 	if (rdtab[unit].b_errcnt < rderrthresh)
926 		return(1);
927 
928 	/*
929 	 * First conjure up the block number at which the error occured.
930 	 * Note that not all errors report a block number, in that case
931 	 * we just use b_blkno.
932  	 */
933 	bp = rdtab[unit].b_actf;
934 	pbn = rs->sc_info->nbpc *
935 		rs->sc_info->sizes[rdpart(bp->b_dev)].cyloff;
936 	if ((sp->c_fef & FEF_CU) || (sp->c_fef & FEF_DR) ||
937 	    (sp->c_ief & IEF_RRMASK)) {
938 		hwbn = RDBTOS(pbn + bp->b_blkno);
939 		pbn = bp->b_blkno;
940 	} else {
941 		hwbn = sp->c_blk;
942 		pbn = RDSTOB(hwbn) - pbn;
943 	}
944 	/*
945 	 * Now output a generic message suitable for badsect.
946 	 * Note that we don't use harderr cuz it just prints
947 	 * out b_blkno which is just the beginning block number
948 	 * of the transfer, not necessary where the error occured.
949 	 */
950 	printf("rd%d%c: hard error sn%d\n",
951 	       rdunit(bp->b_dev), 'a'+rdpart(bp->b_dev), pbn);
952 	/*
953 	 * Now report the status as returned by the hardware with
954 	 * attempt at interpretation (unless debugging).
955 	 */
956 	printf("rd%d %s error:",
957 	       unit, (bp->b_flags & B_READ) ? "read" : "write");
958 #ifdef DEBUG
959 	if (rddebug & RDB_ERROR) {
960 		/* status info */
961 		printf("\n    volume: %d, unit: %d\n",
962 		       (sp->c_vu>>4)&0xF, sp->c_vu&0xF);
963 		rdprinterr("reject", sp->c_ref, err_reject);
964 		rdprinterr("fault", sp->c_fef, err_fault);
965 		rdprinterr("access", sp->c_aef, err_access);
966 		rdprinterr("info", sp->c_ief, err_info);
967 		printf("    block: %d, P1-P10: ", hwbn);
968 		printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8));
969 		printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8));
970 		printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4));
971 		/* command */
972 		printf("    ioc: ");
973 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_pad, 8));
974 		printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_hiaddr, 4));
975 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_addr, 8));
976 		printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_nop2, 4));
977 		printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_len, 8));
978 		printf("%s\n", hexstr(*(u_short *)&rs->sc_ioc.c_cmd, 4));
979 		return(1);
980 	}
981 #endif
982 	printf(" v%d u%d, R0x%x F0x%x A0x%x I0x%x\n",
983 	       (sp->c_vu>>4)&0xF, sp->c_vu&0xF,
984 	       sp->c_ref, sp->c_fef, sp->c_aef, sp->c_ief);
985 	printf("P1-P10: ");
986 	printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8));
987 	printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8));
988 	printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4));
989 	return(1);
990 }
991 
992 int
993 rdread(dev, uio, flags)
994 	dev_t dev;
995 	struct uio *uio;
996 	int flags;
997 {
998 	register int unit = rdunit(dev);
999 
1000 	return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
1001 }
1002 
1003 int
1004 rdwrite(dev, uio, flags)
1005 	dev_t dev;
1006 	struct uio *uio;
1007 	int flags;
1008 {
1009 	register int unit = rdunit(dev);
1010 
1011 	return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
1012 }
1013 
1014 int
1015 rdioctl(dev, cmd, data, flag, p)
1016 	dev_t dev;
1017 	int cmd;
1018 	caddr_t data;
1019 	int flag;
1020 	struct proc *p;
1021 {
1022 	return(EINVAL);
1023 }
1024 
1025 int
1026 rdsize(dev)
1027 	dev_t dev;
1028 {
1029 	register int unit = rdunit(dev);
1030 	register struct rd_softc *rs = &rd_softc[unit];
1031 
1032 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
1033 		return(-1);
1034 	return(rs->sc_info->sizes[rdpart(dev)].nblocks);
1035 }
1036 
1037 #ifdef DEBUG
1038 rdprinterr(str, err, tab)
1039 	char *str;
1040 	short err;
1041 	char *tab[];
1042 {
1043 	register int i;
1044 	int printed;
1045 
1046 	if (err == 0)
1047 		return;
1048 	printf("    %s error field:", str, err);
1049 	printed = 0;
1050 	for (i = 0; i < 16; i++)
1051 		if (err & (0x8000 >> i))
1052 			printf("%s%s", printed++ ? " + " : " ", tab[i]);
1053 	printf("\n");
1054 }
1055 #endif
1056 
1057 /*
1058  * Non-interrupt driven, non-dma dump routine.
1059  */
1060 int
1061 rddump(dev)
1062 	dev_t dev;
1063 {
1064 	int part = rdpart(dev);
1065 	int unit = rdunit(dev);
1066 	register struct rd_softc *rs = &rd_softc[unit];
1067 	register struct hp_device *hp = rs->sc_hd;
1068 	register daddr_t baddr;
1069 	register int maddr, pages, i;
1070 	char stat;
1071 	extern int lowram, dumpsize;
1072 #ifdef DEBUG
1073 	extern int pmapdebug;
1074 	pmapdebug = 0;
1075 #endif
1076 
1077 	pages = dumpsize;
1078 #ifdef DEBUG
1079 	if (rddebug & RDB_DUMP)
1080 		printf("rddump(%x): u %d p %d dumplo %d ram %x pmem %d\n",
1081 		       dev, unit, part, dumplo, lowram, ctod(pages));
1082 #endif
1083 	/* is drive ok? */
1084 	if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0)
1085 		return (ENXIO);
1086 	/* HPIB idle? */
1087 	if (!hpibreq(&rs->sc_dq)) {
1088 #ifdef DEBUG
1089 		/* is this a safe thing to do?? */
1090 		hpibreset(hp->hp_ctlr);
1091 		rdreset(rs, rs->sc_hd);
1092 		printf("[ drive %d reset ] ", unit);
1093 #else
1094 		return (EFAULT);
1095 #endif
1096 	}
1097 	/* dump parameters in range? */
1098 	if (dumplo < 0 || dumplo >= rs->sc_info->sizes[part].nblocks)
1099 		return (EINVAL);
1100 	if (dumplo + ctod(pages) > rs->sc_info->sizes[part].nblocks)
1101 		pages = dtoc(rs->sc_info->sizes[part].nblocks - dumplo);
1102 	maddr = lowram;
1103 	baddr = dumplo + rs->sc_info->nbpc * rs->sc_info->sizes[part].cyloff;
1104 #ifdef DEBUG
1105 	if (rddebug & RDB_DUMP)
1106 		printf("rddump: dumping %d pages from %x to disk block %d\n",
1107 		       pages, maddr, baddr);
1108 #endif
1109 	for (i = 0; i < pages; i++) {
1110 #ifdef DEBUG
1111 #define NPGMB	(1024*1024/NBPG)
1112 		/* print out how many Mbs we have dumped */
1113 		if (i && (i % NPGMB) == 0)
1114 			printf("%d ", i / NPGMB);
1115 #undef NPBMG
1116 #endif
1117 		rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit);
1118 		rs->sc_ioc.c_volume = C_SVOL(0);
1119 		rs->sc_ioc.c_saddr = C_SADDR;
1120 		rs->sc_ioc.c_hiaddr = 0;
1121 		rs->sc_ioc.c_addr = RDBTOS(baddr);
1122 		rs->sc_ioc.c_nop2 = C_NOP;
1123 		rs->sc_ioc.c_slen = C_SLEN;
1124 		rs->sc_ioc.c_len = NBPG;
1125 		rs->sc_ioc.c_cmd = C_WRITE;
1126 		hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD,
1127 			 &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2);
1128 		if (hpibswait(hp->hp_ctlr, hp->hp_slave)) {
1129 #ifdef DEBUG
1130 			if (rddebug & RDB_DUMP)
1131 				printf("rddump: IOC wait timeout\n");
1132 #endif
1133 			return (EIO);
1134 		}
1135 		pmap_enter(pmap_kernel(), vmmap, maddr, VM_PROT_READ, TRUE);
1136 		hpibsend(hp->hp_ctlr, hp->hp_slave, C_EXEC, vmmap, NBPG);
1137 		if (hpibswait(hp->hp_ctlr, hp->hp_slave)) {
1138 #ifdef DEBUG
1139 			if (rddebug & RDB_DUMP)
1140 				printf("rddump: write wait timeout\n");
1141 #endif
1142 		}
1143 		hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1);
1144 		if (stat) {
1145 #ifdef DEBUG
1146 			if (rddebug & RDB_DUMP)
1147 				printf("rddump: write failed, status %x\n",
1148 				       stat);
1149 #endif
1150 			return (EIO);
1151 		}
1152 		maddr += NBPG;
1153 		baddr += ctod(1);
1154 	}
1155 	return (0);
1156 }
1157 #endif
1158