ed_mca.c revision 1.65 1 /* $NetBSD: ed_mca.c,v 1.65 2016/07/11 11:31:51 msaitoh Exp $ */
2
3 /*
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jaromir Dolecek.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Disk drive goo for MCA ESDI controller driver.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: ed_mca.c,v 1.65 2016/07/11 11:31:51 msaitoh Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/conf.h>
43 #include <sys/file.h>
44 #include <sys/stat.h>
45 #include <sys/ioctl.h>
46 #include <sys/buf.h>
47 #include <sys/bufq.h>
48 #include <sys/uio.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <sys/disklabel.h>
52 #include <sys/disk.h>
53 #include <sys/syslog.h>
54 #include <sys/proc.h>
55 #include <sys/vnode.h>
56 #include <sys/rndsource.h>
57
58 #include <sys/intr.h>
59 #include <sys/bus.h>
60
61 #include <dev/mca/mcavar.h>
62
63 #include <dev/mca/edcreg.h>
64 #include <dev/mca/edvar.h>
65 #include <dev/mca/edcvar.h>
66
67 /* #define ATADEBUG */
68
69 #ifdef ATADEBUG
70 #define ATADEBUG_PRINT(args, level) printf args
71 #else
72 #define ATADEBUG_PRINT(args, level)
73 #endif
74
75 #define EDLABELDEV(dev) (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
76
77 static int ed_mca_probe (device_t, cfdata_t, void *);
78 static void ed_mca_attach (device_t, device_t, void *);
79
80 CFATTACH_DECL_NEW(ed_mca, sizeof(struct ed_softc),
81 ed_mca_probe, ed_mca_attach, NULL, NULL);
82
83 extern struct cfdriver ed_cd;
84
85 static int ed_get_params(struct ed_softc *, int *);
86 static void edgetdisklabel(dev_t, struct ed_softc *);
87 static void edgetdefaultlabel(struct ed_softc *, struct disklabel *);
88
89 dev_type_open(edmcaopen);
90 dev_type_close(edmcaclose);
91 dev_type_read(edmcaread);
92 dev_type_write(edmcawrite);
93 dev_type_ioctl(edmcaioctl);
94 dev_type_strategy(edmcastrategy);
95 dev_type_dump(edmcadump);
96 dev_type_size(edmcasize);
97
98 const struct bdevsw ed_bdevsw = {
99 .d_open = edmcaopen,
100 .d_close = edmcaclose,
101 .d_strategy = edmcastrategy,
102 .d_ioctl = edmcaioctl,
103 .d_dump = edmcadump,
104 .d_psize = edmcasize,
105 .d_discard = nodiscard,
106 .d_flag = D_DISK
107 };
108
109 const struct cdevsw ed_cdevsw = {
110 .d_open = edmcaopen,
111 .d_close = edmcaclose,
112 .d_read = edmcaread,
113 .d_write = edmcawrite,
114 .d_ioctl = edmcaioctl,
115 .d_stop = nostop,
116 .d_tty = notty,
117 .d_poll = nopoll,
118 .d_mmap = nommap,
119 .d_kqfilter = nokqfilter,
120 .d_discard = nodiscard,
121 .d_flag = D_DISK
122 };
123
124 static struct dkdriver eddkdriver = {
125 .d_strategy = edmcastrategy,
126 .d_minphys = minphys
127 };
128
129 /*
130 * Just check if it's possible to identify the disk.
131 */
132 static int
133 ed_mca_probe(device_t parent, cfdata_t cf, void *aux)
134 {
135 struct edc_mca_softc *sc = device_private(parent);
136 struct ed_attach_args *eda = aux;
137 u_int16_t cmd_args[2];
138 int found = 1;
139
140 /*
141 * Get Device Configuration (09).
142 */
143 cmd_args[0] = 14; /* Options: 00s110, s: 0=Physical 1=Pseudo */
144 cmd_args[1] = 0;
145 if (edc_run_cmd(sc, CMD_GET_DEV_CONF, eda->edc_drive, cmd_args, 2, 1))
146 found = 0;
147
148 return (found);
149 }
150
151 static void
152 ed_mca_attach(device_t parent, device_t self, void *aux)
153 {
154 struct ed_softc *ed = device_private(self);
155 struct edc_mca_softc *sc = device_private(parent);
156 struct ed_attach_args *eda = aux;
157 char pbuf[8];
158 int drv_flags;
159
160 ed->sc_dev = self;
161 ed->edc_softc = sc;
162 ed->sc_devno = eda->edc_drive;
163 edc_add_disk(sc, ed);
164
165 bufq_alloc(&ed->sc_q, "disksort", BUFQ_SORT_RAWBLOCK);
166 mutex_init(&ed->sc_q_lock, MUTEX_DEFAULT, IPL_VM);
167
168 if (ed_get_params(ed, &drv_flags)) {
169 printf(": IDENTIFY failed, no disk found\n");
170 return;
171 }
172
173 format_bytes(pbuf, sizeof(pbuf),
174 (u_int64_t) ed->sc_capacity * DEV_BSIZE);
175 printf(": %s, %u cyl, %u head, %u sec, 512 bytes/sect x %u sectors\n",
176 pbuf,
177 ed->cyl, ed->heads, ed->sectors,
178 ed->sc_capacity);
179
180 printf("%s: %u spares/cyl, %s, %s, %s, %s, %s\n",
181 device_xname(ed->sc_dev), ed->spares,
182 (drv_flags & (1 << 0)) ? "NoRetries" : "Retries",
183 (drv_flags & (1 << 1)) ? "Removable" : "Fixed",
184 (drv_flags & (1 << 2)) ? "SkewedFormat" : "NoSkew",
185 (drv_flags & (1 << 3)) ? "ZeroDefect" : "Defects",
186 (drv_flags & (1 << 4)) ? "InvalidSecondary" : "SecondaryOK"
187 );
188
189 /*
190 * Initialize and attach the disk structure.
191 */
192 disk_init(&ed->sc_dk, device_xname(ed->sc_dev), &eddkdriver);
193 disk_attach(&ed->sc_dk);
194 rnd_attach_source(&ed->rnd_source, device_xname(ed->sc_dev),
195 RND_TYPE_DISK, RND_FLAG_DEFAULT);
196
197 ed->sc_flags |= EDF_INIT;
198
199 /*
200 * XXX We should try to discovery wedges here, but
201 * XXX that would mean being able to do I/O. Should
202 * XXX use config_defer() here.
203 */
204 }
205
206 /*
207 * Read/write routine for a buffer. Validates the arguments and schedules the
208 * transfer. Does not wait for the transfer to complete.
209 */
210 void
211 edmcastrategy(struct buf *bp)
212 {
213 struct ed_softc *ed;
214 struct disklabel *lp;
215 daddr_t blkno;
216
217 ed = device_lookup_private(&ed_cd, DISKUNIT(bp->b_dev));
218 lp = ed->sc_dk.dk_label;
219
220 ATADEBUG_PRINT(("edmcastrategy (%s)\n", device_xname(ed->sc_dev)),
221 DEBUG_XFERS);
222
223 /* Valid request? */
224 if (bp->b_blkno < 0 ||
225 (bp->b_bcount % lp->d_secsize) != 0 ||
226 (bp->b_bcount / lp->d_secsize) >= (1 << NBBY)) {
227 bp->b_error = EINVAL;
228 goto done;
229 }
230
231 /* If device invalidated (e.g. media change, door open), error. */
232 if ((ed->sc_flags & WDF_LOADED) == 0) {
233 bp->b_error = EIO;
234 goto done;
235 }
236
237 /* If it's a null transfer, return immediately. */
238 if (bp->b_bcount == 0)
239 goto done;
240
241 /*
242 * Do bounds checking, adjust transfer. if error, process.
243 * If end of partition, just return.
244 */
245 if (DISKPART(bp->b_dev) != RAW_PART &&
246 bounds_check_with_label(&ed->sc_dk, bp,
247 (ed->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
248 goto done;
249
250 /*
251 * Now convert the block number to absolute and put it in
252 * terms of the device's logical block size.
253 */
254 if (lp->d_secsize >= DEV_BSIZE)
255 blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
256 else
257 blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
258
259 if (DISKPART(bp->b_dev) != RAW_PART)
260 blkno += lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
261
262 bp->b_rawblkno = blkno;
263
264 /* Queue transfer on drive, activate drive and controller if idle. */
265 mutex_enter(&ed->sc_q_lock);
266 bufq_put(ed->sc_q, bp);
267 mutex_exit(&ed->sc_q_lock);
268
269 /* Ring the worker thread */
270 wakeup(ed->edc_softc);
271
272 return;
273 done:
274 /* Toss transfer; we're done early. */
275 bp->b_resid = bp->b_bcount;
276 biodone(bp);
277 }
278
279 int
280 edmcaread(dev_t dev, struct uio *uio, int flags)
281 {
282 ATADEBUG_PRINT(("edread\n"), DEBUG_XFERS);
283 return (physio(edmcastrategy, NULL, dev, B_READ, minphys, uio));
284 }
285
286 int
287 edmcawrite(dev_t dev, struct uio *uio, int flags)
288 {
289 ATADEBUG_PRINT(("edwrite\n"), DEBUG_XFERS);
290 return (physio(edmcastrategy, NULL, dev, B_WRITE, minphys, uio));
291 }
292
293 int
294 edmcaopen(dev_t dev, int flag, int fmt, struct lwp *l)
295 {
296 struct ed_softc *wd;
297 int part, error;
298
299 ATADEBUG_PRINT(("edopen\n"), DEBUG_FUNCS);
300 wd = device_lookup_private(&ed_cd, DISKUNIT(dev));
301 if (wd == NULL || (wd->sc_flags & EDF_INIT) == 0)
302 return (ENXIO);
303
304 part = DISKPART(dev);
305
306 mutex_enter(&wd->sc_dk.dk_openlock);
307
308 /*
309 * If there are wedges, and this is not RAW_PART, then we
310 * need to fail.
311 */
312 if (wd->sc_dk.dk_nwedges != 0 && part != RAW_PART) {
313 error = EBUSY;
314 goto bad1;
315 }
316
317 if (wd->sc_dk.dk_openmask != 0) {
318 /*
319 * If any partition is open, but the disk has been invalidated,
320 * disallow further opens.
321 */
322 if ((wd->sc_flags & WDF_LOADED) == 0) {
323 error = EIO;
324 goto bad1;
325 }
326 } else {
327 if ((wd->sc_flags & WDF_LOADED) == 0) {
328 int s;
329
330 wd->sc_flags |= WDF_LOADED;
331
332 /* Load the physical device parameters. */
333 s = splbio();
334 ed_get_params(wd, NULL);
335 splx(s);
336
337 /* Load the partition info if not already loaded. */
338 edgetdisklabel(dev, wd);
339 }
340 }
341
342 /* Check that the partition exists. */
343 if (part != RAW_PART &&
344 (part >= wd->sc_dk.dk_label->d_npartitions ||
345 wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
346 error = ENXIO;
347 goto bad1;
348 }
349
350 /* Insure only one open at a time. */
351 switch (fmt) {
352 case S_IFCHR:
353 wd->sc_dk.dk_copenmask |= (1 << part);
354 break;
355 case S_IFBLK:
356 wd->sc_dk.dk_bopenmask |= (1 << part);
357 break;
358 }
359 wd->sc_dk.dk_openmask =
360 wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
361
362 error = 0;
363 bad1:
364 mutex_exit(&wd->sc_dk.dk_openlock);
365 return (error);
366 }
367
368 int
369 edmcaclose(dev_t dev, int flag, int fmt, struct lwp *l)
370 {
371 struct ed_softc *wd = device_lookup_private(&ed_cd, DISKUNIT(dev));
372 int part = DISKPART(dev);
373
374 ATADEBUG_PRINT(("edmcaclose\n"), DEBUG_FUNCS);
375
376 mutex_enter(&wd->sc_dk.dk_openlock);
377
378 switch (fmt) {
379 case S_IFCHR:
380 wd->sc_dk.dk_copenmask &= ~(1 << part);
381 break;
382 case S_IFBLK:
383 wd->sc_dk.dk_bopenmask &= ~(1 << part);
384 break;
385 }
386 wd->sc_dk.dk_openmask =
387 wd->sc_dk.dk_copenmask | wd->sc_dk.dk_bopenmask;
388
389 if (wd->sc_dk.dk_openmask == 0) {
390 #if 0
391 wd_flushcache(wd, AT_WAIT);
392 #endif
393 /* XXXX Must wait for I/O to complete! */
394
395 if (! (wd->sc_flags & WDF_KLABEL))
396 wd->sc_flags &= ~WDF_LOADED;
397 }
398
399 mutex_exit(&wd->sc_dk.dk_openlock);
400
401 return 0;
402 }
403
404 static void
405 edgetdefaultlabel(struct ed_softc *ed, struct disklabel *lp)
406 {
407 ATADEBUG_PRINT(("edgetdefaultlabel\n"), DEBUG_FUNCS);
408 memset(lp, 0, sizeof(struct disklabel));
409
410 lp->d_secsize = DEV_BSIZE;
411 lp->d_ntracks = ed->heads;
412 lp->d_nsectors = ed->sectors;
413 lp->d_ncylinders = ed->cyl;
414 lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
415
416 lp->d_type = DKTYPE_ESDI;
417
418 strncpy(lp->d_typename, "ESDI", 16);
419 strncpy(lp->d_packname, "fictitious", 16);
420 lp->d_secperunit = ed->sc_capacity;
421 lp->d_rpm = 3600;
422 lp->d_interleave = 1;
423 lp->d_flags = 0;
424
425 lp->d_partitions[RAW_PART].p_offset = 0;
426 lp->d_partitions[RAW_PART].p_size =
427 lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
428 lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
429 lp->d_npartitions = RAW_PART + 1;
430
431 lp->d_magic = DISKMAGIC;
432 lp->d_magic2 = DISKMAGIC;
433 lp->d_checksum = dkcksum(lp);
434 }
435
436 /*
437 * Fabricate a default disk label, and try to read the correct one.
438 */
439 static void
440 edgetdisklabel(dev_t dev, struct ed_softc *ed)
441 {
442 struct disklabel *lp = ed->sc_dk.dk_label;
443 const char *errstring;
444
445 ATADEBUG_PRINT(("edgetdisklabel\n"), DEBUG_FUNCS);
446
447 memset(ed->sc_dk.dk_cpulabel, 0, sizeof(struct cpu_disklabel));
448
449 edgetdefaultlabel(ed, lp);
450
451 errstring = readdisklabel(
452 EDLABELDEV(dev), edmcastrategy, lp, ed->sc_dk.dk_cpulabel);
453 if (errstring) {
454 /*
455 * This probably happened because the drive's default
456 * geometry doesn't match the DOS geometry. We
457 * assume the DOS geometry is now in the label and try
458 * again. XXX This is a kluge.
459 */
460 #if 0
461 if (wd->drvp->state > RECAL)
462 wd->drvp->drive_flags |= ATA_DRIVE_RESET;
463 #endif
464 errstring = readdisklabel(EDLABELDEV(dev),
465 edmcastrategy, lp, ed->sc_dk.dk_cpulabel);
466 }
467 if (errstring) {
468 printf("%s: %s\n", device_xname(ed->sc_dev), errstring);
469 return;
470 }
471 }
472
473 int
474 edmcaioctl(dev_t dev, u_long xfer, void *addr, int flag, struct lwp *l)
475 {
476 struct ed_softc *ed = device_lookup_private(&ed_cd, DISKUNIT(dev));
477 int error;
478
479 ATADEBUG_PRINT(("edioctl\n"), DEBUG_FUNCS);
480
481 if ((ed->sc_flags & WDF_LOADED) == 0)
482 return EIO;
483
484 error = disk_ioctl(&ed->sc_dk, dev, xfer, addr, flag, l);
485 if (error != EPASSTHROUGH)
486 return error;
487
488 switch (xfer) {
489 case DIOCWDINFO:
490 case DIOCSDINFO:
491 {
492 struct disklabel *lp;
493
494 lp = (struct disklabel *)addr;
495
496 if ((flag & FWRITE) == 0)
497 return EBADF;
498
499 mutex_enter(&ed->sc_dk.dk_openlock);
500 ed->sc_flags |= WDF_LABELLING;
501
502 error = setdisklabel(ed->sc_dk.dk_label,
503 lp, /*wd->sc_dk.dk_openmask : */0,
504 ed->sc_dk.dk_cpulabel);
505 if (error == 0) {
506 #if 0
507 if (wd->drvp->state > RECAL)
508 wd->drvp->drive_flags |= ATA_DRIVE_RESET;
509 #endif
510 if (xfer == DIOCWDINFO)
511 error = writedisklabel(EDLABELDEV(dev),
512 edmcastrategy, ed->sc_dk.dk_label,
513 ed->sc_dk.dk_cpulabel);
514 }
515
516 ed->sc_flags &= ~WDF_LABELLING;
517 mutex_exit(&ed->sc_dk.dk_openlock);
518 return (error);
519 }
520
521 case DIOCKLABEL:
522 if (*(int *)addr)
523 ed->sc_flags |= WDF_KLABEL;
524 else
525 ed->sc_flags &= ~WDF_KLABEL;
526 return 0;
527
528 case DIOCWLABEL:
529 if ((flag & FWRITE) == 0)
530 return EBADF;
531 if (*(int *)addr)
532 ed->sc_flags |= WDF_WLABEL;
533 else
534 ed->sc_flags &= ~WDF_WLABEL;
535 return 0;
536
537 case DIOCGDEFLABEL:
538 edgetdefaultlabel(ed, (struct disklabel *)addr);
539 return 0;
540
541 #if 0
542 case DIOCWFORMAT:
543 if ((flag & FWRITE) == 0)
544 return EBADF;
545 {
546 register struct format_op *fop;
547 struct iovec aiov;
548 struct uio auio;
549
550 fop = (struct format_op *)addr;
551 aiov.iov_base = fop->df_buf;
552 aiov.iov_len = fop->df_count;
553 auio.uio_iov = &aiov;
554 auio.uio_iovcnt = 1;
555 auio.uio_resid = fop->df_count;
556 auio.uio_segflg = 0;
557 auio.uio_offset =
558 fop->df_startblk * wd->sc_dk.dk_label->d_secsize;
559 auio.uio_lwp = l;
560 error = physio(wdformat, NULL, dev, B_WRITE, minphys,
561 &auio);
562 fop->df_count -= auio.uio_resid;
563 fop->df_reg[0] = wdc->sc_status;
564 fop->df_reg[1] = wdc->sc_error;
565 return error;
566 }
567 #endif
568
569 default:
570 return ENOTTY;
571 }
572
573 #ifdef DIAGNOSTIC
574 panic("edioctl: impossible");
575 #endif
576 }
577
578 int
579 edmcasize(dev_t dev)
580 {
581 struct ed_softc *wd;
582 int part, omask;
583 int size;
584
585 ATADEBUG_PRINT(("edsize\n"), DEBUG_FUNCS);
586
587 wd = device_lookup_private(&ed_cd, DISKUNIT(dev));
588 if (wd == NULL)
589 return (-1);
590
591 part = DISKPART(dev);
592 omask = wd->sc_dk.dk_openmask & (1 << part);
593
594 if (omask == 0 && edmcaopen(dev, 0, S_IFBLK, NULL) != 0)
595 return (-1);
596 if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
597 size = -1;
598 else
599 size = wd->sc_dk.dk_label->d_partitions[part].p_size *
600 (wd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
601 if (omask == 0 && edmcaclose(dev, 0, S_IFBLK, NULL) != 0)
602 return (-1);
603 return (size);
604 }
605
606 /* #define WD_DUMP_NOT_TRUSTED if you just want to watch */
607 static int eddoingadump = 0;
608 static int eddumprecalibrated = 0;
609 static int eddumpmulti = 1;
610
611 /*
612 * Dump core after a system crash.
613 */
614 int
615 edmcadump(dev_t dev, daddr_t blkno, void *va, size_t size)
616 {
617 struct ed_softc *ed; /* disk unit to do the I/O */
618 struct disklabel *lp; /* disk's disklabel */
619 int part;
620 int nblks; /* total number of sectors left to write */
621 int error;
622
623 /* Check if recursive dump; if so, punt. */
624 if (eddoingadump)
625 return EFAULT;
626 eddoingadump = 1;
627
628 ed = device_lookup_private(&ed_cd, DISKUNIT(dev));
629 if (ed == NULL)
630 return (ENXIO);
631
632 part = DISKPART(dev);
633
634 /* Make sure it was initialized. */
635 if ((ed->sc_flags & EDF_INIT) == 0)
636 return ENXIO;
637
638 /* Convert to disk sectors. Request must be a multiple of size. */
639 lp = ed->sc_dk.dk_label;
640 if ((size % lp->d_secsize) != 0)
641 return EFAULT;
642 nblks = size / lp->d_secsize;
643 blkno = blkno / (lp->d_secsize / DEV_BSIZE);
644
645 /* Check transfer bounds against partition size. */
646 if ((blkno < 0) || ((blkno + nblks) > lp->d_partitions[part].p_size))
647 return EINVAL;
648
649 /* Offset block number to start of partition. */
650 blkno += lp->d_partitions[part].p_offset;
651
652 /* Recalibrate, if first dump transfer. */
653 if (eddumprecalibrated == 0) {
654 eddumprecalibrated = 1;
655 eddumpmulti = 8;
656 #if 0
657 wd->drvp->state = RESET;
658 #endif
659 }
660
661 while (nblks > 0) {
662 error = edc_bio(ed->edc_softc, ed, va, blkno,
663 min(nblks, eddumpmulti) * lp->d_secsize, 0, 1);
664 if (error)
665 return (error);
666
667 /* update block count */
668 nblks -= min(nblks, eddumpmulti);
669 blkno += min(nblks, eddumpmulti);
670 va = (char *)va + min(nblks, eddumpmulti) * lp->d_secsize;
671 }
672
673 eddoingadump = 0;
674 return (0);
675 }
676
677 static int
678 ed_get_params(struct ed_softc *ed, int *drv_flags)
679 {
680 u_int16_t cmd_args[2];
681
682 /*
683 * Get Device Configuration (09).
684 */
685 cmd_args[0] = 14; /* Options: 00s110, s: 0=Physical 1=Pseudo */
686 cmd_args[1] = 0;
687 if (edc_run_cmd(ed->edc_softc, CMD_GET_DEV_CONF, ed->sc_devno,
688 cmd_args, 2, 1))
689 return (1);
690
691 ed->spares = ed->sense_data[1] >> 8;
692 if (drv_flags)
693 *drv_flags = ed->sense_data[1] & 0x1f;
694 ed->rba = ed->sense_data[2] | (ed->sense_data[3] << 16);
695 /* Instead of using:
696 ed->cyl = ed->sense_data[4];
697 ed->heads = ed->sense_data[5] & 0xff;
698 ed->sectors = ed->sense_data[5] >> 8;
699 * we fabricate the numbers from RBA count, so that
700 * number of sectors is 32 and heads 64. This seems
701 * to be necessary for integrated ESDI controller.
702 */
703 ed->sectors = 32;
704 ed->heads = 64;
705 ed->cyl = ed->rba / (ed->heads * ed->sectors);
706 ed->sc_capacity = ed->rba;
707
708 return (0);
709 }
710