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