1*889e8222Sbostic /*-
2*889e8222Sbostic * Copyright (c) 1982, 1986 The Regents of the University of California.
3*889e8222Sbostic * All rights reserved.
4c5a607b2Smckusick *
5*889e8222Sbostic * %sccs.include.proprietary.c%
6*889e8222Sbostic *
7*889e8222Sbostic * @(#)hp.c 7.23 (Berkeley) 05/08/91
8c5a607b2Smckusick */
93b895dd6Sroot
103b895dd6Sroot #ifdef HPDEBUG
114d79458fSwnj int hpdebug;
123b895dd6Sroot #endif
133b895dd6Sroot #ifdef HPBDEBUG
143b895dd6Sroot int hpbdebug;
153b895dd6Sroot #endif
16f87ddd94Sbill
1716a40936Swnj #include "hp.h"
187d993dedSbill #if NHP > 0
19f87ddd94Sbill /*
207fe1b41dSroot * HP disk driver for RP0x+RMxx+ML11
21c1c761cfSwnj *
22c1c761cfSwnj * TODO:
233b895dd6Sroot * see if DCLR and/or RELEASE set attention status
24f87ddd94Sbill */
25dd262573Sbostic #include "sys/param.h"
26dd262573Sbostic #include "sys/systm.h"
27dd262573Sbostic #include "sys/dkstat.h"
28dd262573Sbostic #include "sys/buf.h"
29dd262573Sbostic #include "sys/conf.h"
30dd262573Sbostic #include "sys/file.h"
31dd262573Sbostic #include "sys/user.h"
32dd262573Sbostic #include "sys/map.h"
33dd262573Sbostic #include "../include/mtpr.h"
34dd262573Sbostic #include "sys/vm.h"
35dd262573Sbostic #include "sys/cmap.h"
36dd262573Sbostic #include "sys/dkbad.h"
37dd262573Sbostic #include "sys/disklabel.h"
38dd262573Sbostic #include "sys/ioctl.h"
39dd262573Sbostic #include "sys/syslog.h"
40dd262573Sbostic #include "sys/stat.h"
41f87ddd94Sbill
42dd262573Sbostic #include "../include/pte.h"
43bdf916b6Sbloom #include "mbareg.h"
44bdf916b6Sbloom #include "mbavar.h"
45bdf916b6Sbloom #include "hpreg.h"
46f87ddd94Sbill
471a9c5c6aSkarels #define COMPAT_42
481a9c5c6aSkarels #define B_FORMAT B_XXX
491a9c5c6aSkarels
501a9c5c6aSkarels /*
511a9c5c6aSkarels * Table of supported Massbus drive types.
521a9c5c6aSkarels * When using unlabeled packs, slot numbers here
531a9c5c6aSkarels * are used as indices into the partition tables.
541a9c5c6aSkarels * Slots are left for those drives divined from other means
551a9c5c6aSkarels * (e.g. SI, AMPEX, etc.).
561a9c5c6aSkarels */
571a9c5c6aSkarels short hptypes[] = {
581a9c5c6aSkarels #define HPDT_RM03 0
591a9c5c6aSkarels MBDT_RM03,
601a9c5c6aSkarels #define HPDT_RM05 1
611a9c5c6aSkarels MBDT_RM05,
621a9c5c6aSkarels #define HPDT_RP06 2
631a9c5c6aSkarels MBDT_RP06,
641a9c5c6aSkarels #define HPDT_RM80 3
651a9c5c6aSkarels MBDT_RM80,
661a9c5c6aSkarels #define HPDT_RP04 4
671a9c5c6aSkarels MBDT_RP04,
681a9c5c6aSkarels #define HPDT_RP05 5
691a9c5c6aSkarels MBDT_RP05,
701a9c5c6aSkarels #define HPDT_RP07 6
711a9c5c6aSkarels MBDT_RP07,
721a9c5c6aSkarels #define HPDT_ML11A 7
731a9c5c6aSkarels MBDT_ML11A,
741a9c5c6aSkarels #define HPDT_ML11B 8
751a9c5c6aSkarels MBDT_ML11B,
761a9c5c6aSkarels #define HPDT_9775 9
771a9c5c6aSkarels -1,
781a9c5c6aSkarels #define HPDT_9730 10
791a9c5c6aSkarels -1,
801a9c5c6aSkarels #define HPDT_CAPRICORN 11
811a9c5c6aSkarels -1,
821a9c5c6aSkarels #define HPDT_EAGLE 12
831a9c5c6aSkarels -1,
841a9c5c6aSkarels #define HPDT_9300 13
851a9c5c6aSkarels -1,
861a9c5c6aSkarels #define HPDT_RM02 14
871a9c5c6aSkarels MBDT_RM02, /* beware, actually mapped */
881a9c5c6aSkarels #define HPDT_2361 15
891a9c5c6aSkarels -1,
902745f7c8Sbostic #define HPDT_2361A 16
912745f7c8Sbostic -1,
921a9c5c6aSkarels 0
931a9c5c6aSkarels };
941a9c5c6aSkarels
951a9c5c6aSkarels struct mba_device *hpinfo[NHP];
96f960dea9Skarels int hpattach(),hpustart(),hpstart(),hpdtint(),hpstrategy();
971a9c5c6aSkarels struct mba_driver hpdriver =
981a9c5c6aSkarels { hpattach, 0, hpustart, hpstart, hpdtint, 0,
991a9c5c6aSkarels hptypes, "hp", 0, hpinfo };
1001a9c5c6aSkarels
1011a9c5c6aSkarels u_char hp_offset[16] = {
1021a9c5c6aSkarels HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400,
1031a9c5c6aSkarels HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800,
1041a9c5c6aSkarels HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200,
1051a9c5c6aSkarels 0, 0, 0, 0,
1061a9c5c6aSkarels };
1071a9c5c6aSkarels
1081a9c5c6aSkarels struct disklabel hplabel[NHP];
1091a9c5c6aSkarels struct dkbad hpbad[NHP];
1101a9c5c6aSkarels
1111a9c5c6aSkarels struct hpsoftc {
1121a9c5c6aSkarels u_char sc_recal; /* recalibrate state */
1131a9c5c6aSkarels u_char sc_doseeks; /* perform explicit seeks */
114fd8888adSkarels #ifdef COMPAT_42
115fd8888adSkarels u_char sc_hdr; /* next i/o includes header */
116fd8888adSkarels #endif
1171a9c5c6aSkarels int sc_state; /* open fsm */
118fd8888adSkarels int sc_wlabel; /* label sector is currently writable */
119c83a6d18Skarels u_long sc_openpart; /* bit mask of open subunits */
120c83a6d18Skarels u_long sc_copenpart; /* bit mask of open character subunits */
121c83a6d18Skarels u_long sc_bopenpart; /* bit mask of open block subunits */
1221a9c5c6aSkarels daddr_t sc_mlsize; /* ML11 size */
1231a9c5c6aSkarels int sc_blkdone; /* amount sucessfully transfered */
1241a9c5c6aSkarels daddr_t sc_badbn; /* replacement block number */
125fd8888adSkarels int sc_status; /* copy of drive status reg. after format */
126fd8888adSkarels int sc_hpds; /* copy of hpds reg. after format */
127fd8888adSkarels int sc_er1; /* copy of error reg. 1 after format */
128fd8888adSkarels int sc_er2; /* copy of error reg. 2 after format */
1291a9c5c6aSkarels } hpsoftc[NHP];
1301a9c5c6aSkarels
1311a9c5c6aSkarels /*
1321a9c5c6aSkarels * Drive states. Used during steps of open/initialization.
1331a9c5c6aSkarels * States < OPEN (> 0) are transient, during an open operation.
1341a9c5c6aSkarels * OPENRAW is used for unlabeled disks,
1351a9c5c6aSkarels * to inhibit bad-sector forwarding or allow format operations.
1361a9c5c6aSkarels */
1371a9c5c6aSkarels #define CLOSED 0 /* disk is closed. */
1381a9c5c6aSkarels #define WANTOPEN 1 /* open requested, not started */
1391a9c5c6aSkarels #define WANTOPENRAW 2 /* open requested, no label */
1401a9c5c6aSkarels #define RDLABEL 3 /* reading pack label */
1411a9c5c6aSkarels #define RDBADTBL 4 /* reading bad-sector table */
1421a9c5c6aSkarels #define OPEN 5 /* initialized and ready */
1431a9c5c6aSkarels #define OPENRAW 6 /* open, no label or badsect */
1441a9c5c6aSkarels
1451a9c5c6aSkarels #define b_cylin b_resid
1461a9c5c6aSkarels
1471a9c5c6aSkarels /* #define ML11 0 to remove ML11 support */
1481a9c5c6aSkarels #define ML11(type) ((type) == HPDT_ML11A)
1491a9c5c6aSkarels #define RP06(type) (hptypes[type] <= MBDT_RP06)
1501a9c5c6aSkarels #define RM80(type) ((type) == HPDT_RM80)
1511a9c5c6aSkarels
1521a9c5c6aSkarels #define hpunit(dev) (minor(dev) >> 3)
1531a9c5c6aSkarels #define hppart(dev) (minor(dev) & 07)
1541a9c5c6aSkarels #define hpminor(unit, part) (((unit) << 3) | (part))
1551a9c5c6aSkarels
1561a9c5c6aSkarels #define MASKREG(reg) ((reg)&0xffff)
1571a9c5c6aSkarels #ifdef lint
1581a9c5c6aSkarels #define HPWAIT(mi, addr) (hpwait(mi))
1591a9c5c6aSkarels #else
1601a9c5c6aSkarels #define HPWAIT(mi, addr) (((addr)->hpds & HPDS_DRY) || hpwait(mi))
1611a9c5c6aSkarels #endif
1621a9c5c6aSkarels
1631a9c5c6aSkarels /*ARGSUSED*/
1641a9c5c6aSkarels hpattach(mi, slave)
1651a9c5c6aSkarels struct mba_device *mi;
1661a9c5c6aSkarels {
1671a9c5c6aSkarels register int unit = mi->mi_unit;
168fd8888adSkarels extern int cold;
1691a9c5c6aSkarels
170fd8888adSkarels if (cold) {
1711a9c5c6aSkarels /*
1721a9c5c6aSkarels * Try to initialize device and read pack label.
1731a9c5c6aSkarels */
1741a9c5c6aSkarels if (hpinit(hpminor(unit, 0), 0) == 0) {
17503308f71Skarels printf(": %s", hplabel[unit].d_typename);
1761a9c5c6aSkarels #ifdef notyet
177fd8888adSkarels addswap(makedev(HPMAJOR, hpminor(unit, 0)),
178fd8888adSkarels &hplabel[unit]);
1791a9c5c6aSkarels #endif
1801a9c5c6aSkarels } else
18103308f71Skarels printf(": offline");
1821a9c5c6aSkarels }
183fd8888adSkarels }
1841a9c5c6aSkarels
hpopen(dev,flags,fmt)185f960dea9Skarels hpopen(dev, flags, fmt)
1861a9c5c6aSkarels dev_t dev;
187f960dea9Skarels int flags, fmt;
1881a9c5c6aSkarels {
1891a9c5c6aSkarels register int unit = hpunit(dev);
1901a9c5c6aSkarels register struct hpsoftc *sc;
1911a9c5c6aSkarels register struct disklabel *lp;
1921a9c5c6aSkarels register struct partition *pp;
1931a9c5c6aSkarels struct mba_device *mi;
194f960dea9Skarels int s, error, part = hppart(dev), mask = 1 << part;
1951a9c5c6aSkarels daddr_t start, end;
1961a9c5c6aSkarels
1971a9c5c6aSkarels if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0)
1981a9c5c6aSkarels return (ENXIO);
1991a9c5c6aSkarels sc = &hpsoftc[unit];
2001a9c5c6aSkarels lp = &hplabel[unit];
2011a9c5c6aSkarels
2021a9c5c6aSkarels s = spl5();
2031a9c5c6aSkarels while (sc->sc_state != OPEN && sc->sc_state != OPENRAW &&
2041a9c5c6aSkarels sc->sc_state != CLOSED)
2059abc1b4cSkarels if (error = tsleep((caddr_t)sc, (PZERO+1) | PCATCH,
2069abc1b4cSkarels devopn, 0)) {
2079abc1b4cSkarels splx(s);
2089abc1b4cSkarels return (error);
2099abc1b4cSkarels }
2101a9c5c6aSkarels splx(s);
2111a9c5c6aSkarels if (sc->sc_state != OPEN && sc->sc_state != OPENRAW)
2121a9c5c6aSkarels if (error = hpinit(dev, flags))
2131a9c5c6aSkarels return (error);
2141a9c5c6aSkarels if (part >= lp->d_npartitions)
2151a9c5c6aSkarels return (ENXIO);
2161a9c5c6aSkarels /*
2171a9c5c6aSkarels * Warn if a partion is opened
2181a9c5c6aSkarels * that overlaps another partition which is open
2191a9c5c6aSkarels * unless one is the "raw" partition (whole disk).
2201a9c5c6aSkarels */
2211a9c5c6aSkarels #define RAWPART 2 /* 'c' partition */ /* XXX */
222c83a6d18Skarels if ((sc->sc_openpart & mask) == 0 && part != RAWPART) {
2231a9c5c6aSkarels pp = &lp->d_partitions[part];
2241a9c5c6aSkarels start = pp->p_offset;
2251a9c5c6aSkarels end = pp->p_offset + pp->p_size;
2261a9c5c6aSkarels for (pp = lp->d_partitions;
2271a9c5c6aSkarels pp < &lp->d_partitions[lp->d_npartitions]; pp++) {
2281a9c5c6aSkarels if (pp->p_offset + pp->p_size <= start ||
2291a9c5c6aSkarels pp->p_offset >= end)
2301a9c5c6aSkarels continue;
2311a9c5c6aSkarels if (pp - lp->d_partitions == RAWPART)
2321a9c5c6aSkarels continue;
2331a9c5c6aSkarels if (sc->sc_openpart & (1 << (pp - lp->d_partitions)))
2341a9c5c6aSkarels log(LOG_WARNING,
2351a9c5c6aSkarels "hp%d%c: overlaps open partition (%c)\n",
2361a9c5c6aSkarels unit, part + 'a',
2371a9c5c6aSkarels pp - lp->d_partitions + 'a');
2381a9c5c6aSkarels }
2391a9c5c6aSkarels }
240f960dea9Skarels switch (fmt) {
241f960dea9Skarels case S_IFCHR:
242f960dea9Skarels sc->sc_copenpart |= mask;
243f960dea9Skarels break;
244f960dea9Skarels case S_IFBLK:
245f960dea9Skarels sc->sc_bopenpart |= mask;
246f960dea9Skarels break;
247f960dea9Skarels }
248f960dea9Skarels sc->sc_openpart |= mask;
2491a9c5c6aSkarels return (0);
2501a9c5c6aSkarels }
2511a9c5c6aSkarels
25223378597Skarels /* ARGSUSED */
hpclose(dev,flags,fmt)253f960dea9Skarels hpclose(dev, flags, fmt)
2541a9c5c6aSkarels dev_t dev;
255f960dea9Skarels int flags, fmt;
2561a9c5c6aSkarels {
2571a9c5c6aSkarels register int unit = hpunit(dev);
2581a9c5c6aSkarels register struct hpsoftc *sc;
2591a9c5c6aSkarels struct mba_device *mi;
260f960dea9Skarels int s, mask = 1 << hppart(dev);
2611a9c5c6aSkarels
2621a9c5c6aSkarels sc = &hpsoftc[unit];
2631a9c5c6aSkarels mi = hpinfo[unit];
264f960dea9Skarels switch (fmt) {
265f960dea9Skarels case S_IFCHR:
266f960dea9Skarels sc->sc_copenpart &= ~mask;
267f960dea9Skarels break;
268f960dea9Skarels case S_IFBLK:
269f960dea9Skarels sc->sc_bopenpart &= ~mask;
270f960dea9Skarels break;
271f960dea9Skarels }
272fd8888adSkarels sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart;
273fd8888adSkarels
2741a9c5c6aSkarels /*
2751a9c5c6aSkarels * Should wait for I/O to complete on this partition
2761a9c5c6aSkarels * even if others are open, but wait for work on blkflush().
2771a9c5c6aSkarels */
2781a9c5c6aSkarels if (sc->sc_openpart == 0) {
2791a9c5c6aSkarels s = spl5();
2801a9c5c6aSkarels while (mi->mi_tab.b_actf)
281f960dea9Skarels sleep((caddr_t)sc, PZERO - 1);
2821a9c5c6aSkarels splx(s);
2831a9c5c6aSkarels sc->sc_state = CLOSED;
284fd8888adSkarels sc->sc_wlabel = 0;
2851a9c5c6aSkarels }
286f960dea9Skarels return (0);
2871a9c5c6aSkarels }
2881a9c5c6aSkarels
hpinit(dev,flags)2891a9c5c6aSkarels hpinit(dev, flags)
2901a9c5c6aSkarels dev_t dev;
2911a9c5c6aSkarels int flags;
2921a9c5c6aSkarels {
2931a9c5c6aSkarels register struct hpsoftc *sc;
2941a9c5c6aSkarels register struct buf *bp;
2951a9c5c6aSkarels register struct disklabel *lp;
2961a9c5c6aSkarels struct mba_device *mi;
2971a9c5c6aSkarels struct hpdevice *hpaddr;
2981a9c5c6aSkarels struct dkbad *db;
299f960dea9Skarels char *msg, *readdisklabel();
3001a9c5c6aSkarels int unit, i, error = 0;
3011a9c5c6aSkarels
3021a9c5c6aSkarels unit = hpunit(dev);
3031a9c5c6aSkarels sc = &hpsoftc[unit];
3041a9c5c6aSkarels lp = &hplabel[unit];
3051a9c5c6aSkarels mi = hpinfo[unit];
3061a9c5c6aSkarels hpaddr = (struct hpdevice *)mi->mi_drv;
3071a9c5c6aSkarels
3081a9c5c6aSkarels sc->sc_state = WANTOPEN;
3091a9c5c6aSkarels /*
3101a9c5c6aSkarels * Use the default sizes until we've read the label,
3111a9c5c6aSkarels * or longer if there isn't one there.
3121a9c5c6aSkarels */
313fd8888adSkarels if (lp->d_secpercyl == 0) {
3141a9c5c6aSkarels lp->d_secsize = DEV_BSIZE;
3151a9c5c6aSkarels lp->d_nsectors = 32;
3161a9c5c6aSkarels lp->d_ntracks = 20;
3171a9c5c6aSkarels lp->d_secpercyl = 32*20;
3184fcad5b5Skarels lp->d_npartitions = 1;
3194fcad5b5Skarels lp->d_partitions[0].p_offset = 0;
3204fcad5b5Skarels lp->d_partitions[0].p_size = LABELSECTOR + 1;
321fd8888adSkarels }
3221a9c5c6aSkarels
323e94346f6Skarels if (flags & O_NDELAY)
324e94346f6Skarels goto raw;
325e94346f6Skarels
3261a9c5c6aSkarels /*
3271a9c5c6aSkarels * Map all ML11's to the same type. Also calculate
3281a9c5c6aSkarels * transfer rates based on device characteristics.
3291a9c5c6aSkarels * Set up dummy label with all that's needed.
3301a9c5c6aSkarels */
3311a9c5c6aSkarels if (mi->mi_type == MBDT_ML11A || mi->mi_type == MBDT_ML11B) {
3321a9c5c6aSkarels register int trt;
3331a9c5c6aSkarels
3341a9c5c6aSkarels sc->sc_mlsize = hpaddr->hpmr & HPMR_SZ;
3351a9c5c6aSkarels if ((hpaddr->hpmr & HPMR_ARRTYP) == 0)
3361a9c5c6aSkarels sc->sc_mlsize >>= 2;
3371a9c5c6aSkarels if (mi->mi_dk >= 0) {
3381a9c5c6aSkarels trt = (hpaddr->hpmr & HPMR_TRT) >> 8;
339ef17d506Smckusick dk_wpms[mi->mi_dk] = (1<<(20-trt));
3401a9c5c6aSkarels }
3411a9c5c6aSkarels mi->mi_type = MBDT_ML11A;
3421a9c5c6aSkarels lp->d_partitions[0].p_size = sc->sc_mlsize;
3431a9c5c6aSkarels lp->d_secpercyl = sc->sc_mlsize;
344e94346f6Skarels goto raw;
3451a9c5c6aSkarels }
3461a9c5c6aSkarels
3471a9c5c6aSkarels /*
3481a9c5c6aSkarels * Preset, pack acknowledge will be done in hpstart
3491a9c5c6aSkarels * during first read operation.
3501a9c5c6aSkarels */
351f960dea9Skarels if (msg = readdisklabel(dev, hpstrategy, lp)) {
35203308f71Skarels if (cold)
353f960dea9Skarels printf(": %s", msg);
35403308f71Skarels else
355f960dea9Skarels log(LOG_ERR, "hp%d: %s\n", unit, msg);
3561a9c5c6aSkarels #ifdef COMPAT_42
357fc429abdSkarels if (hpmaptype(mi, lp) == 0)
3581a9c5c6aSkarels #endif
359fd8888adSkarels goto raw;
3601a9c5c6aSkarels }
3611a9c5c6aSkarels
3621a9c5c6aSkarels /*
3631a9c5c6aSkarels * Seconds per word = (60 / rpm) / (nsectors * secsize/2)
3641a9c5c6aSkarels */
3651a9c5c6aSkarels if (mi->mi_dk >= 0 && lp->d_rpm)
366ef17d506Smckusick dk_wpms[mi->mi_dk] =
367ef17d506Smckusick (lp->d_rpm * lp->d_nsectors * lp->d_secsize) / 120;
3681a9c5c6aSkarels /*
3691a9c5c6aSkarels * Read bad sector table into memory.
3701a9c5c6aSkarels */
371f960dea9Skarels bp = geteblk(DEV_BSIZE); /* max sector size */
372f960dea9Skarels bp->b_dev = dev;
3731a9c5c6aSkarels sc->sc_state = RDBADTBL;
3741a9c5c6aSkarels i = 0;
3751a9c5c6aSkarels do {
3761a9c5c6aSkarels bp->b_flags = B_BUSY | B_READ;
3771a9c5c6aSkarels bp->b_blkno = lp->d_secperunit - lp->d_nsectors + i;
3781a9c5c6aSkarels bp->b_bcount = lp->d_secsize;
3791a9c5c6aSkarels bp->b_cylin = lp->d_ncylinders - 1;
3801a9c5c6aSkarels hpstrategy(bp);
381dae78867Smckusick (void) biowait(bp);
3821a9c5c6aSkarels } while ((bp->b_flags & B_ERROR) && (i += 2) < 10 &&
3831a9c5c6aSkarels i < lp->d_nsectors);
3841a9c5c6aSkarels db = (struct dkbad *)(bp->b_un.b_addr);
3851a9c5c6aSkarels if ((bp->b_flags & B_ERROR) == 0 && db->bt_mbz == 0 &&
3861a9c5c6aSkarels db->bt_flag == 0) {
3871a9c5c6aSkarels hpbad[unit] = *db;
388dae78867Smckusick } else
3891a9c5c6aSkarels log(LOG_ERR, "hp%d: %s bad-sector file\n", unit,
3901a9c5c6aSkarels (bp->b_flags & B_ERROR) ? "can't read" : "format error in");
391fd8888adSkarels sc->sc_state = OPEN;
3921a9c5c6aSkarels bp->b_flags = B_INVAL | B_AGE;
3931a9c5c6aSkarels brelse(bp);
3941a9c5c6aSkarels wakeup((caddr_t)sc);
3951a9c5c6aSkarels return (error);
396e94346f6Skarels
397e94346f6Skarels raw:
398fd8888adSkarels if (cold)
399fd8888adSkarels sc->sc_state = CLOSED;
400fd8888adSkarels else {
401e94346f6Skarels sc->sc_state = OPENRAW;
402e94346f6Skarels wakeup((caddr_t)sc);
403fd8888adSkarels }
404e94346f6Skarels return (error);
4051a9c5c6aSkarels }
4061a9c5c6aSkarels
hpstrategy(bp)4071a9c5c6aSkarels hpstrategy(bp)
4081a9c5c6aSkarels register struct buf *bp;
4091a9c5c6aSkarels {
4101a9c5c6aSkarels register struct mba_device *mi;
4111a9c5c6aSkarels register struct disklabel *lp;
4121a9c5c6aSkarels register struct hpsoftc *sc;
4131a9c5c6aSkarels register int unit;
4141a9c5c6aSkarels daddr_t sz, maxsz;
4151a9c5c6aSkarels int xunit = hppart(bp->b_dev);
4161a9c5c6aSkarels int s;
4171a9c5c6aSkarels
4181a9c5c6aSkarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
4191a9c5c6aSkarels unit = hpunit(bp->b_dev);
4201a9c5c6aSkarels if (unit >= NHP) {
4211a9c5c6aSkarels bp->b_error = ENXIO;
4221a9c5c6aSkarels goto bad;
4231a9c5c6aSkarels }
4241a9c5c6aSkarels mi = hpinfo[unit];
4251a9c5c6aSkarels sc = &hpsoftc[unit];
4261a9c5c6aSkarels lp = &hplabel[unit];
4271a9c5c6aSkarels if (mi == 0 || mi->mi_alive == 0) {
4281a9c5c6aSkarels bp->b_error = ENXIO;
4291a9c5c6aSkarels goto bad;
4301a9c5c6aSkarels }
431fd8888adSkarels #ifdef COMPAT_42
432fd8888adSkarels if (sc->sc_hdr) { /* XXX */
433fd8888adSkarels if (bp->b_bcount == 516)
434fd8888adSkarels bp->b_flags |= B_FORMAT;
435fd8888adSkarels sc->sc_hdr = 0;
436fd8888adSkarels }
437fd8888adSkarels #endif
4381a9c5c6aSkarels if (sc->sc_state < OPEN)
4391a9c5c6aSkarels goto q;
4409abc1b4cSkarels if (sc->sc_state != OPEN && (bp->b_flags & (B_READ|B_FORMAT)) == 0) {
441fd8888adSkarels bp->b_error = EROFS;
442fd8888adSkarels goto bad;
443fd8888adSkarels }
4441a9c5c6aSkarels if ((sc->sc_openpart & (1 << xunit)) == 0) {
4451a9c5c6aSkarels bp->b_error = ENODEV;
4461a9c5c6aSkarels goto bad;
4471a9c5c6aSkarels }
4481a9c5c6aSkarels maxsz = lp->d_partitions[xunit].p_size;
449fd8888adSkarels if (bp->b_blkno + lp->d_partitions[xunit].p_offset <= LABELSECTOR &&
450fd8888adSkarels #if LABELSECTOR != 0
451fd8888adSkarels bp->b_blkno + lp->d_partitions[xunit].p_offset + sz > LABELSECTOR &&
452fd8888adSkarels #endif
453fd8888adSkarels (bp->b_flags & B_READ) == 0 && sc->sc_wlabel == 0) {
454fd8888adSkarels bp->b_error = EROFS;
455fd8888adSkarels goto bad;
456fd8888adSkarels }
4571a9c5c6aSkarels if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) {
4581a9c5c6aSkarels if (bp->b_blkno == maxsz) {
4591a9c5c6aSkarels bp->b_resid = bp->b_bcount;
4601a9c5c6aSkarels goto done;
4611a9c5c6aSkarels }
4621a9c5c6aSkarels sz = maxsz - bp->b_blkno;
4631a9c5c6aSkarels if (sz <= 0) {
4641a9c5c6aSkarels bp->b_error = EINVAL;
4651a9c5c6aSkarels goto bad;
4661a9c5c6aSkarels }
4671a9c5c6aSkarels bp->b_bcount = sz << DEV_BSHIFT;
4681a9c5c6aSkarels }
4691a9c5c6aSkarels bp->b_cylin = (bp->b_blkno + lp->d_partitions[xunit].p_offset) /
4701a9c5c6aSkarels lp->d_secpercyl;
4711a9c5c6aSkarels q:
4721a9c5c6aSkarels s = spl5();
4731a9c5c6aSkarels disksort(&mi->mi_tab, bp);
4741a9c5c6aSkarels if (mi->mi_tab.b_active == 0)
4751a9c5c6aSkarels mbustart(mi);
4761a9c5c6aSkarels splx(s);
4771a9c5c6aSkarels return;
4781a9c5c6aSkarels
4791a9c5c6aSkarels bad:
4801a9c5c6aSkarels bp->b_flags |= B_ERROR;
4811a9c5c6aSkarels done:
4821a9c5c6aSkarels biodone(bp);
4831a9c5c6aSkarels return;
4841a9c5c6aSkarels }
4851a9c5c6aSkarels
hpustart(mi)4861a9c5c6aSkarels hpustart(mi)
4871a9c5c6aSkarels register struct mba_device *mi;
4881a9c5c6aSkarels {
4891a9c5c6aSkarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
4901a9c5c6aSkarels register struct buf *bp = mi->mi_tab.b_actf;
4911a9c5c6aSkarels register struct disklabel *lp;
4921a9c5c6aSkarels struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
4931a9c5c6aSkarels daddr_t bn;
4941a9c5c6aSkarels int sn, tn, dist;
4951a9c5c6aSkarels
4961a9c5c6aSkarels lp = &hplabel[mi->mi_unit];
4971a9c5c6aSkarels hpaddr->hpcs1 = 0;
4981a9c5c6aSkarels if ((hpaddr->hpcs1&HP_DVA) == 0)
4991a9c5c6aSkarels return (MBU_BUSY);
5001a9c5c6aSkarels
5011a9c5c6aSkarels switch (sc->sc_recal) {
5021a9c5c6aSkarels
5031a9c5c6aSkarels case 1:
5041a9c5c6aSkarels (void)HPWAIT(mi, hpaddr);
5051a9c5c6aSkarels hpaddr->hpdc = bp->b_cylin;
5061a9c5c6aSkarels hpaddr->hpcs1 = HP_SEEK|HP_GO;
5071a9c5c6aSkarels sc->sc_recal++;
5081a9c5c6aSkarels return (MBU_STARTED);
5091a9c5c6aSkarels case 2:
5101a9c5c6aSkarels break;
5111a9c5c6aSkarels }
5121a9c5c6aSkarels sc->sc_recal = 0;
5131a9c5c6aSkarels if ((hpaddr->hpds & HPDS_VV) == 0) {
5141a9c5c6aSkarels if (sc->sc_state == OPEN && lp->d_flags & D_REMOVABLE) {
5151a9c5c6aSkarels if (sc->sc_openpart)
5161a9c5c6aSkarels log(LOG_ERR, "hp%d: volume changed\n",
5171a9c5c6aSkarels mi->mi_unit);
5181a9c5c6aSkarels sc->sc_openpart = 0;
5191a9c5c6aSkarels bp->b_flags |= B_ERROR;
5201a9c5c6aSkarels return (MBU_NEXT);
5211a9c5c6aSkarels }
5221a9c5c6aSkarels hpaddr->hpcs1 = HP_DCLR|HP_GO;
5231a9c5c6aSkarels if (mi->mi_mba->mba_drv[0].mbd_as & (1<<mi->mi_drive))
5241a9c5c6aSkarels printf("DCLR attn\n");
5251a9c5c6aSkarels hpaddr->hpcs1 = HP_PRESET|HP_GO;
5261a9c5c6aSkarels if (!ML11(mi->mi_type))
5271a9c5c6aSkarels hpaddr->hpof = HPOF_FMT22;
5281a9c5c6aSkarels mbclrattn(mi);
5291a9c5c6aSkarels if (sc->sc_state == WANTOPENRAW) {
5301a9c5c6aSkarels sc->sc_state = OPENRAW;
5311a9c5c6aSkarels return (MBU_NEXT);
5321a9c5c6aSkarels }
5331a9c5c6aSkarels if (sc->sc_state == WANTOPEN)
5341a9c5c6aSkarels sc->sc_state = RDLABEL;
5351a9c5c6aSkarels }
5361a9c5c6aSkarels if (mi->mi_tab.b_active || mi->mi_hd->mh_ndrive == 1) {
5371a9c5c6aSkarels if (mi->mi_tab.b_errcnt >= 16 && (bp->b_flags & B_READ)) {
5381a9c5c6aSkarels hpaddr->hpof =
5391a9c5c6aSkarels hp_offset[mi->mi_tab.b_errcnt & 017]|HPOF_FMT22;
5401a9c5c6aSkarels hpaddr->hpcs1 = HP_OFFSET|HP_GO;
5411a9c5c6aSkarels (void)HPWAIT(mi, hpaddr);
5421a9c5c6aSkarels mbclrattn(mi);
5431a9c5c6aSkarels }
5441a9c5c6aSkarels return (MBU_DODATA);
5451a9c5c6aSkarels }
5461a9c5c6aSkarels if (ML11(mi->mi_type))
5471a9c5c6aSkarels return (MBU_DODATA);
5481a9c5c6aSkarels if ((hpaddr->hpds & HPDS_DREADY) != HPDS_DREADY)
5491a9c5c6aSkarels return (MBU_DODATA);
5501a9c5c6aSkarels bn = bp->b_blkno;
5511a9c5c6aSkarels sn = bn % lp->d_secpercyl;
5521a9c5c6aSkarels tn = sn / lp->d_nsectors;
5531a9c5c6aSkarels sn = sn % lp->d_nsectors;
5541a9c5c6aSkarels if (bp->b_cylin == MASKREG(hpaddr->hpdc)) {
5551a9c5c6aSkarels if (sc->sc_doseeks)
5561a9c5c6aSkarels return (MBU_DODATA);
5571a9c5c6aSkarels dist = sn - (MASKREG(hpaddr->hpla) >> 6) - 1;
5581a9c5c6aSkarels if (dist < 0)
5591a9c5c6aSkarels dist += lp->d_nsectors;
560af4a276bSkarels if (dist <= lp->d_maxdist && dist >= lp->d_mindist)
5611a9c5c6aSkarels return (MBU_DODATA);
5621a9c5c6aSkarels } else
5631a9c5c6aSkarels hpaddr->hpdc = bp->b_cylin;
5641a9c5c6aSkarels if (sc->sc_doseeks)
5651a9c5c6aSkarels hpaddr->hpcs1 = HP_SEEK|HP_GO;
5661a9c5c6aSkarels else {
5671a9c5c6aSkarels sn = (sn + lp->d_nsectors - lp->d_sdist) % lp->d_nsectors;
5681a9c5c6aSkarels hpaddr->hpda = (tn << 8) + sn;
5691a9c5c6aSkarels hpaddr->hpcs1 = HP_SEARCH|HP_GO;
5701a9c5c6aSkarels }
5711a9c5c6aSkarels return (MBU_STARTED);
5721a9c5c6aSkarels }
5731a9c5c6aSkarels
hpstart(mi)5741a9c5c6aSkarels hpstart(mi)
5751a9c5c6aSkarels register struct mba_device *mi;
5761a9c5c6aSkarels {
5771a9c5c6aSkarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
5781a9c5c6aSkarels register struct buf *bp = mi->mi_tab.b_actf;
5791a9c5c6aSkarels register struct disklabel *lp = &hplabel[mi->mi_unit];
5801a9c5c6aSkarels struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
5811a9c5c6aSkarels daddr_t bn;
5821a9c5c6aSkarels int sn, tn, cn;
5831a9c5c6aSkarels
5841a9c5c6aSkarels if (ML11(mi->mi_type))
5851a9c5c6aSkarels hpaddr->hpda = bp->b_blkno + sc->sc_blkdone;
5861a9c5c6aSkarels else {
5871a9c5c6aSkarels if (bp->b_flags & B_BAD) {
5881a9c5c6aSkarels bn = sc->sc_badbn;
5891a9c5c6aSkarels cn = bn / lp->d_secpercyl;
5901a9c5c6aSkarels } else {
5911a9c5c6aSkarels bn = bp->b_blkno;
5921a9c5c6aSkarels cn = bp->b_cylin;
5931a9c5c6aSkarels }
5941a9c5c6aSkarels sn = bn % lp->d_secpercyl;
5951a9c5c6aSkarels if ((bp->b_flags & B_BAD) == 0)
5961a9c5c6aSkarels sn += sc->sc_blkdone;
5971a9c5c6aSkarels tn = sn / lp->d_nsectors;
5981a9c5c6aSkarels sn %= lp->d_nsectors;
5991a9c5c6aSkarels cn += tn / lp->d_ntracks;
6001a9c5c6aSkarels tn %= lp->d_ntracks;
6011a9c5c6aSkarels hpaddr->hpda = (tn << 8) + sn;
6021a9c5c6aSkarels hpaddr->hpdc = cn;
6031a9c5c6aSkarels }
6041a9c5c6aSkarels mi->mi_tab.b_bdone = dbtob(sc->sc_blkdone);
6051a9c5c6aSkarels if (bp->b_flags & B_FORMAT) {
6061a9c5c6aSkarels if (bp->b_flags & B_READ)
6071a9c5c6aSkarels return (HP_RHDR|HP_GO);
6081a9c5c6aSkarels else
6091a9c5c6aSkarels return (HP_WHDR|HP_GO);
6101a9c5c6aSkarels }
6111a9c5c6aSkarels return (0);
6121a9c5c6aSkarels }
6131a9c5c6aSkarels
hpdtint(mi,mbsr)6141a9c5c6aSkarels hpdtint(mi, mbsr)
6151a9c5c6aSkarels register struct mba_device *mi;
6161a9c5c6aSkarels int mbsr;
6171a9c5c6aSkarels {
6181a9c5c6aSkarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
6191a9c5c6aSkarels register struct buf *bp = mi->mi_tab.b_actf;
6201a9c5c6aSkarels register int er1, er2;
6211a9c5c6aSkarels struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
6221a9c5c6aSkarels int retry = 0;
623ca7ebfb4Skarels int npf, bcr;
6241a9c5c6aSkarels
6251a9c5c6aSkarels bcr = MASKREG(-mi->mi_mba->mba_bcr);
626fd8888adSkarels if (bp->b_flags & B_FORMAT) {
627fd8888adSkarels sc->sc_status = mbsr;
628fd8888adSkarels sc->sc_hpds = hpaddr->hpds;
629fd8888adSkarels sc->sc_er1 = hpaddr->hper1;
630fd8888adSkarels sc->sc_er2 = hpaddr->hper2;
631fd8888adSkarels }
6321a9c5c6aSkarels if (hpaddr->hpds&HPDS_ERR || mbsr&MBSR_EBITS) {
6331a9c5c6aSkarels er1 = hpaddr->hper1;
6341a9c5c6aSkarels er2 = hpaddr->hper2;
635ca7ebfb4Skarels if (bp->b_flags & B_BAD)
6361a9c5c6aSkarels npf = bp->b_error;
637ca7ebfb4Skarels else {
638fd8888adSkarels npf = btodb(bp->b_bcount + (DEV_BSIZE - 1) - bcr);
6391a9c5c6aSkarels if (er1 & (HPER1_DCK | HPER1_ECH))
6401a9c5c6aSkarels npf--;
6411a9c5c6aSkarels }
6421a9c5c6aSkarels if (HPWAIT(mi, hpaddr) == 0)
6431a9c5c6aSkarels goto hard;
6441a9c5c6aSkarels #ifdef HPDEBUG
6451a9c5c6aSkarels if (hpdebug) {
6461a9c5c6aSkarels int dc = hpaddr->hpdc, da = hpaddr->hpda;
647ca7ebfb4Skarels daddr_t bn;
6481a9c5c6aSkarels
649ca7ebfb4Skarels if (bp->b_flags & B_BAD)
650ca7ebfb4Skarels bn = sc->sc_badbn;
651ca7ebfb4Skarels else
652ca7ebfb4Skarels bn = bp->b_blkno + npf;
6531a9c5c6aSkarels log(LOG_DEBUG,
6541a9c5c6aSkarels "hperr: bp %x cyl %d blk %d blkdone %d as %o dc %x da %x\n",
6551a9c5c6aSkarels bp, bp->b_cylin, bn, sc->sc_blkdone,
6561a9c5c6aSkarels hpaddr->hpas&0xff, MASKREG(dc), MASKREG(da));
6571a9c5c6aSkarels log(LOG_DEBUG,
6581a9c5c6aSkarels "errcnt %d mbsr=%b er1=%b er2=%b bcr -%d\n",
6591a9c5c6aSkarels mi->mi_tab.b_errcnt, mbsr, mbsr_bits,
6601a9c5c6aSkarels MASKREG(er1), HPER1_BITS,
6611a9c5c6aSkarels MASKREG(er2), HPER2_BITS, bcr);
6621a9c5c6aSkarels }
6631a9c5c6aSkarels #endif
6641a9c5c6aSkarels if (er1 & HPER1_HCRC) {
6651a9c5c6aSkarels er1 &= ~(HPER1_HCE|HPER1_FER);
6661a9c5c6aSkarels er2 &= ~HPER2_BSE;
6671a9c5c6aSkarels }
6681a9c5c6aSkarels if (er1 & HPER1_WLE) {
6691a9c5c6aSkarels log(LOG_WARNING, "hp%d: write locked\n",
6701a9c5c6aSkarels hpunit(bp->b_dev));
6711a9c5c6aSkarels bp->b_flags |= B_ERROR;
6721a9c5c6aSkarels } else if (bp->b_flags & B_FORMAT) {
673ca7ebfb4Skarels bp->b_flags |= B_ERROR;
6741a9c5c6aSkarels } else if (RM80(mi->mi_type) && er2&HPER2_SSE) {
6751a9c5c6aSkarels (void) hpecc(mi, SSE);
6761a9c5c6aSkarels return (MBD_RESTARTED);
6771a9c5c6aSkarels } else if ((er2 & HPER2_BSE) && !ML11(mi->mi_type)) {
6781a9c5c6aSkarels if (hpecc(mi, BSE))
6791a9c5c6aSkarels return (MBD_RESTARTED);
6801a9c5c6aSkarels goto hard;
6811a9c5c6aSkarels } else if (MASKREG(er1) == HPER1_FER && RP06(mi->mi_type)) {
6821a9c5c6aSkarels if (hpecc(mi, BSE))
6831a9c5c6aSkarels return (MBD_RESTARTED);
6841a9c5c6aSkarels goto hard;
6851a9c5c6aSkarels } else if ((er1 & (HPER1_DCK | HPER1_ECH)) == HPER1_DCK &&
6861a9c5c6aSkarels mi->mi_tab.b_errcnt >= 3) {
6871a9c5c6aSkarels if (hpecc(mi, ECC))
6881a9c5c6aSkarels return (MBD_RESTARTED);
6891a9c5c6aSkarels /*
6901a9c5c6aSkarels * ECC corrected. Only log retries below
6911a9c5c6aSkarels * if we got errors other than soft ECC
6921a9c5c6aSkarels * (as indicated by additional retries).
6931a9c5c6aSkarels */
6941a9c5c6aSkarels if (mi->mi_tab.b_errcnt == 3)
6951a9c5c6aSkarels mi->mi_tab.b_errcnt = 0;
6961a9c5c6aSkarels } else if ((er1 & HPER1_HCRC) && !ML11(mi->mi_type) &&
6971a9c5c6aSkarels hpecc(mi, BSE)) {
6981a9c5c6aSkarels /*
6991a9c5c6aSkarels * HCRC means the header is screwed up and the sector
7001a9c5c6aSkarels * might well exist in the bad sector table,
7011a9c5c6aSkarels * better check....
7021a9c5c6aSkarels */
7031a9c5c6aSkarels return (MBD_RESTARTED);
7041a9c5c6aSkarels } else if (++mi->mi_tab.b_errcnt > 27 ||
7051a9c5c6aSkarels (ML11(mi->mi_type) && mi->mi_tab.b_errcnt > 15) ||
7061a9c5c6aSkarels mbsr & MBSR_HARD ||
7071a9c5c6aSkarels er1 & HPER1_HARD ||
7081a9c5c6aSkarels (!ML11(mi->mi_type) && (er2 & HPER2_HARD))) {
7091a9c5c6aSkarels hard:
710ca7ebfb4Skarels diskerr(bp, "hp", "hard error", LOG_PRINTF, npf,
711ca7ebfb4Skarels &hplabel[mi->mi_unit]);
712ca7ebfb4Skarels if (bp->b_flags & B_BAD)
713ca7ebfb4Skarels printf(" (on replacement sector %d)",
714ca7ebfb4Skarels sc->sc_badbn);
7151a9c5c6aSkarels if (mbsr & (MBSR_EBITS &~ (MBSR_DTABT|MBSR_MBEXC)))
7161a9c5c6aSkarels printf(" mbsr=%b", mbsr, mbsr_bits);
7179abc1b4cSkarels printf(" er1=%b er2=%b ds=%b\n",
7181a9c5c6aSkarels MASKREG(hpaddr->hper1), HPER1_BITS,
7199abc1b4cSkarels MASKREG(hpaddr->hper2), HPER2_BITS,
7209abc1b4cSkarels MASKREG(hpaddr->hpds), HPDS_BITS);
7211a9c5c6aSkarels bp->b_flags |= B_ERROR;
7221a9c5c6aSkarels bp->b_flags &= ~B_BAD;
7231a9c5c6aSkarels } else
7241a9c5c6aSkarels retry = 1;
7251a9c5c6aSkarels hpaddr->hpcs1 = HP_DCLR|HP_GO;
7261a9c5c6aSkarels if (retry && (mi->mi_tab.b_errcnt & 07) == 4) {
7271a9c5c6aSkarels hpaddr->hpcs1 = HP_RECAL|HP_GO;
7281a9c5c6aSkarels sc->sc_recal = 1;
7291a9c5c6aSkarels return (MBD_REPOSITION);
7301a9c5c6aSkarels }
7311a9c5c6aSkarels }
7321a9c5c6aSkarels #ifdef HPDEBUG
7331a9c5c6aSkarels else
7341a9c5c6aSkarels if (hpdebug && sc->sc_recal) {
7351a9c5c6aSkarels log(LOG_DEBUG,
7361a9c5c6aSkarels "recal %d errcnt %d mbsr=%b er1=%b er2=%b\n",
7371a9c5c6aSkarels sc->sc_recal, mi->mi_tab.b_errcnt, mbsr, mbsr_bits,
7381a9c5c6aSkarels hpaddr->hper1, HPER1_BITS,
7391a9c5c6aSkarels hpaddr->hper2, HPER2_BITS);
7401a9c5c6aSkarels }
7411a9c5c6aSkarels #endif
7421a9c5c6aSkarels (void)HPWAIT(mi, hpaddr);
7431a9c5c6aSkarels if (retry)
7441a9c5c6aSkarels return (MBD_RETRY);
7451a9c5c6aSkarels if (mi->mi_tab.b_errcnt >= 16) {
7461a9c5c6aSkarels /*
7471a9c5c6aSkarels * This is fast and occurs rarely; we don't
7481a9c5c6aSkarels * bother with interrupts.
7491a9c5c6aSkarels */
7501a9c5c6aSkarels hpaddr->hpcs1 = HP_RTC|HP_GO;
7511a9c5c6aSkarels (void)HPWAIT(mi, hpaddr);
7521a9c5c6aSkarels mbclrattn(mi);
7531a9c5c6aSkarels }
754ca7ebfb4Skarels if (mi->mi_tab.b_errcnt && (bp->b_flags & B_ERROR) == 0) {
755ca7ebfb4Skarels diskerr(bp, "hp", "retries", LOG_INFO, sc->sc_blkdone,
756ca7ebfb4Skarels &hplabel[mi->mi_unit]);
757ca7ebfb4Skarels addlog(": %d retries\n", mi->mi_tab.b_errcnt);
758ca7ebfb4Skarels }
7591a9c5c6aSkarels if ((bp->b_flags & B_BAD) && hpecc(mi, CONT))
7601a9c5c6aSkarels return (MBD_RESTARTED);
7611a9c5c6aSkarels sc->sc_blkdone = 0;
7621a9c5c6aSkarels bp->b_resid = bcr;
7631a9c5c6aSkarels if (!ML11(mi->mi_type)) {
7641a9c5c6aSkarels hpaddr->hpof = HPOF_FMT22;
7651a9c5c6aSkarels hpaddr->hpcs1 = HP_RELEASE|HP_GO;
7661a9c5c6aSkarels }
767f960dea9Skarels if (sc->sc_openpart == 0)
768f960dea9Skarels wakeup((caddr_t)sc);
7691a9c5c6aSkarels return (MBD_DONE);
7701a9c5c6aSkarels }
7711a9c5c6aSkarels
7721a9c5c6aSkarels /*
7731a9c5c6aSkarels * Wait (for a bit) for a drive to come ready;
7741a9c5c6aSkarels * returns nonzero on success.
7751a9c5c6aSkarels */
hpwait(mi)7761a9c5c6aSkarels hpwait(mi)
7771a9c5c6aSkarels register struct mba_device *mi;
7781a9c5c6aSkarels {
7791a9c5c6aSkarels register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
7801a9c5c6aSkarels register i = 100000;
7811a9c5c6aSkarels
7821a9c5c6aSkarels while ((hpaddr->hpds & HPDS_DRY) == 0 && --i)
7831a9c5c6aSkarels DELAY(10);
7841a9c5c6aSkarels if (i == 0)
7851a9c5c6aSkarels printf("hp%d: intr, not ready\n", mi->mi_unit);
7861a9c5c6aSkarels return (i);
7871a9c5c6aSkarels }
7881a9c5c6aSkarels
hpioctl(dev,cmd,data,flag)7891a9c5c6aSkarels hpioctl(dev, cmd, data, flag)
7901a9c5c6aSkarels dev_t dev;
7911a9c5c6aSkarels int cmd;
7921a9c5c6aSkarels caddr_t data;
7931a9c5c6aSkarels int flag;
7941a9c5c6aSkarels {
7951a9c5c6aSkarels int unit = hpunit(dev);
7961a9c5c6aSkarels register struct disklabel *lp;
797fd8888adSkarels register struct hpsoftc *sc = &hpsoftc[unit];
798932a00a3Skarels int error = 0;
7991a9c5c6aSkarels int hpformat();
8001a9c5c6aSkarels
8011a9c5c6aSkarels lp = &hplabel[unit];
8021a9c5c6aSkarels
8031a9c5c6aSkarels switch (cmd) {
8041a9c5c6aSkarels
8051a9c5c6aSkarels case DIOCGDINFO:
8061a9c5c6aSkarels *(struct disklabel *)data = *lp;
8071a9c5c6aSkarels break;
8081a9c5c6aSkarels
809f960dea9Skarels case DIOCGPART:
810f960dea9Skarels ((struct partinfo *)data)->disklab = lp;
811f960dea9Skarels ((struct partinfo *)data)->part =
812f960dea9Skarels &lp->d_partitions[hppart(dev)];
8131a9c5c6aSkarels break;
8141a9c5c6aSkarels
8151a9c5c6aSkarels case DIOCSDINFO:
8161a9c5c6aSkarels if ((flag & FWRITE) == 0)
8171a9c5c6aSkarels error = EBADF;
8181a9c5c6aSkarels else
819c83a6d18Skarels error = setdisklabel(lp, (struct disklabel *)data,
820fd8888adSkarels (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart);
821fd8888adSkarels if (error == 0)
822fd8888adSkarels sc->sc_state = OPEN;
823fd8888adSkarels break;
824fd8888adSkarels
825fd8888adSkarels case DIOCWLABEL:
826fd8888adSkarels if ((flag & FWRITE) == 0)
827fd8888adSkarels error = EBADF;
828fd8888adSkarels else
829fd8888adSkarels sc->sc_wlabel = *(int *)data;
8301a9c5c6aSkarels break;
8311a9c5c6aSkarels
8321a9c5c6aSkarels case DIOCWDINFO:
833c83a6d18Skarels if ((flag & FWRITE) == 0)
8341a9c5c6aSkarels error = EBADF;
835c83a6d18Skarels else if ((error = setdisklabel(lp, (struct disklabel *)data,
836fd8888adSkarels (sc->sc_state == OPENRAW) ? 0 : sc->sc_openpart)) == 0) {
837932a00a3Skarels int wlab;
838932a00a3Skarels
839fd8888adSkarels sc->sc_state = OPEN;
840932a00a3Skarels /* simulate opening partition 0 so write succeeds */
841932a00a3Skarels sc->sc_openpart |= (1 << 0); /* XXX */
842932a00a3Skarels wlab = sc->sc_wlabel;
843932a00a3Skarels sc->sc_wlabel = 1;
844c83a6d18Skarels error = writedisklabel(dev, hpstrategy, lp);
845fd8888adSkarels sc->sc_openpart = sc->sc_copenpart | sc->sc_bopenpart;
846fd8888adSkarels sc->sc_wlabel = wlab;
847932a00a3Skarels }
8481a9c5c6aSkarels break;
8491a9c5c6aSkarels
850fd8888adSkarels case DIOCSBAD:
851fd8888adSkarels {
852fd8888adSkarels struct dkbad *db = (struct dkbad *)data;
853fd8888adSkarels
854fd8888adSkarels if ((flag & FWRITE) == 0)
8551a9c5c6aSkarels error = EBADF;
856fd8888adSkarels else if (db->bt_mbz != 0 || db->bt_flag != 0)
857fd8888adSkarels error = EINVAL;
858fd8888adSkarels else
859fd8888adSkarels hpbad[unit] = *db;
8601a9c5c6aSkarels break;
8611a9c5c6aSkarels }
862fd8888adSkarels
863fd8888adSkarels case DIOCRFORMAT:
864fd8888adSkarels case DIOCWFORMAT:
8651a9c5c6aSkarels {
866ccef8083Sbostic register struct format_op *fop;
8671a9c5c6aSkarels struct uio auio;
8681a9c5c6aSkarels struct iovec aiov;
8691a9c5c6aSkarels
870fd8888adSkarels if (cmd == DIOCWFORMAT && (flag & FWRITE) == 0) {
871fd8888adSkarels error = EBADF;
872fd8888adSkarels break;
873fd8888adSkarels }
8741a9c5c6aSkarels fop = (struct format_op *)data;
8751a9c5c6aSkarels aiov.iov_base = fop->df_buf;
8761a9c5c6aSkarels aiov.iov_len = fop->df_count;
8771a9c5c6aSkarels auio.uio_iov = &aiov;
8781a9c5c6aSkarels auio.uio_iovcnt = 1;
8791a9c5c6aSkarels auio.uio_resid = fop->df_count;
880fd8888adSkarels auio.uio_segflg = UIO_USERSPACE;
8811a9c5c6aSkarels auio.uio_offset = fop->df_startblk * lp->d_secsize;
882fd8888adSkarels /*
883fd8888adSkarels * Don't return errors, as the format op won't get copied
884fd8888adSkarels * out if we return nonzero. Callers must check the returned
885fd8888adSkarels * count.
886fd8888adSkarels */
887ccef8083Sbostic (void) physio(hpformat, (struct buf *)NULL, dev,
888fd8888adSkarels (cmd == DIOCWFORMAT ? B_WRITE : B_READ), minphys, &auio);
8891a9c5c6aSkarels fop->df_count -= auio.uio_resid;
8901a9c5c6aSkarels fop->df_reg[0] = sc->sc_status;
891fd8888adSkarels fop->df_reg[1] = sc->sc_hpds;
892fd8888adSkarels fop->df_reg[2] = sc->sc_er1;
893fd8888adSkarels fop->df_reg[3] = sc->sc_er2;
894fd8888adSkarels break;
8951a9c5c6aSkarels }
896fd8888adSkarels
8971a9c5c6aSkarels default:
8981a9c5c6aSkarels error = ENOTTY;
8991a9c5c6aSkarels break;
9001a9c5c6aSkarels }
901af4a276bSkarels return (error);
9021a9c5c6aSkarels }
9031a9c5c6aSkarels
9041a9c5c6aSkarels hpformat(bp)
9051a9c5c6aSkarels struct buf *bp;
9061a9c5c6aSkarels {
9071a9c5c6aSkarels bp->b_flags |= B_FORMAT;
908ccef8083Sbostic hpstrategy(bp);
9091a9c5c6aSkarels }
9101a9c5c6aSkarels
hpecc(mi,flag)9111a9c5c6aSkarels hpecc(mi, flag)
9121a9c5c6aSkarels register struct mba_device *mi;
9131a9c5c6aSkarels int flag;
9141a9c5c6aSkarels {
9151a9c5c6aSkarels register struct mba_regs *mbp = mi->mi_mba;
9161a9c5c6aSkarels register struct hpdevice *rp = (struct hpdevice *)mi->mi_drv;
9171a9c5c6aSkarels register struct buf *bp = mi->mi_tab.b_actf;
9181a9c5c6aSkarels register struct disklabel *lp = &hplabel[mi->mi_unit];
9191a9c5c6aSkarels struct hpsoftc *sc = &hpsoftc[mi->mi_unit];
9201a9c5c6aSkarels int npf, o;
9211a9c5c6aSkarels int bn, cn, tn, sn;
9221a9c5c6aSkarels int bcr;
9231a9c5c6aSkarels
9241a9c5c6aSkarels bcr = MASKREG(-mbp->mba_bcr);
9251a9c5c6aSkarels if (bp->b_flags & B_BAD)
9261a9c5c6aSkarels npf = bp->b_error;
9271a9c5c6aSkarels else {
9281a9c5c6aSkarels npf = bp->b_bcount - bcr;
9291a9c5c6aSkarels /*
9301a9c5c6aSkarels * Watch out for fractional sector at end of transfer;
9311a9c5c6aSkarels * want to round up if finished, otherwise round down.
9321a9c5c6aSkarels */
9331a9c5c6aSkarels if (bcr == 0)
9341a9c5c6aSkarels npf += 511;
9351a9c5c6aSkarels npf = btodb(npf);
9361a9c5c6aSkarels }
9371a9c5c6aSkarels o = (int)bp->b_un.b_addr & PGOFSET;
9381a9c5c6aSkarels bn = bp->b_blkno;
9391a9c5c6aSkarels cn = bp->b_cylin;
9401a9c5c6aSkarels sn = bn % lp->d_secpercyl + npf;
9411a9c5c6aSkarels tn = sn / lp->d_nsectors;
9421a9c5c6aSkarels sn %= lp->d_nsectors;
9431a9c5c6aSkarels cn += tn / lp->d_ntracks;
9441a9c5c6aSkarels tn %= lp->d_ntracks;
9451a9c5c6aSkarels bn += npf;
9461a9c5c6aSkarels switch (flag) {
9471a9c5c6aSkarels case ECC: {
9481a9c5c6aSkarels register int i;
9491a9c5c6aSkarels caddr_t addr;
9501a9c5c6aSkarels struct pte mpte;
9511a9c5c6aSkarels int bit, byte, mask;
9521a9c5c6aSkarels
9531a9c5c6aSkarels npf--; /* because block in error is previous block */
954ca7ebfb4Skarels diskerr(bp, "hp", "soft ecc", LOG_WARNING, npf, lp);
9551a9c5c6aSkarels if (bp->b_flags & B_BAD)
956ca7ebfb4Skarels addlog(" (on replacement sector %d)", sc->sc_badbn);
957ca7ebfb4Skarels addlog("\n");
9581a9c5c6aSkarels mask = MASKREG(rp->hpec2);
9591a9c5c6aSkarels i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */
9601a9c5c6aSkarels bit = i&07;
9611a9c5c6aSkarels i = (i&~07)>>3;
9621a9c5c6aSkarels byte = i + o;
9631a9c5c6aSkarels while (i < 512 && (int)dbtob(npf)+i < bp->b_bcount && bit > -11) {
9641a9c5c6aSkarels mpte = mbp->mba_map[npf+btop(byte)];
9651a9c5c6aSkarels addr = ptob(mpte.pg_pfnum) + (byte & PGOFSET);
9661a9c5c6aSkarels putmemc(addr, getmemc(addr)^(mask<<bit));
9671a9c5c6aSkarels byte++;
9681a9c5c6aSkarels i++;
9691a9c5c6aSkarels bit -= 8;
9701a9c5c6aSkarels }
9711a9c5c6aSkarels if (bcr == 0)
9721a9c5c6aSkarels return (0);
9731a9c5c6aSkarels npf++;
9741a9c5c6aSkarels break;
9751a9c5c6aSkarels }
9761a9c5c6aSkarels
9771a9c5c6aSkarels case SSE:
9781a9c5c6aSkarels rp->hpof |= HPOF_SSEI;
9791a9c5c6aSkarels if (bp->b_flags & B_BAD) {
9801a9c5c6aSkarels bn = sc->sc_badbn;
9811a9c5c6aSkarels goto fixregs;
9821a9c5c6aSkarels }
9831a9c5c6aSkarels mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
9841a9c5c6aSkarels break;
9851a9c5c6aSkarels
9861a9c5c6aSkarels case BSE:
9871a9c5c6aSkarels if (sc->sc_state == OPENRAW)
9881a9c5c6aSkarels return (0);
9891a9c5c6aSkarels if (rp->hpof & HPOF_SSEI)
9901a9c5c6aSkarels sn++;
9911a9c5c6aSkarels #ifdef HPBDEBUG
9921a9c5c6aSkarels if (hpbdebug)
9931a9c5c6aSkarels log(LOG_DEBUG, "hpecc, BSE: bn %d cn %d tn %d sn %d\n", bn, cn, tn, sn);
9941a9c5c6aSkarels #endif
9951a9c5c6aSkarels if (bp->b_flags & B_BAD)
9961a9c5c6aSkarels return (0);
9971a9c5c6aSkarels if ((bn = isbad(&hpbad[mi->mi_unit], cn, tn, sn)) < 0)
9981a9c5c6aSkarels return (0);
9991a9c5c6aSkarels bp->b_flags |= B_BAD;
10001a9c5c6aSkarels bp->b_error = npf + 1;
10011a9c5c6aSkarels rp->hpof &= ~HPOF_SSEI;
10021a9c5c6aSkarels bn = lp->d_ncylinders * lp->d_secpercyl -
10031a9c5c6aSkarels lp->d_nsectors - 1 - bn;
10041a9c5c6aSkarels sc->sc_badbn = bn;
10051a9c5c6aSkarels fixregs:
10061a9c5c6aSkarels cn = bn / lp->d_secpercyl;
10071a9c5c6aSkarels sn = bn % lp->d_secpercyl;
10081a9c5c6aSkarels tn = sn / lp->d_nsectors;
10091a9c5c6aSkarels sn %= lp->d_nsectors;
10101a9c5c6aSkarels bcr = bp->b_bcount - (int)ptob(npf);
10111a9c5c6aSkarels bcr = MIN(bcr, 512);
10121a9c5c6aSkarels mbp->mba_bcr = -bcr;
10131a9c5c6aSkarels #ifdef HPBDEBUG
10141a9c5c6aSkarels if (hpbdebug)
10151a9c5c6aSkarels log(LOG_DEBUG, "revector to cn %d tn %d sn %d\n", cn, tn, sn);
10161a9c5c6aSkarels #endif
10171a9c5c6aSkarels break;
10181a9c5c6aSkarels
10191a9c5c6aSkarels case CONT:
10201a9c5c6aSkarels #ifdef HPBDEBUG
10211a9c5c6aSkarels if (hpbdebug)
10221a9c5c6aSkarels log(LOG_DEBUG, "hpecc, CONT: bn %d cn %d tn %d sn %d\n", bn,cn,tn,sn);
10231a9c5c6aSkarels #endif
10241a9c5c6aSkarels bp->b_flags &= ~B_BAD;
10251a9c5c6aSkarels if ((int)ptob(npf) >= bp->b_bcount)
10261a9c5c6aSkarels return (0);
10271a9c5c6aSkarels mbp->mba_bcr = -(bp->b_bcount - (int)ptob(npf));
10281a9c5c6aSkarels break;
10291a9c5c6aSkarels }
10301a9c5c6aSkarels rp->hpcs1 = HP_DCLR|HP_GO;
10311a9c5c6aSkarels if (rp->hpof & HPOF_SSEI)
10321a9c5c6aSkarels sn++;
10331a9c5c6aSkarels rp->hpdc = cn;
10341a9c5c6aSkarels rp->hpda = (tn<<8) + sn;
10351a9c5c6aSkarels mbp->mba_sr = -1;
10361a9c5c6aSkarels mbp->mba_var = (int)ptob(npf) + o;
10371a9c5c6aSkarels rp->hpcs1 = bp->b_flags&B_READ ? HP_RCOM|HP_GO : HP_WCOM|HP_GO;
10381a9c5c6aSkarels mi->mi_tab.b_errcnt = 0; /* error has been corrected */
10391a9c5c6aSkarels sc->sc_blkdone = npf;
10401a9c5c6aSkarels return (1);
10411a9c5c6aSkarels }
10421a9c5c6aSkarels
10431a9c5c6aSkarels #define DBSIZE 20
10441a9c5c6aSkarels
hpdump(dev)10451a9c5c6aSkarels hpdump(dev)
10461a9c5c6aSkarels dev_t dev;
10471a9c5c6aSkarels {
10481a9c5c6aSkarels register struct mba_device *mi;
10491a9c5c6aSkarels register struct mba_regs *mba;
10509abc1b4cSkarels register struct disklabel *lp;
10511a9c5c6aSkarels struct hpdevice *hpaddr;
10521a9c5c6aSkarels char *start;
10531a9c5c6aSkarels int num, unit;
10549abc1b4cSkarels extern int dumpsize;
10551a9c5c6aSkarels
10569abc1b4cSkarels num = dumpsize;
10571a9c5c6aSkarels start = 0;
10581a9c5c6aSkarels unit = hpunit(dev);
10591a9c5c6aSkarels if (unit >= NHP)
10601a9c5c6aSkarels return (ENXIO);
10611a9c5c6aSkarels #define phys(a,b) ((b)((int)(a)&0x7fffffff))
10621a9c5c6aSkarels mi = phys(hpinfo[unit],struct mba_device *);
10631a9c5c6aSkarels if (mi == 0 || mi->mi_alive == 0)
10641a9c5c6aSkarels return (ENXIO);
10651a9c5c6aSkarels lp = &hplabel[unit];
10661a9c5c6aSkarels mba = phys(mi->mi_hd, struct mba_hd *)->mh_physmba;
10671a9c5c6aSkarels mba->mba_cr = MBCR_INIT;
10681a9c5c6aSkarels hpaddr = (struct hpdevice *)&mba->mba_drv[mi->mi_drive];
10691a9c5c6aSkarels if ((hpaddr->hpds & HPDS_VV) == 0) {
10701a9c5c6aSkarels hpaddr->hpcs1 = HP_DCLR|HP_GO;
10711a9c5c6aSkarels hpaddr->hpcs1 = HP_PRESET|HP_GO;
10721a9c5c6aSkarels hpaddr->hpof = HPOF_FMT22;
10731a9c5c6aSkarels }
10741a9c5c6aSkarels if (dumplo + num >= lp->d_partitions[hppart(dev)].p_size)
10751a9c5c6aSkarels num = lp->d_partitions[hppart(dev)].p_size - dumplo;
10761a9c5c6aSkarels while (num > 0) {
10771a9c5c6aSkarels register struct pte *hpte = mba->mba_map;
10781a9c5c6aSkarels register int i;
10791a9c5c6aSkarels int blk, cn, sn, tn;
10801a9c5c6aSkarels daddr_t bn;
10811a9c5c6aSkarels
10821a9c5c6aSkarels blk = num > DBSIZE ? DBSIZE : num;
1083fd8888adSkarels bn = dumplo + btodb(start);
10841a9c5c6aSkarels cn = (bn + lp->d_partitions[hppart(dev)].p_offset) /
10851a9c5c6aSkarels lp->d_secpercyl;
10861a9c5c6aSkarels sn = bn % lp->d_secpercyl;
10871a9c5c6aSkarels tn = sn / lp->d_nsectors;
10881a9c5c6aSkarels sn = sn % lp->d_nsectors;
10891a9c5c6aSkarels hpaddr->hpdc = cn;
10901a9c5c6aSkarels hpaddr->hpda = (tn << 8) + sn;
10911a9c5c6aSkarels for (i = 0; i < blk; i++)
10921a9c5c6aSkarels *(int *)hpte++ = (btop(start)+i) | PG_V;
10931a9c5c6aSkarels mba->mba_sr = -1;
10941a9c5c6aSkarels mba->mba_bcr = -(blk*NBPG);
10951a9c5c6aSkarels mba->mba_var = 0;
10961a9c5c6aSkarels hpaddr->hpcs1 = HP_WCOM | HP_GO;
10971a9c5c6aSkarels while ((hpaddr->hpds & HPDS_DRY) == 0)
10981a9c5c6aSkarels DELAY(10);
10991a9c5c6aSkarels if (hpaddr->hpds&HPDS_ERR)
11001a9c5c6aSkarels return (EIO);
11011a9c5c6aSkarels start += blk*NBPG;
11021a9c5c6aSkarels num -= blk;
11031a9c5c6aSkarels }
11041a9c5c6aSkarels return (0);
11051a9c5c6aSkarels }
11061a9c5c6aSkarels
hpsize(dev)11071a9c5c6aSkarels hpsize(dev)
11081a9c5c6aSkarels dev_t dev;
11091a9c5c6aSkarels {
11101a9c5c6aSkarels register int unit = hpunit(dev);
11111a9c5c6aSkarels struct mba_device *mi;
11121a9c5c6aSkarels
11131a9c5c6aSkarels if (unit >= NHP || (mi = hpinfo[unit]) == 0 || mi->mi_alive == 0 ||
11141a9c5c6aSkarels hpsoftc[unit].sc_state != OPEN)
11151a9c5c6aSkarels return (-1);
11161a9c5c6aSkarels return ((int)hplabel[unit].d_partitions[hppart(dev)].p_size);
11171a9c5c6aSkarels }
11181a9c5c6aSkarels
11191a9c5c6aSkarels #ifdef COMPAT_42
11201a9c5c6aSkarels /*
11211a9c5c6aSkarels * Compatibility code to fake up pack label
11221a9c5c6aSkarels * for unlabeled disks.
11231a9c5c6aSkarels */
11244c29c562Swnj struct size {
1125f87ddd94Sbill daddr_t nblocks;
1126f87ddd94Sbill int cyloff;
1127500079a2Ssam } rp06_sizes[8] = {
1128d0495467Sbill 15884, 0, /* A=cyl 0 thru 37 */
1129d0495467Sbill 33440, 38, /* B=cyl 38 thru 117 */
1130d0495467Sbill 340670, 0, /* C=cyl 0 thru 814 */
1131500079a2Ssam 15884, 118, /* D=cyl 118 thru 155 */
1132500079a2Ssam 55936, 156, /* E=cyl 156 thru 289 */
1133500079a2Ssam 219384, 290, /* F=cyl 290 thru 814 */
1134af4a276bSkarels 291192, 118, /* G=cyl 118 thru 814 */
1135f87ddd94Sbill 0, 0,
1136500079a2Ssam }, rp05_sizes[8] = {
1137500079a2Ssam 15884, 0, /* A=cyl 0 thru 37 */
1138500079a2Ssam 33440, 38, /* B=cyl 38 thru 117 */
1139500079a2Ssam 171798, 0, /* C=cyl 0 thru 410 */
1140500079a2Ssam 15884, 118, /* D=cyl 118 thru 155 */
1141500079a2Ssam 55936, 156, /* E=cyl 156 thru 289 */
1142500079a2Ssam 50512, 290, /* F=cyl 290 thru 410 */
1143500079a2Ssam 122408, 118, /* G=cyl 118 thru 410 */
1144500079a2Ssam 0, 0,
1145500079a2Ssam }, rm03_sizes[8] = {
1146d0495467Sbill 15884, 0, /* A=cyl 0 thru 99 */
1147500079a2Ssam 33440, 100, /* B=cyl 100 thru 308 */
1148d0495467Sbill 131680, 0, /* C=cyl 0 thru 822 */
1149500079a2Ssam 15884, 309, /* D=cyl 309 thru 408 */
1150500079a2Ssam 55936, 409, /* E=cyl 409 thru 758 */
1151500079a2Ssam 10144, 759, /* F=cyl 759 thru 822 */
1152500079a2Ssam 82144, 309, /* G=cyl 309 thru 822 */
1153f87ddd94Sbill 0, 0,
1154500079a2Ssam }, rm05_sizes[8] = {
1155d0495467Sbill 15884, 0, /* A=cyl 0 thru 26 */
1156d0495467Sbill 33440, 27, /* B=cyl 27 thru 81 */
1157359ec2b1Swnj 500384, 0, /* C=cyl 0 thru 822 */
1158d0495467Sbill 15884, 562, /* D=cyl 562 thru 588 */
1159d0495467Sbill 55936, 589, /* E=cyl 589 thru 680 */
1160c17074cbSroot 86240, 681, /* F=cyl 681 thru 822 */
1161c17074cbSroot 158592, 562, /* G=cyl 562 thru 822 */
1162d0495467Sbill 291346, 82, /* H=cyl 82 thru 561 */
11634c29c562Swnj }, rm80_sizes[8] = {
11644c29c562Swnj 15884, 0, /* A=cyl 0 thru 36 */
11654c29c562Swnj 33440, 37, /* B=cyl 37 thru 114 */
11664c29c562Swnj 242606, 0, /* C=cyl 0 thru 558 */
1167500079a2Ssam 15884, 115, /* D=cyl 115 thru 151 */
1168500079a2Ssam 55936, 152, /* E=cyl 152 thru 280 */
1169500079a2Ssam 120559, 281, /* F=cyl 281 thru 558 */
1170500079a2Ssam 192603, 115, /* G=cyl 115 thru 558 */
11714c29c562Swnj 0, 0,
1172500079a2Ssam }, rp07_sizes[8] = {
11739c2d39a9Ssam 15884, 0, /* A=cyl 0 thru 9 */
1174500079a2Ssam 66880, 10, /* B=cyl 10 thru 51 */
11753b895dd6Sroot 1008000, 0, /* C=cyl 0 thru 629 */
1176500079a2Ssam 15884, 235, /* D=cyl 235 thru 244 */
1177500079a2Ssam 307200, 245, /* E=cyl 245 thru 436 */
1178500079a2Ssam 308650, 437, /* F=cyl 437 thru 629 */
1179500079a2Ssam 631850, 235, /* G=cyl 235 thru 629 */
1180500079a2Ssam 291346, 52, /* H=cyl 52 thru 234 */
1181500079a2Ssam }, cdc9775_sizes[8] = {
1182500079a2Ssam 15884, 0, /* A=cyl 0 thru 12 */
1183500079a2Ssam 66880, 13, /* B=cyl 13 thru 65 */
1184c95ef97fSkarels 1077760, 0, /* C=cyl 0 thru 841 */
1185500079a2Ssam 15884, 294, /* D=cyl 294 thru 306 */
1186500079a2Ssam 307200, 307, /* E=cyl 307 thru 546 */
1187c95ef97fSkarels 377440, 547, /* F=cyl 547 thru 841 */
1188c95ef97fSkarels 701280, 294, /* G=cyl 294 thru 841 */
1189500079a2Ssam 291346, 66, /* H=cyl 66 thru 293 */
1190500079a2Ssam }, cdc9730_sizes[8] = {
11919c2d39a9Ssam 15884, 0, /* A=cyl 0 thru 49 */
11929c2d39a9Ssam 33440, 50, /* B=cyl 50 thru 154 */
11939c2d39a9Ssam 263360, 0, /* C=cyl 0 thru 822 */
1194500079a2Ssam 15884, 155, /* D=cyl 155 thru 204 */
1195500079a2Ssam 55936, 205, /* E=cyl 205 thru 379 */
1196500079a2Ssam 141664, 380, /* F=cyl 380 thru 822 */
1197500079a2Ssam 213664, 155, /* G=cyl 155 thru 822 */
11989c2d39a9Ssam 0, 0,
1199500079a2Ssam }, capricorn_sizes[8] = {
12009c2d39a9Ssam 15884, 0, /* A=cyl 0 thru 31 */
12019c2d39a9Ssam 33440, 32, /* B=cyl 32 thru 97 */
12029c2d39a9Ssam 524288, 0, /* C=cyl 0 thru 1023 */
1203500079a2Ssam 15884, 668, /* D=cyl 668 thru 699 */
1204500079a2Ssam 55936, 700, /* E=cyl 700 thru 809 */
1205500079a2Ssam 109472, 810, /* F=cyl 810 thru 1023 */
1206500079a2Ssam 182176, 668, /* G=cyl 668 thru 1023 */
12079c2d39a9Ssam 291346, 98, /* H=cyl 98 thru 667 */
1208500079a2Ssam }, eagle_sizes[8] = {
1209500079a2Ssam 15884, 0, /* A=cyl 0 thru 16 */
1210500079a2Ssam 66880, 17, /* B=cyl 17 thru 86 */
121110def8aaSsam 808320, 0, /* C=cyl 0 thru 841 */
1212500079a2Ssam 15884, 391, /* D=cyl 391 thru 407 */
1213500079a2Ssam 307200, 408, /* E=cyl 408 thru 727 */
121410def8aaSsam 109296, 728, /* F=cyl 728 thru 841 */
121510def8aaSsam 432816, 391, /* G=cyl 391 thru 841 */
1216500079a2Ssam 291346, 87, /* H=cyl 87 thru 390 */
1217089250f0Sroot }, ampex_sizes[8] = {
1218965098efSsam 15884, 0, /* A=cyl 0 thru 26 */
1219965098efSsam 33440, 27, /* B=cyl 27 thru 81 */
1220e87193ddShelge 495520, 0, /* C=cyl 0 thru 814 */
1221965098efSsam 15884, 562, /* D=cyl 562 thru 588 */
1222965098efSsam 55936, 589, /* E=cyl 589 thru 680 */
1223e87193ddShelge 81312, 681, /* F=cyl 681 thru 814 */
1224e87193ddShelge 153664, 562, /* G=cyl 562 thru 814 */
1225965098efSsam 291346, 82, /* H=cyl 82 thru 561 */
1226457ffefbSkarels }, fj2361_sizes[8] = {
1227457ffefbSkarels 15884, 0, /* A=cyl 0 thru 12 */
1228457ffefbSkarels 66880, 13, /* B=cyl 13 thru 65 */
1229457ffefbSkarels 1077760, 0, /* C=cyl 0 thru 841 */
1230457ffefbSkarels 15884, 294, /* D=cyl 294 thru 306 */
1231457ffefbSkarels 307200, 307, /* E=cyl 307 thru 546 */
1232457ffefbSkarels 377408, 547, /* F=cyl 547 thru 841 */
1233457ffefbSkarels 701248, 294, /* G=cyl 294 thru 841 */
1234457ffefbSkarels 291346, 66, /* H=cyl 66 thru 293 */
12352745f7c8Sbostic }, fj2361a_sizes[8] = {
12362745f7c8Sbostic 15884, 0, /* A=cyl 0 thru 11 */
12372745f7c8Sbostic 66880, 12, /* B=cyl 12 thru 61 */
12382745f7c8Sbostic 1145120, 0, /* C=cyl 0 thru 841 */
12392745f7c8Sbostic 15884, 277, /* D=cyl 277 thru 288 */
12402745f7c8Sbostic 307200, 289, /* E=cyl 289 thru 514 */
12412745f7c8Sbostic 444516, 515, /* F=cyl 515 thru 841 */
12422745f7c8Sbostic 768196, 277, /* G=cyl 277 thru 841 */
12432745f7c8Sbostic 291346, 62, /* H=cyl 62 thru 276 */
12444c29c562Swnj };
12454c29c562Swnj
1246a5048495Ssam /*
12470bd1f874Skarels * These variable are all measured in sectors.
12480bd1f874Skarels * Sdist is how much to "lead" in the search for a desired sector
12490bd1f874Skarels * (i.e. if want N, search for N-sdist.)
12500bd1f874Skarels * Maxdist and mindist define the region right before our desired sector within
12510bd1f874Skarels * which we don't bother searching. We don't search when we are already less
12520bd1f874Skarels * then maxdist and more than mindist sectors "before" our desired sector.
12530bd1f874Skarels * Maxdist should be >= sdist.
12540bd1f874Skarels *
12550bd1f874Skarels * Beware, sdist, mindist and maxdist are not well tuned
1256a5048495Ssam * for many of the drives listed in this table.
1257a5048495Ssam * Try patching things with something i/o intensive
1258a5048495Ssam * running and watch iostat.
12594fcad5b5Skarels *
12604fcad5b5Skarels * The order of these entries must agree with the indices in hptypes[].
1261a5048495Ssam */
12624c29c562Swnj struct hpst {
1263a5048495Ssam short nsect; /* # sectors/track */
1264a5048495Ssam short ntrak; /* # tracks/cylinder */
1265a5048495Ssam short nspc; /* # sector/cylinders */
1266a5048495Ssam short ncyl; /* # cylinders */
1267a5048495Ssam struct size *sizes; /* partition tables */
1268a5048495Ssam short sdist; /* seek distance metric */
12690bd1f874Skarels short maxdist; /* boundaries of non-searched area */
12700bd1f874Skarels short mindist; /* preceding the target sector */
1271457ffefbSkarels char *name; /* name of disk type */
12724c29c562Swnj } hpst[] = {
1273457ffefbSkarels { 32, 5, 32*5, 823, rm03_sizes, 7, 4, 1, "RM03" },
1274457ffefbSkarels { 32, 19, 32*19, 823, rm05_sizes, 7, 4, 1, "RM05" },
1275457ffefbSkarels { 22,19, 22*19, 815, rp06_sizes, 7, 4, 1, "RP06"},
1276457ffefbSkarels { 31, 14, 31*14, 559, rm80_sizes, 7, 4, 1, "RM80"},
1277457ffefbSkarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP04"},
1278457ffefbSkarels { 22, 19, 22*19, 411, rp05_sizes, 7, 4, 1, "RP05"},
1279457ffefbSkarels { 50, 32, 50*32, 630, rp07_sizes, 15, 8, 3, "RP07"},
1280457ffefbSkarels { 1, 1, 1, 1, 0, 0, 0, 0, "ML11A"},
1281457ffefbSkarels { 1, 1, 1, 1, 0, 0, 0, 0, "ML11B" },
1282457ffefbSkarels { 32, 40, 32*40, 843, cdc9775_sizes, 7, 4, 1, "9775" },
1283457ffefbSkarels { 32, 10, 32*10, 823, cdc9730_sizes, 7, 4, 1, "9730-160" },
1284457ffefbSkarels { 32, 16, 32*16, 1024, capricorn_sizes,10,4, 3, "capricorn" },
1285457ffefbSkarels { 48, 20, 48*20, 842, eagle_sizes, 15, 8, 3, "eagle" },
1286457ffefbSkarels { 32, 19, 32*19, 815, ampex_sizes, 7, 4, 1, "9300" },
1287457ffefbSkarels { 64, 20, 64*20, 842, fj2361_sizes, 15, 8, 3, "2361" },
12882745f7c8Sbostic { 68, 20, 68*20, 842, fj2361a_sizes, 15, 8, 3, "2361a" },
1289f87ddd94Sbill };
1290f87ddd94Sbill
1291e9edd5fbSsam /*
1292e9edd5fbSsam * Map apparent MASSBUS drive type into manufacturer
1293e9edd5fbSsam * specific configuration. For SI controllers this is done
1294e9edd5fbSsam * based on codes in the serial number register. For
1295e9edd5fbSsam * EMULEX controllers, the track and sector attributes are
1296e9edd5fbSsam * used when the drive type is an RM02 (not supported by DEC).
1297e9edd5fbSsam */
hpmaptype(mi,lp)12981a9c5c6aSkarels hpmaptype(mi, lp)
1299e9edd5fbSsam register struct mba_device *mi;
13001a9c5c6aSkarels register struct disklabel *lp;
130135f7ff6dSwnj {
13029c2d39a9Ssam register struct hpdevice *hpaddr = (struct hpdevice *)mi->mi_drv;
1303e9edd5fbSsam register int type = mi->mi_type;
13041a9c5c6aSkarels register struct hpst *st;
13051a9c5c6aSkarels register i;
13069c2d39a9Ssam
13079c2d39a9Ssam /*
1308965098efSsam * Model-byte processing for SI controllers.
13099c2d39a9Ssam * NB: Only deals with RM03 and RM05 emulations.
13109c2d39a9Ssam */
1311e9edd5fbSsam if (type == HPDT_RM03 || type == HPDT_RM05) {
1312e9edd5fbSsam int hpsn = hpaddr->hpsn;
13139c2d39a9Ssam
13141a9c5c6aSkarels if ((hpsn & SIMB_LU) == mi->mi_drive)
13159c2d39a9Ssam switch ((hpsn & SIMB_MB) & ~(SIMB_S6|SIRM03|SIRM05)) {
13169c2d39a9Ssam
13179c2d39a9Ssam case SI9775D:
1318e9edd5fbSsam type = HPDT_9775;
13199c2d39a9Ssam break;
13209c2d39a9Ssam
13219c2d39a9Ssam case SI9730D:
1322e9edd5fbSsam type = HPDT_9730;
13239c2d39a9Ssam break;
13249c2d39a9Ssam
13259c2d39a9Ssam case SI9766:
1326457ffefbSkarels type = HPDT_RM05;
13279c2d39a9Ssam break;
13289c2d39a9Ssam
13299c2d39a9Ssam case SI9762:
1330e9edd5fbSsam type = HPDT_RM03;
13319c2d39a9Ssam break;
1332965098efSsam
1333965098efSsam case SICAPD:
1334965098efSsam type = HPDT_CAPRICORN;
1335965098efSsam break;
1336965098efSsam
1337965098efSsam case SI9751D:
1338965098efSsam type = HPDT_EAGLE;
1339965098efSsam break;
13409c2d39a9Ssam }
1341fc429abdSkarels mi->mi_type = type;
13429c2d39a9Ssam }
13439c2d39a9Ssam
13449c2d39a9Ssam /*
1345e9edd5fbSsam * EMULEX SC750 or SC780. Poke the holding register.
13469c2d39a9Ssam */
1347e9edd5fbSsam if (type == HPDT_RM02) {
1348457ffefbSkarels int nsectors, ntracks, ncyl;
1349e9edd5fbSsam
135071008204Ssam hpaddr->hpof = HPOF_FMT22;
135171008204Ssam mbclrattn(mi);
13529c2d39a9Ssam hpaddr->hpcs1 = HP_NOP;
13539c2d39a9Ssam hpaddr->hphr = HPHR_MAXTRAK;
135489958e60Ssam ntracks = MASKREG(hpaddr->hphr) + 1;
1355457ffefbSkarels DELAY(100);
1356e9edd5fbSsam hpaddr->hpcs1 = HP_NOP;
1357e9edd5fbSsam hpaddr->hphr = HPHR_MAXSECT;
135889958e60Ssam nsectors = MASKREG(hpaddr->hphr) + 1;
1359457ffefbSkarels DELAY(100);
1360457ffefbSkarels hpaddr->hpcs1 = HP_NOP;
1361457ffefbSkarels hpaddr->hphr = HPHR_MAXCYL;
1362457ffefbSkarels ncyl = MASKREG(hpaddr->hphr) + 1;
1363457ffefbSkarels for (type = 0; hptypes[type] != 0; type++)
1364457ffefbSkarels if (hpst[type].nsect == nsectors &&
1365457ffefbSkarels hpst[type].ntrak == ntracks &&
1366457ffefbSkarels hpst[type].ncyl == ncyl)
1367457ffefbSkarels break;
1368457ffefbSkarels
1369fd8888adSkarels hpaddr->hpcs1 = HP_DCLR|HP_GO;
1370fd8888adSkarels mbclrattn(mi); /* conservative */
1371457ffefbSkarels if (hptypes[type] == 0) {
1372457ffefbSkarels printf("hp%d: %d sectors, %d tracks, %d cylinders: unknown device\n",
1373457ffefbSkarels mi->mi_unit, nsectors, ntracks, ncyl);
1374fd8888adSkarels lp->d_nsectors = nsectors;
1375fd8888adSkarels lp->d_ntracks = ntracks;
1376fd8888adSkarels lp->d_ncylinders = ncyl;
1377fd8888adSkarels lp->d_secpercyl = nsectors*ntracks;
1378fd8888adSkarels lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
13794fcad5b5Skarels #ifdef notdef /* set elsewhere */
1380fd8888adSkarels lp->d_npartitions = 1;
1381fd8888adSkarels lp->d_partitions[0].p_offset = 0;
13824fcad5b5Skarels #endif
1383fd8888adSkarels lp->d_partitions[0].p_size = lp->d_secperunit;
1384fd8888adSkarels return (0);
1385e9edd5fbSsam }
1386fc429abdSkarels mi->mi_type = type;
1387e9edd5fbSsam }
13889c2d39a9Ssam
1389e9edd5fbSsam /*
13901a9c5c6aSkarels * set up minimal disk label.
1391e9edd5fbSsam */
13921a9c5c6aSkarels st = &hpst[type];
13931a9c5c6aSkarels lp->d_nsectors = st->nsect;
13941a9c5c6aSkarels lp->d_ntracks = st->ntrak;
13951a9c5c6aSkarels lp->d_secpercyl = st->nspc;
13961a9c5c6aSkarels lp->d_ncylinders = st->ncyl;
13971a9c5c6aSkarels lp->d_secperunit = st->nspc * st->ncyl;
13981a9c5c6aSkarels lp->d_sdist = st->sdist;
13991a9c5c6aSkarels lp->d_mindist = st->mindist;
14001a9c5c6aSkarels lp->d_maxdist = st->maxdist;
14011a9c5c6aSkarels bcopy(hpst[type].name, lp->d_typename, sizeof(lp->d_typename));
14021a9c5c6aSkarels lp->d_npartitions = 8;
14031a9c5c6aSkarels for (i = 0; i < 8; i++) {
14041a9c5c6aSkarels lp->d_partitions[i].p_offset = st->sizes[i].cyloff *
14051a9c5c6aSkarels lp->d_secpercyl;
14061a9c5c6aSkarels lp->d_partitions[i].p_size = st->sizes[i].nblocks;
14079c2d39a9Ssam }
1408fc429abdSkarels return (1);
14097fe1b41dSroot }
14101a9c5c6aSkarels #endif COMPAT_42
14117d993dedSbill #endif
1412