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