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