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