1 /*-
2 * Copyright (c) 1982, 1986 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 *
7 * @(#)hp.c 7.23 (Berkeley) 05/08/91
8 */
9
10 #ifdef HPDEBUG
11 int hpdebug;
12 #endif
13 #ifdef HPBDEBUG
14 int hpbdebug;
15 #endif
16
17 #include "hp.h"
18 #if NHP > 0
19 /*
20 * HP disk driver for RP0x+RMxx+ML11
21 *
22 * TODO:
23 * see if DCLR and/or RELEASE set attention status
24 */
25 #include "sys/param.h"
26 #include "sys/systm.h"
27 #include "sys/dkstat.h"
28 #include "sys/buf.h"
29 #include "sys/conf.h"
30 #include "sys/file.h"
31 #include "sys/user.h"
32 #include "sys/map.h"
33 #include "../include/mtpr.h"
34 #include "sys/vm.h"
35 #include "sys/cmap.h"
36 #include "sys/dkbad.h"
37 #include "sys/disklabel.h"
38 #include "sys/ioctl.h"
39 #include "sys/syslog.h"
40 #include "sys/stat.h"
41
42 #include "../include/pte.h"
43 #include "mbareg.h"
44 #include "mbavar.h"
45 #include "hpreg.h"
46
47 #define COMPAT_42
48 #define B_FORMAT B_XXX
49
50 /*
51 * Table of supported Massbus drive types.
52 * When using unlabeled packs, slot numbers here
53 * are used as indices into the partition tables.
54 * Slots are left for those drives divined from other means
55 * (e.g. SI, AMPEX, etc.).
56 */
57 short hptypes[] = {
58 #define HPDT_RM03 0
59 MBDT_RM03,
60 #define HPDT_RM05 1
61 MBDT_RM05,
62 #define HPDT_RP06 2
63 MBDT_RP06,
64 #define HPDT_RM80 3
65 MBDT_RM80,
66 #define HPDT_RP04 4
67 MBDT_RP04,
68 #define HPDT_RP05 5
69 MBDT_RP05,
70 #define HPDT_RP07 6
71 MBDT_RP07,
72 #define HPDT_ML11A 7
73 MBDT_ML11A,
74 #define HPDT_ML11B 8
75 MBDT_ML11B,
76 #define HPDT_9775 9
77 -1,
78 #define HPDT_9730 10
79 -1,
80 #define HPDT_CAPRICORN 11
81 -1,
82 #define HPDT_EAGLE 12
83 -1,
84 #define HPDT_9300 13
85 -1,
86 #define HPDT_RM02 14
87 MBDT_RM02, /* beware, actually mapped */
88 #define HPDT_2361 15
89 -1,
90 #define HPDT_2361A 16
91 -1,
92 0
93 };
94
95 struct mba_device *hpinfo[NHP];
96 int hpattach(),hpustart(),hpstart(),hpdtint(),hpstrategy();
97 struct mba_driver hpdriver =
98 { hpattach, 0, hpustart, hpstart, hpdtint, 0,
99 hptypes, "hp", 0, hpinfo };
100
101 u_char hp_offset[16] = {
102 HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
103 HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
104 HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
105 0, 0, 0, 0,
106 };
107
108 struct disklabel hplabel[NHP];
109 struct dkbad hpbad[NHP];
110
111 struct hpsoftc {
112 u_char sc_recal; /* recalibrate state */
113 u_char sc_doseeks; /* perform explicit seeks */
114 #ifdef COMPAT_42
115 u_char sc_hdr; /* next i/o includes header */
116 #endif
117 int sc_state; /* open fsm */
118 int sc_wlabel; /* label sector is currently writable */
119 u_long sc_openpart; /* bit mask of open subunits */
120 u_long sc_copenpart; /* bit mask of open character subunits */
121 u_long sc_bopenpart; /* bit mask of open block subunits */
122 daddr_t sc_mlsize; /* ML11 size */
123 int sc_blkdone; /* amount sucessfully transfered */
124 daddr_t sc_badbn; /* replacement block number */
125 int sc_status; /* copy of drive status reg. after format */
126 int sc_hpds; /* copy of hpds reg. after format */
127 int sc_er1; /* copy of error reg. 1 after format */
128 int sc_er2; /* copy of error reg. 2 after format */
129 } hpsoftc[NHP];
130
131 /*
132 * Drive states. Used during steps of open/initialization.
133 * States < OPEN (> 0) are transient, during an open operation.
134 * OPENRAW is used for unlabeled disks,
135 * to inhibit bad-sector forwarding or allow format operations.
136 */
137 #define CLOSED 0 /* disk is closed. */
138 #define WANTOPEN 1 /* open requested, not started */
139 #define WANTOPENRAW 2 /* open requested, no label */
140 #define RDLABEL 3 /* reading pack label */
141 #define RDBADTBL 4 /* reading bad-sector table */
142 #define OPEN 5 /* initialized and ready */
143 #define OPENRAW 6 /* open, no label or badsect */
144
145 #define b_cylin b_resid
146
147 /* #define ML11 0 to remove ML11 support */
148 #define ML11(type) ((type) == HPDT_ML11A)
149 #define RP06(type) (hptypes[type] <= MBDT_RP06)
150 #define RM80(type) ((type) == HPDT_RM80)
151
152 #define hpunit(dev) (minor(dev) >> 3)
153 #define hppart(dev) (minor(dev) & 07)
154 #define hpminor(unit, part) (((unit) << 3) | (part))
155
156 #define MASKREG(reg) ((reg)&0xffff)
157 #ifdef lint
158 #define HPWAIT(mi, addr) (hpwait(mi))
159 #else
160 #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi))
161 #endif
162
163 /*ARGSUSED*/
164 hpattach(mi, slave)
165 struct mba_device *mi;
166 {
167 register int unit = mi->mi_unit;
168 extern int cold;
169
170 if (cold) {
171 /*
172 * Try to initialize device and read pack label.
173 */
174 if (hpinit(hpminor(unit, 0), 0) == 0) {
175 printf(": %s", hplabel[unit].d_typename);
176 #ifdef notyet
177 addswap(makedev(HPMAJOR, hpminor(unit, 0)),
178 &hplabel[unit]);
179 #endif
180 } else
181 printf(": offline");
182 }
183 }
184
hpopen(dev,flags,fmt)185 hpopen(dev, flags, fmt)
186 dev_t dev;
187 int flags, fmt;
188 {
189 register int unit = hpunit(dev);
190 register struct hpsoftc *sc;
191 register struct disklabel *lp;
192 register struct partition *pp;
193 struct mba_device *mi;
194 int s, error, part = hppart(dev), mask = 1 << part;
195 daddr_t start, end;
196
197 if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
198 return (ENXIO);
199 sc = &hpsoftc[unit];
200 lp = &hplabel[unit];
201
202 s = spl5();
203 while (sc->sc_state != OPEN && sc->sc_state != OPENRAW &&
204 sc->sc_state != CLOSED)
205 if (error = tsleep((caddr_t)sc, (PZERO+1) | PCATCH,
206 devopn, 0)) {
207 splx(s);
208 return (error);
209 }
210 splx(s);
211 if (sc->sc_state != OPEN && sc->sc_state != OPENRAW)
212 if (error = hpinit(dev, flags))
213 return (error);
214 if (part >= lp->d_npartitions)
215 return (ENXIO);
216 /*
217 * Warn if a partion is opened
218 * that overlaps another partition which is open
219 * unless one is the "raw" partition (whole disk).
220 */
221 #define RAWPART 2 /* 'c' partition */ /* XXX */
222 if ((sc->sc_openpart & mask) == 0 && part != RAWPART) {
223 pp = &lp->d_partitions[part];
224 start = pp->p_offset;
225 end = pp->p_offset + pp->p_size;
226 for (pp = lp->d_partitions;
227 pp < &lp->d_partitions[lp->d_npartitions]; pp++) {
228 if (pp->p_offset + pp->p_size <= start ||
229 pp->p_offset >= end)
230 continue;
231 if (pp - lp->d_partitions == RAWPART)
232 continue;
233 if (sc->sc_openpart & (1 << (pp - lp->d_partitions)))
234 log(LOG_WARNING,
235 "hp%d%c: overlaps open partition (%c)\n",
236 unit, part + 'a',
237 pp - lp->d_partitions + 'a');
238 }
239 }
240 switch (fmt) {
241 case S_IFCHR:
242 sc->sc_copenpart |= mask;
243 break;
244 case S_IFBLK:
245 sc->sc_bopenpart |= mask;
246 break;
247 }
248 sc->sc_openpart |= mask;
249 return (0);
250 }
251
252 /* ARGSUSED */
hpclose(dev,flags,fmt)253 hpclose(dev, flags, fmt)
254 dev_t dev;
255 int flags, fmt;
256 {
257 register int unit = hpunit(dev);
258 register struct hpsoftc *sc;
259 struct mba_device *mi;
260 int s, mask = 1 << hppart(dev);
261
262 sc = &hpsoftc[unit];
263 mi = hpinfo[unit];
264 switch (fmt) {
265 case S_IFCHR:
266 sc->sc_copenpart &= ~mask;
267 break;
268 case S_IFBLK:
269 sc->sc_bopenpart &= ~mask;
270 break;
271 }
272 sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart;
273
274 /*
275 * Should wait for I/O to complete on this partition
276 * even if others are open, but wait for work on blkflush().
277 */
278 if (sc->sc_openpart == 0) {
279 s = spl5();
280 while (mi->mi_tab.b_actf)
281 sleep((caddr_t)sc, PZERO - 1);
282 splx(s);
283 sc->sc_state = CLOSED;
284 sc->sc_wlabel = 0;
285 }
286 return (0);
287 }
288
hpinit(dev,flags)289 hpinit(dev, flags)
290 dev_t dev;
291 int flags;
292 {
293 register struct hpsoftc *sc;
294 register struct buf *bp;
295 register struct disklabel *lp;
296 struct mba_device *mi;
297 struct hpdevice *hpaddr;
298 struct dkbad *db;
299 char *msg, *readdisklabel();
300 int unit, i, error = 0;
301
302 unit = hpunit(dev);
303 sc = &hpsoftc[unit];
304 lp = &hplabel[unit];
305 mi = hpinfo[unit];
306 hpaddr = (struct hpdevice *)mi->mi_drv;
307
308 sc->sc_state = WANTOPEN;
309 /*
310 * Use the default sizes until we've read the label,
311 * or longer if there isn't one there.
312 */
313 if (lp->d_secpercyl == 0) {
314 lp->d_secsize = DEV_BSIZE;
315 lp->d_nsectors = 32;
316 lp->d_ntracks = 20;
317 lp->d_secpercyl = 32*20;
318 lp->d_npartitions = 1;
319 lp->d_partitions[0].p_offset = 0;
320 lp->d_partitions[0].p_size = LABELSECTOR + 1;
321 }
322
323 if (flags & O_NDELAY)
324 goto raw;
325
326 /*
327 * Map all ML11's to the same type. Also calculate
328 * transfer rates based on device characteristics.
329 * Set up dummy label with all that's needed.
330 */
331 if (mi->mi_type == MBDT_ML11A || mi->mi_type == MBDT_ML11B) {
332 register int trt;
333
334 sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
335 if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
336 sc->sc_mlsize >>= 2;
337 if (mi->mi_dk >= 0) {
338 trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
339 dk_wpms[mi->mi_dk] = (1<<(20-trt));
340 }
341 mi->mi_type = MBDT_ML11A;
342 lp->d_partitions[0].p_size = sc->sc_mlsize;
343 lp->d_secpercyl = sc->sc_mlsize;
344 goto raw;
345 }
346
347 /*
348 * Preset, pack acknowledge will be done in hpstart
349 * during first read operation.
350 */
351 if (msg = readdisklabel(dev, hpstrategy, lp)) {
352 if (cold)
353 printf(": %s", msg);
354 else
355 log(LOG_ERR, "hp%d: %s\n", unit, msg);
356 #ifdef COMPAT_42
357 if (hpmaptype(mi, lp) == 0)
358 #endif
359 goto raw;
360 }
361
362 /*
363 * Seconds per word = (60 / rpm) / (nsectors * secsize/2)
364 */
365 if (mi->mi_dk >= 0 && lp->d_rpm)
366 dk_wpms[mi->mi_dk] =
367 (lp->d_rpm * lp->d_nsectors * lp->d_secsize) / 120;
368 /*
369 * Read bad sector table into memory.
370 */
371 bp = geteblk(DEV_BSIZE); /* max sector size */
372 bp->b_dev = dev;
373 sc->sc_state = RDBADTBL;
374 i = 0;
375 do {
376 bp->b_flags = B_BUSY | B_READ;
377 bp->b_blkno = lp->d_secperunit - lp->d_nsectors + i;
378 bp->b_bcount = lp->d_secsize;
379 bp->b_cylin = lp->d_ncylinders - 1;
380 hpstrategy(bp);
381 (void) biowait(bp);
382 } while ((bp->b_flags & B_ERROR) && (i += 2) < 10 &&
383 i < lp->d_nsectors);
384 db = (struct dkbad *)(bp->b_un.b_addr);
385 if ((bp->b_flags & B_ERROR) == 0 && db->bt_mbz == 0 &&
386 db->bt_flag == 0) {
387 hpbad[unit] = *db;
388 } else
389 log(LOG_ERR, "hp%d: %s bad-sector file\n", unit,
390 (bp->b_flags & B_ERROR) ? "can't read" : "format error in");
391 sc->sc_state = OPEN;
392 bp->b_flags = B_INVAL | B_AGE;
393 brelse(bp);
394 wakeup((caddr_t)sc);
395 return (error);
396
397 raw:
398 if (cold)
399 sc->sc_state = CLOSED;
400 else {
401 sc->sc_state = OPENRAW;
402 wakeup((caddr_t)sc);
403 }
404 return (error);
405 }
406
hpstrategy(bp)407 hpstrategy(bp)
408 register struct buf *bp;
409 {
410 register struct mba_device *mi;
411 register struct disklabel *lp;
412 register struct hpsoftc *sc;
413 register int unit;
414 daddr_t sz, maxsz;
415 int xunit = hppart(bp->b_dev);
416 int s;
417
418 sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
419 unit = hpunit(bp->b_dev);
420 if (unit >= NHP) {
421 bp->b_error = ENXIO;
422 goto bad;
423 }
424 mi = hpinfo[unit];
425 sc = &hpsoftc[unit];
426 lp = &hplabel[unit];
427 if (mi == 0 || mi->mi_alive == 0) {
428 bp->b_error = ENXIO;
429 goto bad;
430 }
431 #ifdef COMPAT_42
432 if (sc->sc_hdr) { /* XXX */
433 if (bp->b_bcount == 516)
434 bp->b_flags |= B_FORMAT;
435 sc->sc_hdr = 0;
436 }
437 #endif
438 if (sc->sc_state < OPEN)
439 goto q;
440 if (sc->sc_state != OPEN && (bp->b_flags & (B_READ|B_FORMAT)) == 0) {
441 bp->b_error = EROFS;
442 goto bad;
443 }
444 if ((sc->sc_openpart & (1 << xunit)) == 0) {
445 bp->b_error = ENODEV;
446 goto bad;
447 }
448 maxsz = lp->d_partitions[xunit].p_size;
449 if (bp->b_blkno + lp->d_partitions[xunit].p_offset <= LABELSECTOR &&
450 #if LABELSECTOR != 0
451 bp->b_blkno + lp->d_partitions[xunit].p_offset + sz > LABELSECTOR &&
452 #endif
453 (bp->b_flags & B_READ) == 0 && sc->sc_wlabel == 0) {
454 bp->b_error = EROFS;
455 goto bad;
456 }
457 if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
458 if (bp->b_blkno == maxsz) {
459 bp->b_resid = bp->b_bcount;
460 goto done;
461 }
462 sz = maxsz - bp->b_blkno;
463 if (sz <= 0) {
464 bp->b_error = EINVAL;
465 goto bad;
466 }
467 bp->b_bcount = sz << DEV_BSHIFT;
468 }
469 bp->b_cylin = (bp->b_blkno + lp->d_partitions[xunit].p_offset) /
470 lp->d_secpercyl;
471 q:
472 s = spl5();
473 disksort(&mi->mi_tab, bp);
474 if (mi->mi_tab.b_active == 0)
475 mbustart(mi);
476 splx(s);
477 return;
478
479 bad:
480 bp->b_flags |= B_ERROR;
481 done:
482 biodone(bp);
483 return;
484 }
485
hpustart(mi)486 hpustart(mi)
487 register struct mba_device *mi;
488 {
489 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
490 register struct buf *bp = mi->mi_tab.b_actf;
491 register struct disklabel *lp;
492 struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
493 daddr_t bn;
494 int sn, tn, dist;
495
496 lp = &hplabel[mi->mi_unit];
497 hpaddr->hpcs1 = 0;
498 if ((hpaddr->hpcs1&HP_DVA) == 0)
499 return (MBU_BUSY);
500
501 switch (sc->sc_recal) {
502
503 case 1:
504 (void)HPWAIT(mi, hpaddr);
505 hpaddr->hpdc = bp->b_cylin;
506 hpaddr->hpcs1 = HP_SEEK|HP_GO;
507 sc->sc_recal++;
508 return (MBU_STARTED);
509 case 2:
510 break;
511 }
512 sc->sc_recal = 0;
513 if ((hpaddr->hpds & HPDS_VV) == 0) {
514 if (sc->sc_state == OPEN && lp->d_flags & D_REMOVABLE) {
515 if (sc->sc_openpart)
516 log(LOG_ERR, "hp%d: volume changed\n",
517 mi->mi_unit);
518 sc->sc_openpart = 0;
519 bp->b_flags |= B_ERROR;
520 return (MBU_NEXT);
521 }
522 hpaddr->hpcs1 = HP_DCLR|HP_GO;
523 if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
524 printf("DCLR attn\n");
525 hpaddr->hpcs1 = HP_PRESET|HP_GO;
526 if (!ML11(mi->mi_type))
527 hpaddr->hpof = HPOF_FMT22;
528 mbclrattn(mi);
529 if (sc->sc_state == WANTOPENRAW) {
530 sc->sc_state = OPENRAW;
531 return (MBU_NEXT);
532 }
533 if (sc->sc_state == WANTOPEN)
534 sc->sc_state = RDLABEL;
535 }
536 if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) {
537 if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) {
538 hpaddr->hpof =
539 hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
540 hpaddr->hpcs1 = HP_OFFSET|HP_GO;
541 (void)HPWAIT(mi, hpaddr);
542 mbclrattn(mi);
543 }
544 return (MBU_DODATA);
545 }
546 if (ML11(mi->mi_type))
547 return (MBU_DODATA);
548 if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
549 return (MBU_DODATA);
550 bn = bp->b_blkno;
551 sn = bn % lp->d_secpercyl;
552 tn = sn / lp->d_nsectors;
553 sn = sn % lp->d_nsectors;
554 if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
555 if (sc->sc_doseeks)
556 return (MBU_DODATA);
557 dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1;
558 if (dist < 0)
559 dist += lp->d_nsectors;
560 if (dist <= lp->d_maxdist && dist >= lp->d_mindist)
561 return (MBU_DODATA);
562 } else
563 hpaddr->hpdc = bp->b_cylin;
564 if (sc->sc_doseeks)
565 hpaddr->hpcs1 = HP_SEEK|HP_GO;
566 else {
567 sn = (sn + lp->d_nsectors - lp->d_sdist) % lp->d_nsectors;
568 hpaddr->hpda = (tn << 8) + sn;
569 hpaddr->hpcs1 = HP_SEARCH|HP_GO;
570 }
571 return (MBU_STARTED);
572 }
573
hpstart(mi)574 hpstart(mi)
575 register struct mba_device *mi;
576 {
577 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
578 register struct buf *bp = mi->mi_tab.b_actf;
579 register struct disklabel *lp = &hplabel[mi->mi_unit];
580 struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
581 daddr_t bn;
582 int sn, tn, cn;
583
584 if (ML11(mi->mi_type))
585 hpaddr->hpda = bp->b_blkno + sc->sc_blkdone;
586 else {
587 if (bp->b_flags & B_BAD) {
588 bn = sc->sc_badbn;
589 cn = bn / lp->d_secpercyl;
590 } else {
591 bn = bp->b_blkno;
592 cn = bp->b_cylin;
593 }
594 sn = bn % lp->d_secpercyl;
595 if ((bp->b_flags & B_BAD) == 0)
596 sn += sc->sc_blkdone;
597 tn = sn / lp->d_nsectors;
598 sn %= lp->d_nsectors;
599 cn += tn / lp->d_ntracks;
600 tn %= lp->d_ntracks;
601 hpaddr->hpda = (tn << 8) + sn;
602 hpaddr->hpdc = cn;
603 }
604 mi->mi_tab.b_bdone = dbtob(sc->sc_blkdone);
605 if (bp->b_flags & B_FORMAT) {
606 if (bp->b_flags & B_READ)
607 return (HP_RHDR|HP_GO);
608 else
609 return (HP_WHDR|HP_GO);
610 }
611 return (0);
612 }
613
hpdtint(mi,mbsr)614 hpdtint(mi, mbsr)
615 register struct mba_device *mi;
616 int mbsr;
617 {
618 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
619 register struct buf *bp = mi->mi_tab.b_actf;
620 register int er1, er2;
621 struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
622 int retry = 0;
623 int npf, bcr;
624
625 bcr = MASKREG(-mi->mi_mba->mba_bcr);
626 if (bp->b_flags & B_FORMAT) {
627 sc->sc_status = mbsr;
628 sc->sc_hpds = hpaddr->hpds;
629 sc->sc_er1 = hpaddr->hper1;
630 sc->sc_er2 = hpaddr->hper2;
631 }
632 if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
633 er1 = hpaddr->hper1;
634 er2 = hpaddr->hper2;
635 if (bp->b_flags & B_BAD)
636 npf = bp->b_error;
637 else {
638 npf = btodb(bp->b_bcount + (DEV_BSIZE - 1) - bcr);
639 if (er1 & (HPER1_DCK | HPER1_ECH))
640 npf--;
641 }
642 if (HPWAIT(mi, hpaddr) == 0)
643 goto hard;
644 #ifdef HPDEBUG
645 if (hpdebug) {
646 int dc = hpaddr->hpdc, da = hpaddr->hpda;
647 daddr_t bn;
648
649 if (bp->b_flags & B_BAD)
650 bn = sc->sc_badbn;
651 else
652 bn = bp->b_blkno + npf;
653 log(LOG_DEBUG,
654 "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n",
655 bp, bp->b_cylin, bn, sc->sc_blkdone,
656 hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da));
657 log(LOG_DEBUG,
658 "errcnt %d mbsr=%b er1=%b er2=%b bcr -%d\n",
659 mi->mi_tab.b_errcnt, mbsr, mbsr_bits,
660 MASKREG(er1), HPER1_BITS,
661 MASKREG(er2), HPER2_BITS, bcr);
662 }
663 #endif
664 if (er1 & HPER1_HCRC) {
665 er1 &= ~(HPER1_HCE|HPER1_FER);
666 er2 &= ~HPER2_BSE;
667 }
668 if (er1 & HPER1_WLE) {
669 log(LOG_WARNING, "hp%d: write locked\n",
670 hpunit(bp->b_dev));
671 bp->b_flags |= B_ERROR;
672 } else if (bp->b_flags & B_FORMAT) {
673 bp->b_flags |= B_ERROR;
674 } else if (RM80(mi->mi_type) && er2&HPER2_SSE) {
675 (void) hpecc(mi, SSE);
676 return (MBD_RESTARTED);
677 } else if ((er2 & HPER2_BSE) && !ML11(mi->mi_type)) {
678 if (hpecc(mi, BSE))
679 return (MBD_RESTARTED);
680 goto hard;
681 } else if (MASKREG(er1) == HPER1_FER && RP06(mi->mi_type)) {
682 if (hpecc(mi, BSE))
683 return (MBD_RESTARTED);
684 goto hard;
685 } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK &&
686 mi->mi_tab.b_errcnt >= 3) {
687 if (hpecc(mi, ECC))
688 return (MBD_RESTARTED);
689 /*
690 * ECC corrected. Only log retries below
691 * if we got errors other than soft ECC
692 * (as indicated by additional retries).
693 */
694 if (mi->mi_tab.b_errcnt == 3)
695 mi->mi_tab.b_errcnt = 0;
696 } else if ((er1 & HPER1_HCRC) && !ML11(mi->mi_type) &&
697 hpecc(mi, BSE)) {
698 /*
699 * HCRC means the header is screwed up and the sector
700 * might well exist in the bad sector table,
701 * better check....
702 */
703 return (MBD_RESTARTED);
704 } else if (++mi->mi_tab.b_errcnt > 27 ||
705 (ML11(mi->mi_type) && mi->mi_tab.b_errcnt > 15) ||
706 mbsr & MBSR_HARD ||
707 er1 & HPER1_HARD ||
708 (!ML11(mi->mi_type) && (er2 & HPER2_HARD))) {
709 hard:
710 diskerr(bp, "hp", "hard error", LOG_PRINTF, npf,
711 &hplabel[mi->mi_unit]);
712 if (bp->b_flags & B_BAD)
713 printf(" (on replacement sector %d)",
714 sc->sc_badbn);
715 if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
716 printf(" mbsr=%b", mbsr, mbsr_bits);
717 printf(" er1=%b er2=%b ds=%b\n",
718 MASKREG(hpaddr->hper1), HPER1_BITS,
719 MASKREG(hpaddr->hper2), HPER2_BITS,
720 MASKREG(hpaddr->hpds), HPDS_BITS);
721 bp->b_flags |= B_ERROR;
722 bp->b_flags &= ~B_BAD;
723 } else
724 retry = 1;
725 hpaddr->hpcs1 = HP_DCLR|HP_GO;
726 if (retry && (mi->mi_tab.b_errcnt & 07) == 4) {
727 hpaddr->hpcs1 = HP_RECAL|HP_GO;
728 sc->sc_recal = 1;
729 return (MBD_REPOSITION);
730 }
731 }
732 #ifdef HPDEBUG
733 else
734 if (hpdebug && sc->sc_recal) {
735 log(LOG_DEBUG,
736 "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n",
737 sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits,
738 hpaddr->hper1, HPER1_BITS,
739 hpaddr->hper2, HPER2_BITS);
740 }
741 #endif
742 (void)HPWAIT(mi, hpaddr);
743 if (retry)
744 return (MBD_RETRY);
745 if (mi->mi_tab.b_errcnt >= 16) {
746 /*
747 * This is fast and occurs rarely; we don't
748 * bother with interrupts.
749 */
750 hpaddr->hpcs1 = HP_RTC|HP_GO;
751 (void)HPWAIT(mi, hpaddr);
752 mbclrattn(mi);
753 }
754 if (mi->mi_tab.b_errcnt && (bp->b_flags & B_ERROR) == 0) {
755 diskerr(bp, "hp", "retries", LOG_INFO, sc->sc_blkdone,
756 &hplabel[mi->mi_unit]);
757 addlog(": %d retries\n", mi->mi_tab.b_errcnt);
758 }
759 if ((bp->b_flags & B_BAD) && hpecc(mi, CONT))
760 return (MBD_RESTARTED);
761 sc->sc_blkdone = 0;
762 bp->b_resid = bcr;
763 if (!ML11(mi->mi_type)) {
764 hpaddr->hpof = HPOF_FMT22;
765 hpaddr->hpcs1 = HP_RELEASE|HP_GO;
766 }
767 if (sc->sc_openpart == 0)
768 wakeup((caddr_t)sc);
769 return (MBD_DONE);
770 }
771
772 /*
773 * Wait (for a bit) for a drive to come ready;
774 * returns nonzero on success.
775 */
hpwait(mi)776 hpwait(mi)
777 register struct mba_device *mi;
778 {
779 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
780 register i = 100000;
781
782 while ((hpaddr->hpds & HPDS_DRY) == 0 && --i)
783 DELAY(10);
784 if (i == 0)
785 printf("hp%d: intr, not ready\n", mi->mi_unit);
786 return (i);
787 }
788
hpioctl(dev,cmd,data,flag)789 hpioctl(dev, cmd, data, flag)
790 dev_t dev;
791 int cmd;
792 caddr_t data;
793 int flag;
794 {
795 int unit = hpunit(dev);
796 register struct disklabel *lp;
797 register struct hpsoftc *sc = &hpsoftc[unit];
798 int error = 0;
799 int hpformat();
800
801 lp = &hplabel[unit];
802
803 switch (cmd) {
804
805 case DIOCGDINFO:
806 *(struct disklabel *)data = *lp;
807 break;
808
809 case DIOCGPART:
810 ((struct partinfo *)data)->disklab = lp;
811 ((struct partinfo *)data)->part =
812 &lp->d_partitions[hppart(dev)];
813 break;
814
815 case DIOCSDINFO:
816 if ((flag & FWRITE) == 0)
817 error = EBADF;
818 else
819 error = setdisklabel(lp, (struct disklabel *)data,
820 (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart);
821 if (error == 0)
822 sc->sc_state = OPEN;
823 break;
824
825 case DIOCWLABEL:
826 if ((flag & FWRITE) == 0)
827 error = EBADF;
828 else
829 sc->sc_wlabel = *(int *)data;
830 break;
831
832 case DIOCWDINFO:
833 if ((flag & FWRITE) == 0)
834 error = EBADF;
835 else if ((error = setdisklabel(lp, (struct disklabel *)data,
836 (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart)) == 0) {
837 int wlab;
838
839 sc->sc_state = OPEN;
840 /* simulate opening partition 0 so write succeeds */
841 sc->sc_openpart |= (1 << 0); /* XXX */
842 wlab = sc->sc_wlabel;
843 sc->sc_wlabel = 1;
844 error = writedisklabel(dev, hpstrategy, lp);
845 sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart;
846 sc->sc_wlabel = wlab;
847 }
848 break;
849
850 case DIOCSBAD:
851 {
852 struct dkbad *db = (struct dkbad *)data;
853
854 if ((flag & FWRITE) == 0)
855 error = EBADF;
856 else if (db->bt_mbz != 0 || db->bt_flag != 0)
857 error = EINVAL;
858 else
859 hpbad[unit] = *db;
860 break;
861 }
862
863 case DIOCRFORMAT:
864 case DIOCWFORMAT:
865 {
866 register struct format_op *fop;
867 struct uio auio;
868 struct iovec aiov;
869
870 if (cmd == DIOCWFORMAT && (flag & FWRITE) == 0) {
871 error = EBADF;
872 break;
873 }
874 fop = (struct format_op *)data;
875 aiov.iov_base = fop->df_buf;
876 aiov.iov_len = fop->df_count;
877 auio.uio_iov = &aiov;
878 auio.uio_iovcnt = 1;
879 auio.uio_resid = fop->df_count;
880 auio.uio_segflg = UIO_USERSPACE;
881 auio.uio_offset = fop->df_startblk * lp->d_secsize;
882 /*
883 * Don't return errors, as the format op won't get copied
884 * out if we return nonzero. Callers must check the returned
885 * count.
886 */
887 (void) physio(hpformat, (struct buf *)NULL, dev,
888 (cmd == DIOCWFORMAT ? B_WRITE : B_READ), minphys, &auio);
889 fop->df_count -= auio.uio_resid;
890 fop->df_reg[0] = sc->sc_status;
891 fop->df_reg[1] = sc->sc_hpds;
892 fop->df_reg[2] = sc->sc_er1;
893 fop->df_reg[3] = sc->sc_er2;
894 break;
895 }
896
897 default:
898 error = ENOTTY;
899 break;
900 }
901 return (error);
902 }
903
904 hpformat(bp)
905 struct buf *bp;
906 {
907 bp->b_flags |= B_FORMAT;
908 hpstrategy(bp);
909 }
910
hpecc(mi,flag)911 hpecc(mi, flag)
912 register struct mba_device *mi;
913 int flag;
914 {
915 register struct mba_regs *mbp = mi->mi_mba;
916 register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
917 register struct buf *bp = mi->mi_tab.b_actf;
918 register struct disklabel *lp = &hplabel[mi->mi_unit];
919 struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
920 int npf, o;
921 int bn, cn, tn, sn;
922 int bcr;
923
924 bcr = MASKREG(-mbp->mba_bcr);
925 if (bp->b_flags & B_BAD)
926 npf = bp->b_error;
927 else {
928 npf = bp->b_bcount - bcr;
929 /*
930 * Watch out for fractional sector at end of transfer;
931 * want to round up if finished, otherwise round down.
932 */
933 if (bcr == 0)
934 npf += 511;
935 npf = btodb(npf);
936 }
937 o = (int)bp->b_un.b_addr & PGOFSET;
938 bn = bp->b_blkno;
939 cn = bp->b_cylin;
940 sn = bn % lp->d_secpercyl + npf;
941 tn = sn / lp->d_nsectors;
942 sn %= lp->d_nsectors;
943 cn += tn / lp->d_ntracks;
944 tn %= lp->d_ntracks;
945 bn += npf;
946 switch (flag) {
947 case ECC: {
948 register int i;
949 caddr_t addr;
950 struct pte mpte;
951 int bit, byte, mask;
952
953 npf--; /* because block in error is previous block */
954 diskerr(bp, "hp", "soft ecc", LOG_WARNING, npf, lp);
955 if (bp->b_flags & B_BAD)
956 addlog(" (on replacement sector %d)", sc->sc_badbn);
957 addlog("\n");
958 mask = MASKREG(rp->hpec2);
959 i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */
960 bit = i&07;
961 i = (i&~07)>>3;
962 byte = i + o;
963 while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) {
964 mpte = mbp->mba_map[npf+btop(byte)];
965 addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
966 putmemc(addr, getmemc(addr)^(mask<<bit));
967 byte++;
968 i++;
969 bit -= 8;
970 }
971 if (bcr == 0)
972 return (0);
973 npf++;
974 break;
975 }
976
977 case SSE:
978 rp->hpof |= HPOF_SSEI;
979 if (bp->b_flags & B_BAD) {
980 bn = sc->sc_badbn;
981 goto fixregs;
982 }
983 mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
984 break;
985
986 case BSE:
987 if (sc->sc_state == OPENRAW)
988 return (0);
989 if (rp->hpof & HPOF_SSEI)
990 sn++;
991 #ifdef HPBDEBUG
992 if (hpbdebug)
993 log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
994 #endif
995 if (bp->b_flags & B_BAD)
996 return (0);
997 if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
998 return (0);
999 bp->b_flags |= B_BAD;
1000 bp->b_error = npf + 1;
1001 rp->hpof &= ~HPOF_SSEI;
1002 bn = lp->d_ncylinders * lp->d_secpercyl -
1003 lp->d_nsectors - 1 - bn;
1004 sc->sc_badbn = bn;
1005 fixregs:
1006 cn = bn / lp->d_secpercyl;
1007 sn = bn % lp->d_secpercyl;
1008 tn = sn / lp->d_nsectors;
1009 sn %= lp->d_nsectors;
1010 bcr = bp->b_bcount - (int)ptob(npf);
1011 bcr = MIN(bcr, 512);
1012 mbp->mba_bcr = -bcr;
1013 #ifdef HPBDEBUG
1014 if (hpbdebug)
1015 log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn);
1016 #endif
1017 break;
1018
1019 case CONT:
1020 #ifdef HPBDEBUG
1021 if (hpbdebug)
1022 log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
1023 #endif
1024 bp->b_flags &= ~B_BAD;
1025 if ((int)ptob(npf) >= bp->b_bcount)
1026 return (0);
1027 mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
1028 break;
1029 }
1030 rp->hpcs1 = HP_DCLR|HP_GO;
1031 if (rp->hpof & HPOF_SSEI)
1032 sn++;
1033 rp->hpdc = cn;
1034 rp->hpda = (tn<<8) + sn;
1035 mbp->mba_sr = -1;
1036 mbp->mba_var = (int)ptob(npf) + o;
1037 rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
1038 mi->mi_tab.b_errcnt = 0; /* error has been corrected */
1039 sc->sc_blkdone = npf;
1040 return (1);
1041 }
1042
1043 #define DBSIZE 20
1044
hpdump(dev)1045 hpdump(dev)
1046 dev_t dev;
1047 {
1048 register struct mba_device *mi;
1049 register struct mba_regs *mba;
1050 register struct disklabel *lp;
1051 struct hpdevice *hpaddr;
1052 char *start;
1053 int num, unit;
1054 extern int dumpsize;
1055
1056 num = dumpsize;
1057 start = 0;
1058 unit = hpunit(dev);
1059 if (unit >= NHP)
1060 return (ENXIO);
1061 #define phys(a,b) ((b)((int)(a)&0x7fffffff))
1062 mi = phys(hpinfo[unit],struct mba_device *);
1063 if (mi == 0 || mi->mi_alive == 0)
1064 return (ENXIO);
1065 lp = &hplabel[unit];
1066 mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
1067 mba->mba_cr = MBCR_INIT;
1068 hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
1069 if ((hpaddr->hpds & HPDS_VV) == 0) {
1070 hpaddr->hpcs1 = HP_DCLR|HP_GO;
1071 hpaddr->hpcs1 = HP_PRESET|HP_GO;
1072 hpaddr->hpof = HPOF_FMT22;
1073 }
1074 if (dumplo + num >= lp->d_partitions[hppart(dev)].p_size)
1075 num = lp->d_partitions[hppart(dev)].p_size - dumplo;
1076 while (num > 0) {
1077 register struct pte *hpte = mba->mba_map;
1078 register int i;
1079 int blk, cn, sn, tn;
1080 daddr_t bn;
1081
1082 blk = num > DBSIZE ? DBSIZE : num;
1083 bn = dumplo + btodb(start);
1084 cn = (bn + lp->d_partitions[hppart(dev)].p_offset) /
1085 lp->d_secpercyl;
1086 sn = bn % lp->d_secpercyl;
1087 tn = sn / lp->d_nsectors;
1088 sn = sn % lp->d_nsectors;
1089 hpaddr->hpdc = cn;
1090 hpaddr->hpda = (tn << 8) + sn;
1091 for (i = 0; i < blk; i++)
1092 *(int *)hpte++ = (btop(start)+i) | PG_V;
1093 mba->mba_sr = -1;
1094 mba->mba_bcr = -(blk*NBPG);
1095 mba->mba_var = 0;
1096 hpaddr->hpcs1 = HP_WCOM | HP_GO;
1097 while ((hpaddr->hpds & HPDS_DRY) == 0)
1098 DELAY(10);
1099 if (hpaddr->hpds&HPDS_ERR)
1100 return (EIO);
1101 start += blk*NBPG;
1102 num -= blk;
1103 }
1104 return (0);
1105 }
1106
hpsize(dev)1107 hpsize(dev)
1108 dev_t dev;
1109 {
1110 register int unit = hpunit(dev);
1111 struct mba_device *mi;
1112
1113 if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0 ||
1114 hpsoftc[unit].sc_state != OPEN)
1115 return (-1);
1116 return ((int)hplabel[unit].d_partitions[hppart(dev)].p_size);
1117 }
1118
1119 #ifdef COMPAT_42
1120 /*
1121 * Compatibility code to fake up pack label
1122 * for unlabeled disks.
1123 */
1124 struct size {
1125 daddr_t nblocks;
1126 int cyloff;
1127 } rp06_sizes[8] = {
1128 15884, 0, /* A=cyl 0 thru 37 */
1129 33440, 38, /* B=cyl 38 thru 117 */
1130 340670, 0, /* C=cyl 0 thru 814 */
1131 15884, 118, /* D=cyl 118 thru 155 */
1132 55936, 156, /* E=cyl 156 thru 289 */
1133 219384, 290, /* F=cyl 290 thru 814 */
1134 291192, 118, /* G=cyl 118 thru 814 */
1135 0, 0,
1136 }, rp05_sizes[8] = {
1137 15884, 0, /* A=cyl 0 thru 37 */
1138 33440, 38, /* B=cyl 38 thru 117 */
1139 171798, 0, /* C=cyl 0 thru 410 */
1140 15884, 118, /* D=cyl 118 thru 155 */
1141 55936, 156, /* E=cyl 156 thru 289 */
1142 50512, 290, /* F=cyl 290 thru 410 */
1143 122408, 118, /* G=cyl 118 thru 410 */
1144 0, 0,
1145 }, rm03_sizes[8] = {
1146 15884, 0, /* A=cyl 0 thru 99 */
1147 33440, 100, /* B=cyl 100 thru 308 */
1148 131680, 0, /* C=cyl 0 thru 822 */
1149 15884, 309, /* D=cyl 309 thru 408 */
1150 55936, 409, /* E=cyl 409 thru 758 */
1151 10144, 759, /* F=cyl 759 thru 822 */
1152 82144, 309, /* G=cyl 309 thru 822 */
1153 0, 0,
1154 }, rm05_sizes[8] = {
1155 15884, 0, /* A=cyl 0 thru 26 */
1156 33440, 27, /* B=cyl 27 thru 81 */
1157 500384, 0, /* C=cyl 0 thru 822 */
1158 15884, 562, /* D=cyl 562 thru 588 */
1159 55936, 589, /* E=cyl 589 thru 680 */
1160 86240, 681, /* F=cyl 681 thru 822 */
1161 158592, 562, /* G=cyl 562 thru 822 */
1162 291346, 82, /* H=cyl 82 thru 561 */
1163 }, rm80_sizes[8] = {
1164 15884, 0, /* A=cyl 0 thru 36 */
1165 33440, 37, /* B=cyl 37 thru 114 */
1166 242606, 0, /* C=cyl 0 thru 558 */
1167 15884, 115, /* D=cyl 115 thru 151 */
1168 55936, 152, /* E=cyl 152 thru 280 */
1169 120559, 281, /* F=cyl 281 thru 558 */
1170 192603, 115, /* G=cyl 115 thru 558 */
1171 0, 0,
1172 }, rp07_sizes[8] = {
1173 15884, 0, /* A=cyl 0 thru 9 */
1174 66880, 10, /* B=cyl 10 thru 51 */
1175 1008000, 0, /* C=cyl 0 thru 629 */
1176 15884, 235, /* D=cyl 235 thru 244 */
1177 307200, 245, /* E=cyl 245 thru 436 */
1178 308650, 437, /* F=cyl 437 thru 629 */
1179 631850, 235, /* G=cyl 235 thru 629 */
1180 291346, 52, /* H=cyl 52 thru 234 */
1181 }, cdc9775_sizes[8] = {
1182 15884, 0, /* A=cyl 0 thru 12 */
1183 66880, 13, /* B=cyl 13 thru 65 */
1184 1077760, 0, /* C=cyl 0 thru 841 */
1185 15884, 294, /* D=cyl 294 thru 306 */
1186 307200, 307, /* E=cyl 307 thru 546 */
1187 377440, 547, /* F=cyl 547 thru 841 */
1188 701280, 294, /* G=cyl 294 thru 841 */
1189 291346, 66, /* H=cyl 66 thru 293 */
1190 }, cdc9730_sizes[8] = {
1191 15884, 0, /* A=cyl 0 thru 49 */
1192 33440, 50, /* B=cyl 50 thru 154 */
1193 263360, 0, /* C=cyl 0 thru 822 */
1194 15884, 155, /* D=cyl 155 thru 204 */
1195 55936, 205, /* E=cyl 205 thru 379 */
1196 141664, 380, /* F=cyl 380 thru 822 */
1197 213664, 155, /* G=cyl 155 thru 822 */
1198 0, 0,
1199 }, capricorn_sizes[8] = {
1200 15884, 0, /* A=cyl 0 thru 31 */
1201 33440, 32, /* B=cyl 32 thru 97 */
1202 524288, 0, /* C=cyl 0 thru 1023 */
1203 15884, 668, /* D=cyl 668 thru 699 */
1204 55936, 700, /* E=cyl 700 thru 809 */
1205 109472, 810, /* F=cyl 810 thru 1023 */
1206 182176, 668, /* G=cyl 668 thru 1023 */
1207 291346, 98, /* H=cyl 98 thru 667 */
1208 }, eagle_sizes[8] = {
1209 15884, 0, /* A=cyl 0 thru 16 */
1210 66880, 17, /* B=cyl 17 thru 86 */
1211 808320, 0, /* C=cyl 0 thru 841 */
1212 15884, 391, /* D=cyl 391 thru 407 */
1213 307200, 408, /* E=cyl 408 thru 727 */
1214 109296, 728, /* F=cyl 728 thru 841 */
1215 432816, 391, /* G=cyl 391 thru 841 */
1216 291346, 87, /* H=cyl 87 thru 390 */
1217 }, ampex_sizes[8] = {
1218 15884, 0, /* A=cyl 0 thru 26 */
1219 33440, 27, /* B=cyl 27 thru 81 */
1220 495520, 0, /* C=cyl 0 thru 814 */
1221 15884, 562, /* D=cyl 562 thru 588 */
1222 55936, 589, /* E=cyl 589 thru 680 */
1223 81312, 681, /* F=cyl 681 thru 814 */
1224 153664, 562, /* G=cyl 562 thru 814 */
1225 291346, 82, /* H=cyl 82 thru 561 */
1226 }, fj2361_sizes[8] = {
1227 15884, 0, /* A=cyl 0 thru 12 */
1228 66880, 13, /* B=cyl 13 thru 65 */
1229 1077760, 0, /* C=cyl 0 thru 841 */
1230 15884, 294, /* D=cyl 294 thru 306 */
1231 307200, 307, /* E=cyl 307 thru 546 */
1232 377408, 547, /* F=cyl 547 thru 841 */
1233 701248, 294, /* G=cyl 294 thru 841 */
1234 291346, 66, /* H=cyl 66 thru 293 */
1235 }, fj2361a_sizes[8] = {
1236 15884, 0, /* A=cyl 0 thru 11 */
1237 66880, 12, /* B=cyl 12 thru 61 */
1238 1145120, 0, /* C=cyl 0 thru 841 */
1239 15884, 277, /* D=cyl 277 thru 288 */
1240 307200, 289, /* E=cyl 289 thru 514 */
1241 444516, 515, /* F=cyl 515 thru 841 */
1242 768196, 277, /* G=cyl 277 thru 841 */
1243 291346, 62, /* H=cyl 62 thru 276 */
1244 };
1245
1246 /*
1247 * These variable are all measured in sectors.
1248 * Sdist is how much to "lead" in the search for a desired sector
1249 * (i.e. if want N, search for N-sdist.)
1250 * Maxdist and mindist define the region right before our desired sector within
1251 * which we don't bother searching. We don't search when we are already less
1252 * then maxdist and more than mindist sectors "before" our desired sector.
1253 * Maxdist should be >= sdist.
1254 *
1255 * Beware, sdist, mindist and maxdist are not well tuned
1256 * for many of the drives listed in this table.
1257 * Try patching things with something i/o intensive
1258 * running and watch iostat.
1259 *
1260 * The order of these entries must agree with the indices in hptypes[].
1261 */
1262 struct hpst {
1263 short nsect; /* # sectors/track */
1264 short ntrak; /* # tracks/cylinder */
1265 short nspc; /* # sector/cylinders */
1266 short ncyl; /* # cylinders */
1267 struct size *sizes; /* partition tables */
1268 short sdist; /* seek distance metric */
1269 short maxdist; /* boundaries of non-searched area */
1270 short mindist; /* preceding the target sector */
1271 char *name; /* name of disk type */
1272 } hpst[] = {
1273 { 32, 5, 32*5, 823, rm03_sizes, 7, 4, 1, "RM03" },
1274 { 32, 19, 32*19, 823, rm05_sizes, 7, 4, 1, "RM05" },
1275 { 22,19, 22*19, 815, rp06_sizes, 7, 4, 1, "RP06"},
1276 { 31, 14, 31*14, 559, rm80_sizes, 7, 4, 1, "RM80"},
1277 { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP04"},
1278 { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP05"},
1279 { 50, 32, 50*32, 630, rp07_sizes, 15, 8, 3, "RP07"},
1280 { 1, 1, 1, 1, 0, 0, 0, 0, "ML11A"},
1281 { 1, 1, 1, 1, 0, 0, 0, 0, "ML11B" },
1282 { 32, 40, 32*40, 843, cdc9775_sizes, 7, 4, 1, "9775" },
1283 { 32, 10, 32*10, 823, cdc9730_sizes, 7, 4, 1, "9730-160" },
1284 { 32, 16, 32*16, 1024, capricorn_sizes,10,4, 3, "capricorn" },
1285 { 48, 20, 48*20, 842, eagle_sizes, 15, 8, 3, "eagle" },
1286 { 32, 19, 32*19, 815, ampex_sizes, 7, 4, 1, "9300" },
1287 { 64, 20, 64*20, 842, fj2361_sizes, 15, 8, 3, "2361" },
1288 { 68, 20, 68*20, 842, fj2361a_sizes, 15, 8, 3, "2361a" },
1289 };
1290
1291 /*
1292 * Map apparent MASSBUS drive type into manufacturer
1293 * specific configuration. For SI controllers this is done
1294 * based on codes in the serial number register. For
1295 * EMULEX controllers, the track and sector attributes are
1296 * used when the drive type is an RM02 (not supported by DEC).
1297 */
hpmaptype(mi,lp)1298 hpmaptype(mi, lp)
1299 register struct mba_device *mi;
1300 register struct disklabel *lp;
1301 {
1302 register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
1303 register int type = mi->mi_type;
1304 register struct hpst *st;
1305 register i;
1306
1307 /*
1308 * Model-byte processing for SI controllers.
1309 * NB: Only deals with RM03 and RM05 emulations.
1310 */
1311 if (type == HPDT_RM03 || type == HPDT_RM05) {
1312 int hpsn = hpaddr->hpsn;
1313
1314 if ((hpsn & SIMB_LU) == mi->mi_drive)
1315 switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
1316
1317 case SI9775D:
1318 type = HPDT_9775;
1319 break;
1320
1321 case SI9730D:
1322 type = HPDT_9730;
1323 break;
1324
1325 case SI9766:
1326 type = HPDT_RM05;
1327 break;
1328
1329 case SI9762:
1330 type = HPDT_RM03;
1331 break;
1332
1333 case SICAPD:
1334 type = HPDT_CAPRICORN;
1335 break;
1336
1337 case SI9751D:
1338 type = HPDT_EAGLE;
1339 break;
1340 }
1341 mi->mi_type = type;
1342 }
1343
1344 /*
1345 * EMULEX SC750 or SC780. Poke the holding register.
1346 */
1347 if (type == HPDT_RM02) {
1348 int nsectors, ntracks, ncyl;
1349
1350 hpaddr->hpof = HPOF_FMT22;
1351 mbclrattn(mi);
1352 hpaddr->hpcs1 = HP_NOP;
1353 hpaddr->hphr = HPHR_MAXTRAK;
1354 ntracks = MASKREG(hpaddr->hphr) + 1;
1355 DELAY(100);
1356 hpaddr->hpcs1 = HP_NOP;
1357 hpaddr->hphr = HPHR_MAXSECT;
1358 nsectors = MASKREG(hpaddr->hphr) + 1;
1359 DELAY(100);
1360 hpaddr->hpcs1 = HP_NOP;
1361 hpaddr->hphr = HPHR_MAXCYL;
1362 ncyl = MASKREG(hpaddr->hphr) + 1;
1363 for (type = 0; hptypes[type] != 0; type++)
1364 if (hpst[type].nsect == nsectors &&
1365 hpst[type].ntrak == ntracks &&
1366 hpst[type].ncyl == ncyl)
1367 break;
1368
1369 hpaddr->hpcs1 = HP_DCLR|HP_GO;
1370 mbclrattn(mi); /* conservative */
1371 if (hptypes[type] == 0) {
1372 printf("hp%d: %d sectors, %d tracks, %d cylinders: unknown device\n",
1373 mi->mi_unit, nsectors, ntracks, ncyl);
1374 lp->d_nsectors = nsectors;
1375 lp->d_ntracks = ntracks;
1376 lp->d_ncylinders = ncyl;
1377 lp->d_secpercyl = nsectors*ntracks;
1378 lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
1379 #ifdef notdef /* set elsewhere */
1380 lp->d_npartitions = 1;
1381 lp->d_partitions[0].p_offset = 0;
1382 #endif
1383 lp->d_partitions[0].p_size = lp->d_secperunit;
1384 return (0);
1385 }
1386 mi->mi_type = type;
1387 }
1388
1389 /*
1390 * set up minimal disk label.
1391 */
1392 st = &hpst[type];
1393 lp->d_nsectors = st->nsect;
1394 lp->d_ntracks = st->ntrak;
1395 lp->d_secpercyl = st->nspc;
1396 lp->d_ncylinders = st->ncyl;
1397 lp->d_secperunit = st->nspc * st->ncyl;
1398 lp->d_sdist = st->sdist;
1399 lp->d_mindist = st->mindist;
1400 lp->d_maxdist = st->maxdist;
1401 bcopy(hpst[type].name, lp->d_typename, sizeof(lp->d_typename));
1402 lp->d_npartitions = 8;
1403 for (i = 0; i < 8; i++) {
1404 lp->d_partitions[i].p_offset = st->sizes[i].cyloff *
1405 lp->d_secpercyl;
1406 lp->d_partitions[i].p_size = st->sizes[i].nblocks;
1407 }
1408 return (1);
1409 }
1410 #endif COMPAT_42
1411 #endif
1412