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