sd.c revision 1.151.2.7 1 /* $NetBSD: sd.c,v 1.151.2.7 2000/12/13 18:29:06 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Originally written by Julian Elischer (julian (at) dialix.oz.au)
41 * for TRW Financial Systems for use under the MACH(2.5) operating system.
42 *
43 * TRW Financial Systems, in accordance with their agreement with Carnegie
44 * Mellon University, makes this software available to CMU to distribute
45 * or use in any manner that they see fit as long as this message is kept with
46 * the software. For this reason TFS also grants any other persons or
47 * organisations permission to use or modify this software.
48 *
49 * TFS supplies this software to be publicly redistributed
50 * on the understanding that TFS is not responsible for the correct
51 * functioning of this software in any circumstances.
52 *
53 * Ported to run under 386BSD by Julian Elischer (julian (at) dialix.oz.au) Sept 1992
54 */
55
56 #include "opt_scsi.h"
57 #include "rnd.h"
58
59 #include <sys/types.h>
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/kernel.h>
63 #include <sys/file.h>
64 #include <sys/stat.h>
65 #include <sys/ioctl.h>
66 #include <sys/scsiio.h>
67 #include <sys/buf.h>
68 #include <sys/uio.h>
69 #include <sys/malloc.h>
70 #include <sys/errno.h>
71 #include <sys/device.h>
72 #include <sys/disklabel.h>
73 #include <sys/disk.h>
74 #include <sys/proc.h>
75 #include <sys/conf.h>
76 #include <sys/vnode.h>
77 #if NRND > 0
78 #include <sys/rnd.h>
79 #endif
80
81 #include <dev/scsipi/scsipi_all.h>
82 #include <dev/scsipi/scsi_all.h>
83 #include <dev/scsipi/scsipi_disk.h>
84 #include <dev/scsipi/scsi_disk.h>
85 #include <dev/scsipi/scsiconf.h>
86 #include <dev/scsipi/sdvar.h>
87
88 #include "sd.h" /* NSD_SCSIBUS and NSD_ATAPIBUS come from here */
89
90 #define SDUNIT(dev) DISKUNIT(dev)
91 #define SDPART(dev) DISKPART(dev)
92 #define SDMINOR(unit, part) DISKMINOR(unit, part)
93 #define MAKESDDEV(maj, unit, part) MAKEDISKDEV(maj, unit, part)
94
95 #define SDLABELDEV(dev) (MAKESDDEV(major(dev), SDUNIT(dev), RAW_PART))
96
97 int sdlock __P((struct sd_softc *));
98 void sdunlock __P((struct sd_softc *));
99 void sdminphys __P((struct buf *));
100 void sdgetdefaultlabel __P((struct sd_softc *, struct disklabel *));
101 void sdgetdisklabel __P((struct sd_softc *));
102 void sdstart __P((struct scsipi_periph *));
103 void sddone __P((struct scsipi_xfer *));
104 void sd_shutdown __P((void *));
105 int sd_reassign_blocks __P((struct sd_softc *, u_long));
106 int sd_interpret_sense __P((struct scsipi_xfer *));
107
108 extern struct cfdriver sd_cd;
109
110 struct dkdriver sddkdriver = { sdstrategy };
111
112 const struct scsipi_periphsw sd_switch = {
113 sd_interpret_sense, /* check our error handler first */
114 sdstart, /* have a queue, served by this */
115 NULL, /* have no async handler */
116 sddone, /* deal with stats at interrupt time */
117 };
118
119 /*
120 * Attach routine common to atapi & scsi.
121 */
122 void
123 sdattach(parent, sd, periph, ops)
124 struct device *parent;
125 struct sd_softc *sd;
126 struct scsipi_periph *periph;
127 const struct sd_ops *ops;
128 {
129 int error, result;
130 struct disk_parms *dp = &sd->params;
131 char pbuf[9];
132
133 SC_DEBUG(periph, SCSIPI_DB2, ("sdattach: "));
134
135 BUFQ_INIT(&sd->buf_queue);
136
137 /*
138 * Store information needed to contact our base driver
139 */
140 sd->sc_periph = periph;
141 sd->sc_ops = ops;
142
143 periph->periph_dev = &sd->sc_dev;
144 periph->periph_switch = &sd_switch;
145
146 /*
147 * Increase our openings to the maximum-per-periph
148 * supported by the adapter. This will either be
149 * clamped down or grown by the adapter if necessary.
150 */
151 periph->periph_openings =
152 SCSIPI_CHAN_MAX_PERIPH(periph->periph_channel);
153 periph->periph_flags |= PERIPH_GROW_OPENINGS;
154
155 /*
156 * Initialize and attach the disk structure.
157 */
158 sd->sc_dk.dk_driver = &sddkdriver;
159 sd->sc_dk.dk_name = sd->sc_dev.dv_xname;
160 disk_attach(&sd->sc_dk);
161
162 #ifdef __BROKEN_DK_ESTABLISH
163 dk_establish(&sd->sc_dk, &sd->sc_dev); /* XXX */
164 #endif
165
166 /*
167 * Use the subdriver to request information regarding the drive.
168 */
169 printf("\n");
170
171 error = scsipi_start(periph, SSS_START,
172 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
173 XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_SILENT);
174
175 if (error)
176 result = SDGP_RESULT_OFFLINE;
177 else
178 result = (*sd->sc_ops->sdo_get_parms)(sd, &sd->params,
179 XS_CTL_DISCOVERY);
180 printf("%s: ", sd->sc_dev.dv_xname);
181 switch (result) {
182 case SDGP_RESULT_OK:
183 format_bytes(pbuf, sizeof(pbuf),
184 (u_int64_t)dp->disksize * dp->blksize);
185 printf(
186 "%s, %ld cyl, %ld head, %ld sec, %ld bytes/sect x %ld sectors",
187 pbuf, dp->cyls, dp->heads, dp->sectors, dp->blksize,
188 dp->disksize);
189 break;
190
191 case SDGP_RESULT_OFFLINE:
192 printf("drive offline");
193 break;
194
195 case SDGP_RESULT_UNFORMATTED:
196 printf("unformatted media");
197 break;
198
199 #ifdef DIAGNOSTIC
200 default:
201 panic("sdattach: unknown result from get_parms");
202 break;
203 #endif
204 }
205 printf("\n");
206
207 /*
208 * Establish a shutdown hook so that we can ensure that
209 * our data has actually made it onto the platter at
210 * shutdown time. Note that this relies on the fact
211 * that the shutdown hook code puts us at the head of
212 * the list (thus guaranteeing that our hook runs before
213 * our ancestors').
214 */
215 if ((sd->sc_sdhook =
216 shutdownhook_establish(sd_shutdown, sd)) == NULL)
217 printf("%s: WARNING: unable to establish shutdown hook\n",
218 sd->sc_dev.dv_xname);
219
220 #if NRND > 0
221 /*
222 * attach the device into the random source list
223 */
224 rnd_attach_source(&sd->rnd_source, sd->sc_dev.dv_xname,
225 RND_TYPE_DISK, 0);
226 #endif
227 }
228
229 int
230 sdactivate(self, act)
231 struct device *self;
232 enum devact act;
233 {
234 int rv = 0;
235
236 switch (act) {
237 case DVACT_ACTIVATE:
238 rv = EOPNOTSUPP;
239 break;
240
241 case DVACT_DEACTIVATE:
242 /*
243 * Nothing to do; we key off the device's DVF_ACTIVE.
244 */
245 break;
246 }
247 return (rv);
248 }
249
250 int
251 sddetach(self, flags)
252 struct device *self;
253 int flags;
254 {
255 struct sd_softc *sd = (struct sd_softc *) self;
256 struct buf *bp;
257 int s, bmaj, cmaj, mn;
258
259 /* locate the major number */
260 for (bmaj = 0; bmaj <= nblkdev; bmaj++)
261 if (bdevsw[bmaj].d_open == sdopen)
262 break;
263 for (cmaj = 0; cmaj <= nchrdev; cmaj++)
264 if (cdevsw[cmaj].d_open == sdopen)
265 break;
266
267 s = splbio();
268
269 /* Kill off any queued buffers. */
270 while ((bp = BUFQ_FIRST(&sd->buf_queue)) != NULL) {
271 BUFQ_REMOVE(&sd->buf_queue, bp);
272 bp->b_error = EIO;
273 bp->b_flags |= B_ERROR;
274 bp->b_resid = bp->b_bcount;
275 biodone(bp);
276 }
277
278 /* Kill off any pending commands. */
279 scsipi_kill_pending(sd->sc_periph);
280
281 splx(s);
282
283 /* Nuke the vnodes for any open instances */
284 mn = SDMINOR(self->dv_unit, 0);
285 vdevgone(bmaj, mn, mn + (MAXPARTITIONS - 1), VBLK);
286 vdevgone(cmaj, mn, mn + (MAXPARTITIONS - 1), VCHR);
287
288 /* Detach from the disk list. */
289 disk_detach(&sd->sc_dk);
290
291 /* Get rid of the shutdown hook. */
292 shutdownhook_disestablish(sd->sc_sdhook);
293
294 #if NRND > 0
295 /* Unhook the entropy source. */
296 rnd_detach_source(&sd->rnd_source);
297 #endif
298
299 return (0);
300 }
301
302 /*
303 * Wait interruptibly for an exclusive lock.
304 *
305 * XXX
306 * Several drivers do this; it should be abstracted and made MP-safe.
307 */
308 int
309 sdlock(sd)
310 struct sd_softc *sd;
311 {
312 int error;
313
314 while ((sd->flags & SDF_LOCKED) != 0) {
315 sd->flags |= SDF_WANTED;
316 if ((error = tsleep(sd, PRIBIO | PCATCH, "sdlck", 0)) != 0)
317 return (error);
318 }
319 sd->flags |= SDF_LOCKED;
320 return (0);
321 }
322
323 /*
324 * Unlock and wake up any waiters.
325 */
326 void
327 sdunlock(sd)
328 struct sd_softc *sd;
329 {
330
331 sd->flags &= ~SDF_LOCKED;
332 if ((sd->flags & SDF_WANTED) != 0) {
333 sd->flags &= ~SDF_WANTED;
334 wakeup(sd);
335 }
336 }
337
338 /*
339 * open the device. Make sure the partition info is a up-to-date as can be.
340 */
341 int
342 sdopen(dev, flag, fmt, p)
343 dev_t dev;
344 int flag, fmt;
345 struct proc *p;
346 {
347 struct sd_softc *sd;
348 struct scsipi_periph *periph;
349 struct scsipi_adapter *adapt;
350 int unit, part;
351 int error;
352
353 unit = SDUNIT(dev);
354 if (unit >= sd_cd.cd_ndevs)
355 return (ENXIO);
356 sd = sd_cd.cd_devs[unit];
357 if (sd == NULL)
358 return (ENXIO);
359
360 if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
361 return (ENODEV);
362
363 periph = sd->sc_periph;
364 adapt = periph->periph_channel->chan_adapter;
365 part = SDPART(dev);
366
367 SC_DEBUG(periph, SCSIPI_DB1,
368 ("sdopen: dev=0x%x (unit %d (of %d), partition %d)\n", dev, unit,
369 sd_cd.cd_ndevs, part));
370
371 /*
372 * If this is the first open of this device, add a reference
373 * to the adapter.
374 */
375 if (sd->sc_dk.dk_openmask == 0 &&
376 (error = scsipi_adapter_addref(adapt)) != 0)
377 return (error);
378
379 if ((error = sdlock(sd)) != 0)
380 goto bad4;
381
382 if ((periph->periph_flags & PERIPH_OPEN) != 0) {
383 /*
384 * If any partition is open, but the disk has been invalidated,
385 * disallow further opens of non-raw partition
386 */
387 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0 &&
388 (part != RAW_PART || fmt != S_IFCHR)) {
389 error = EIO;
390 goto bad3;
391 }
392 } else {
393 /* Check that it is still responding and ok. */
394 error = scsipi_test_unit_ready(periph,
395 XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_MEDIA_CHANGE |
396 XS_CTL_IGNORE_NOT_READY);
397 if (error)
398 goto bad3;
399
400 /*
401 * Start the pack spinning if necessary. Always allow the
402 * raw parition to be opened, for raw IOCTLs. Data transfers
403 * will check for SDEV_MEDIA_LOADED.
404 */
405 error = scsipi_start(periph, SSS_START,
406 XS_CTL_IGNORE_ILLEGAL_REQUEST |
407 XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_SILENT);
408 if (error) {
409 if (part != RAW_PART || fmt != S_IFCHR)
410 goto bad3;
411 else
412 goto out;
413 }
414
415 periph->periph_flags |= PERIPH_OPEN;
416
417 /* Lock the pack in. */
418 error = scsipi_prevent(periph, PR_PREVENT,
419 XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_MEDIA_CHANGE);
420 if (error)
421 goto bad;
422
423 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0) {
424 periph->periph_flags |= PERIPH_MEDIA_LOADED;
425
426 /*
427 * Load the physical device parameters.
428 *
429 * Note that if media is present but unformatted,
430 * we allow the open (so that it can be formatted!).
431 * The drive should refuse real I/O, if the media is
432 * unformatted.
433 */
434 if ((*sd->sc_ops->sdo_get_parms)(sd, &sd->params,
435 0) == SDGP_RESULT_OFFLINE) {
436 error = ENXIO;
437 goto bad2;
438 }
439 SC_DEBUG(periph, SCSIPI_DB3, ("Params loaded "));
440
441 /* Load the partition info if not already loaded. */
442 sdgetdisklabel(sd);
443 SC_DEBUG(periph, SCSIPI_DB3, ("Disklabel loaded "));
444 }
445 }
446
447 /* Check that the partition exists. */
448 if (part != RAW_PART &&
449 (part >= sd->sc_dk.dk_label->d_npartitions ||
450 sd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
451 error = ENXIO;
452 goto bad;
453 }
454
455 out: /* Insure only one open at a time. */
456 switch (fmt) {
457 case S_IFCHR:
458 sd->sc_dk.dk_copenmask |= (1 << part);
459 break;
460 case S_IFBLK:
461 sd->sc_dk.dk_bopenmask |= (1 << part);
462 break;
463 }
464 sd->sc_dk.dk_openmask =
465 sd->sc_dk.dk_copenmask | sd->sc_dk.dk_bopenmask;
466
467 SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
468 sdunlock(sd);
469 return (0);
470
471 bad2:
472 periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
473
474 bad:
475 if (sd->sc_dk.dk_openmask == 0) {
476 scsipi_prevent(periph, PR_ALLOW,
477 XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_MEDIA_CHANGE);
478 periph->periph_flags &= ~PERIPH_OPEN;
479 }
480
481 bad3:
482 sdunlock(sd);
483 bad4:
484 if (sd->sc_dk.dk_openmask == 0)
485 scsipi_adapter_delref(adapt);
486 return (error);
487 }
488
489 /*
490 * close the device.. only called if we are the LAST occurence of an open
491 * device. Convenient now but usually a pain.
492 */
493 int
494 sdclose(dev, flag, fmt, p)
495 dev_t dev;
496 int flag, fmt;
497 struct proc *p;
498 {
499 struct sd_softc *sd = sd_cd.cd_devs[SDUNIT(dev)];
500 struct scsipi_periph *periph = sd->sc_periph;
501 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
502 int part = SDPART(dev);
503 int error;
504
505 if ((error = sdlock(sd)) != 0)
506 return (error);
507
508 switch (fmt) {
509 case S_IFCHR:
510 sd->sc_dk.dk_copenmask &= ~(1 << part);
511 break;
512 case S_IFBLK:
513 sd->sc_dk.dk_bopenmask &= ~(1 << part);
514 break;
515 }
516 sd->sc_dk.dk_openmask =
517 sd->sc_dk.dk_copenmask | sd->sc_dk.dk_bopenmask;
518
519 if (sd->sc_dk.dk_openmask == 0) {
520 /*
521 * If the disk cache needs flushing, and the disk supports
522 * it, do it now.
523 */
524 if ((sd->flags & SDF_DIRTY) != 0 &&
525 sd->sc_ops->sdo_flush != NULL) {
526 if ((*sd->sc_ops->sdo_flush)(sd, 0)) {
527 printf("%s: cache synchronization failed\n",
528 sd->sc_dev.dv_xname);
529 sd->flags &= ~SDF_FLUSHING;
530 } else
531 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
532 }
533
534 if (! (periph->periph_flags & PERIPH_KEEP_LABEL))
535 periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
536
537 scsipi_wait_drain(periph);
538
539 scsipi_prevent(periph, PR_ALLOW,
540 XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_NOT_READY);
541 periph->periph_flags &= ~PERIPH_OPEN;
542
543 scsipi_wait_drain(periph);
544
545 scsipi_adapter_delref(adapt);
546 }
547
548 sdunlock(sd);
549 return (0);
550 }
551
552 /*
553 * Actually translate the requested transfer into one the physical driver
554 * can understand. The transfer is described by a buf and will include
555 * only one physical transfer.
556 */
557 void
558 sdstrategy(bp)
559 struct buf *bp;
560 {
561 struct sd_softc *sd = sd_cd.cd_devs[SDUNIT(bp->b_dev)];
562 struct scsipi_periph *periph = sd->sc_periph;
563 struct disklabel *lp;
564 daddr_t blkno;
565 int s;
566 boolean_t sector_aligned;
567
568 SC_DEBUG(sd->sc_periph, SCSIPI_DB2, ("sdstrategy "));
569 SC_DEBUG(sd->sc_periph, SCSIPI_DB1,
570 ("%ld bytes @ blk %d\n", bp->b_bcount, bp->b_blkno));
571 /*
572 * If the device has been made invalid, error out
573 */
574 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0 ||
575 (sd->sc_dev.dv_flags & DVF_ACTIVE) == 0) {
576 if (periph->periph_flags & PERIPH_OPEN)
577 bp->b_error = EIO;
578 else
579 bp->b_error = ENODEV;
580 goto bad;
581 }
582
583 lp = sd->sc_dk.dk_label;
584
585 /*
586 * The transfer must be a whole number of blocks, offset must not be
587 * negative.
588 */
589 if (lp->d_secsize == DEV_BSIZE) {
590 sector_aligned = (bp->b_bcount & (DEV_BSIZE - 1)) == 0;
591 } else {
592 sector_aligned = (bp->b_bcount % lp->d_secsize) == 0;
593 }
594 if (!sector_aligned || bp->b_blkno < 0) {
595 bp->b_error = EINVAL;
596 goto bad;
597 }
598 /*
599 * If it's a null transfer, return immediatly
600 */
601 if (bp->b_bcount == 0)
602 goto done;
603
604 /*
605 * Do bounds checking, adjust transfer. if error, process.
606 * If end of partition, just return.
607 */
608 if (SDPART(bp->b_dev) != RAW_PART &&
609 bounds_check_with_label(bp, lp,
610 (sd->flags & (SDF_WLABEL|SDF_LABELLING)) != 0) <= 0)
611 goto done;
612
613 /*
614 * Now convert the block number to absolute and put it in
615 * terms of the device's logical block size.
616 */
617 if (lp->d_secsize == DEV_BSIZE)
618 blkno = bp->b_blkno;
619 else if (lp->d_secsize > DEV_BSIZE)
620 blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
621 else
622 blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
623
624 if (SDPART(bp->b_dev) != RAW_PART)
625 blkno += lp->d_partitions[SDPART(bp->b_dev)].p_offset;
626
627 bp->b_rawblkno = blkno;
628
629 s = splbio();
630
631 /*
632 * Place it in the queue of disk activities for this disk.
633 *
634 * XXX Only do disksort() if the current operating mode does not
635 * XXX include tagged queueing.
636 */
637 disksort_blkno(&sd->buf_queue, bp);
638
639 /*
640 * Tell the device to get going on the transfer if it's
641 * not doing anything, otherwise just wait for completion
642 */
643 sdstart(sd->sc_periph);
644
645 splx(s);
646 return;
647
648 bad:
649 bp->b_flags |= B_ERROR;
650 done:
651 /*
652 * Correctly set the buf to indicate a completed xfer
653 */
654 bp->b_resid = bp->b_bcount;
655 biodone(bp);
656 }
657
658 /*
659 * sdstart looks to see if there is a buf waiting for the device
660 * and that the device is not already busy. If both are true,
661 * It dequeues the buf and creates a scsi command to perform the
662 * transfer in the buf. The transfer request will call scsipi_done
663 * on completion, which will in turn call this routine again
664 * so that the next queued transfer is performed.
665 * The bufs are queued by the strategy routine (sdstrategy)
666 *
667 * This routine is also called after other non-queued requests
668 * have been made of the scsi driver, to ensure that the queue
669 * continues to be drained.
670 *
671 * must be called at the correct (highish) spl level
672 * sdstart() is called at splbio from sdstrategy and scsipi_done
673 */
674 void
675 sdstart(periph)
676 struct scsipi_periph *periph;
677 {
678 struct sd_softc *sd = (void *)periph->periph_dev;
679 struct disklabel *lp = sd->sc_dk.dk_label;
680 struct buf *bp = 0;
681 struct scsipi_rw_big cmd_big;
682 #if NSD_SCSIBUS > 0
683 struct scsi_rw cmd_small;
684 #endif
685 struct scsipi_generic *cmdp;
686 int nblks, cmdlen, error, flags;
687
688 SC_DEBUG(periph, SCSIPI_DB2, ("sdstart "));
689 /*
690 * Check if the device has room for another command
691 */
692 while (periph->periph_active < periph->periph_openings) {
693 /*
694 * there is excess capacity, but a special waits
695 * It'll need the adapter as soon as we clear out of the
696 * way and let it run (user level wait).
697 */
698 if (periph->periph_flags & PERIPH_WAITING) {
699 periph->periph_flags &= ~PERIPH_WAITING;
700 wakeup((caddr_t)periph);
701 return;
702 }
703
704 /*
705 * See if there is a buf with work for us to do..
706 */
707 if ((bp = BUFQ_FIRST(&sd->buf_queue)) == NULL)
708 return;
709 BUFQ_REMOVE(&sd->buf_queue, bp);
710
711 /*
712 * If the device has become invalid, abort all the
713 * reads and writes until all files have been closed and
714 * re-opened
715 */
716 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0) {
717 bp->b_error = EIO;
718 bp->b_flags |= B_ERROR;
719 bp->b_resid = bp->b_bcount;
720 biodone(bp);
721 continue;
722 }
723
724 /*
725 * We have a buf, now we should make a command.
726 */
727
728 if (lp->d_secsize == DEV_BSIZE)
729 nblks = bp->b_bcount >> DEV_BSHIFT;
730 else
731 nblks = howmany(bp->b_bcount, lp->d_secsize);
732
733 #if NSD_SCSIBUS > 0
734 /*
735 * Fill out the scsi command. If the transfer will
736 * fit in a "small" cdb, use it.
737 */
738 if (((bp->b_rawblkno & 0x1fffff) == bp->b_rawblkno) &&
739 ((nblks & 0xff) == nblks) &&
740 !(periph->periph_quirks & PQUIRK_ONLYBIG) &&
741 scsipi_periph_bustype(periph) == SCSIPI_BUSTYPE_SCSI) {
742 /*
743 * We can fit in a small cdb.
744 */
745 bzero(&cmd_small, sizeof(cmd_small));
746 cmd_small.opcode = (bp->b_flags & B_READ) ?
747 SCSI_READ_COMMAND : SCSI_WRITE_COMMAND;
748 _lto3b(bp->b_rawblkno, cmd_small.addr);
749 cmd_small.length = nblks & 0xff;
750 cmdlen = sizeof(cmd_small);
751 cmdp = (struct scsipi_generic *)&cmd_small;
752 } else
753 #endif
754 {
755 /*
756 * Need a large cdb.
757 */
758 bzero(&cmd_big, sizeof(cmd_big));
759 cmd_big.opcode = (bp->b_flags & B_READ) ?
760 READ_BIG : WRITE_BIG;
761 _lto4b(bp->b_rawblkno, cmd_big.addr);
762 _lto2b(nblks, cmd_big.length);
763 cmdlen = sizeof(cmd_big);
764 cmdp = (struct scsipi_generic *)&cmd_big;
765 }
766
767 /* Instrumentation. */
768 disk_busy(&sd->sc_dk);
769
770 /*
771 * Mark the disk dirty so that the cache will be
772 * flushed on close.
773 */
774 if ((bp->b_flags & B_READ) == 0)
775 sd->flags |= SDF_DIRTY;
776
777 /*
778 * Figure out what flags to use.
779 * XXX Need a B_ORDERED.
780 */
781 flags = XS_CTL_NOSLEEP|XS_CTL_ASYNC;
782 if (bp->b_flags & B_READ)
783 flags |= XS_CTL_DATA_IN | XS_CTL_SIMPLE_TAG;
784 else
785 flags |= XS_CTL_DATA_OUT | XS_CTL_ORDERED_TAG;
786
787 /*
788 * Call the routine that chats with the adapter.
789 * Note: we cannot sleep as we may be an interrupt
790 */
791 error = scsipi_command(periph, cmdp, cmdlen,
792 (u_char *)bp->b_data, bp->b_bcount,
793 SDRETRIES, 60000, bp, flags);
794 if (error) {
795 disk_unbusy(&sd->sc_dk, 0);
796 printf("%s: not queued, error %d\n",
797 sd->sc_dev.dv_xname, error);
798 }
799 }
800 }
801
802 void
803 sddone(xs)
804 struct scsipi_xfer *xs;
805 {
806 struct sd_softc *sd = (void *)xs->xs_periph->periph_dev;
807
808 if (sd->flags & SDF_FLUSHING) {
809 /* Flush completed, no longer dirty. */
810 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
811 }
812
813 if (xs->bp != NULL) {
814 disk_unbusy(&sd->sc_dk, xs->bp->b_bcount - xs->bp->b_resid);
815 #if NRND > 0
816 rnd_add_uint32(&sd->rnd_source, xs->bp->b_rawblkno);
817 #endif
818 }
819 }
820
821 void
822 sdminphys(bp)
823 struct buf *bp;
824 {
825 struct sd_softc *sd = sd_cd.cd_devs[SDUNIT(bp->b_dev)];
826 long max;
827
828 /*
829 * If the device is ancient, we want to make sure that
830 * the transfer fits into a 6-byte cdb.
831 *
832 * XXX Note that the SCSI-I spec says that 256-block transfers
833 * are allowed in a 6-byte read/write, and are specified
834 * by settng the "length" to 0. However, we're conservative
835 * here, allowing only 255-block transfers in case an
836 * ancient device gets confused by length == 0. A length of 0
837 * in a 10-byte read/write actually means 0 blocks.
838 */
839 if ((sd->flags & SDF_ANCIENT) &&
840 ((sd->sc_periph->periph_flags &
841 (PERIPH_REMOVABLE | PERIPH_MEDIA_LOADED)) != PERIPH_REMOVABLE)) {
842 max = sd->sc_dk.dk_label->d_secsize * 0xff;
843
844 if (bp->b_bcount > max)
845 bp->b_bcount = max;
846 }
847
848 (*sd->sc_periph->periph_channel->chan_adapter->adapt_minphys)(bp);
849 }
850
851 int
852 sdread(dev, uio, ioflag)
853 dev_t dev;
854 struct uio *uio;
855 int ioflag;
856 {
857
858 return (physio(sdstrategy, NULL, dev, B_READ, sdminphys, uio));
859 }
860
861 int
862 sdwrite(dev, uio, ioflag)
863 dev_t dev;
864 struct uio *uio;
865 int ioflag;
866 {
867
868 return (physio(sdstrategy, NULL, dev, B_WRITE, sdminphys, uio));
869 }
870
871 /*
872 * Perform special action on behalf of the user
873 * Knows about the internals of this device
874 */
875 int
876 sdioctl(dev, cmd, addr, flag, p)
877 dev_t dev;
878 u_long cmd;
879 caddr_t addr;
880 int flag;
881 struct proc *p;
882 {
883 struct sd_softc *sd = sd_cd.cd_devs[SDUNIT(dev)];
884 struct scsipi_periph *periph = sd->sc_periph;
885 int part = SDPART(dev);
886 int error;
887
888 SC_DEBUG(sd->sc_periph, SCSIPI_DB2, ("sdioctl 0x%lx ", cmd));
889
890 /*
891 * If the device is not valid, some IOCTLs can still be
892 * handled on the raw partition. Check this here.
893 */
894 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0) {
895 switch (cmd) {
896 case DIOCKLABEL:
897 case DIOCWLABEL:
898 case DIOCLOCK:
899 case DIOCEJECT:
900 case ODIOCEJECT:
901 case SCIOCIDENTIFY:
902 case OSCIOCIDENTIFY:
903 case SCIOCCOMMAND:
904 case SCIOCDEBUG:
905 if (part == RAW_PART)
906 break;
907 /* FALLTHROUGH */
908 default:
909 if ((periph->periph_flags & PERIPH_OPEN) == 0)
910 return (ENODEV);
911 else
912 return (EIO);
913 }
914 }
915
916 switch (cmd) {
917 case DIOCGDINFO:
918 *(struct disklabel *)addr = *(sd->sc_dk.dk_label);
919 return (0);
920
921 case DIOCGPART:
922 ((struct partinfo *)addr)->disklab = sd->sc_dk.dk_label;
923 ((struct partinfo *)addr)->part =
924 &sd->sc_dk.dk_label->d_partitions[part];
925 return (0);
926
927 case DIOCWDINFO:
928 case DIOCSDINFO:
929 if ((flag & FWRITE) == 0)
930 return (EBADF);
931
932 if ((error = sdlock(sd)) != 0)
933 return (error);
934 sd->flags |= SDF_LABELLING;
935
936 error = setdisklabel(sd->sc_dk.dk_label,
937 (struct disklabel *)addr, /*sd->sc_dk.dk_openmask : */0,
938 sd->sc_dk.dk_cpulabel);
939 if (error == 0) {
940 if (cmd == DIOCWDINFO)
941 error = writedisklabel(SDLABELDEV(dev),
942 sdstrategy, sd->sc_dk.dk_label,
943 sd->sc_dk.dk_cpulabel);
944 }
945
946 sd->flags &= ~SDF_LABELLING;
947 sdunlock(sd);
948 return (error);
949
950 case DIOCKLABEL:
951 if (*(int *)addr)
952 periph->periph_flags |= PERIPH_KEEP_LABEL;
953 else
954 periph->periph_flags &= ~PERIPH_KEEP_LABEL;
955 return (0);
956
957 case DIOCWLABEL:
958 if ((flag & FWRITE) == 0)
959 return (EBADF);
960 if (*(int *)addr)
961 sd->flags |= SDF_WLABEL;
962 else
963 sd->flags &= ~SDF_WLABEL;
964 return (0);
965
966 case DIOCLOCK:
967 return (scsipi_prevent(periph,
968 (*(int *)addr) ? PR_PREVENT : PR_ALLOW, 0));
969
970 case DIOCEJECT:
971 if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
972 return (ENOTTY);
973 if (*(int *)addr == 0) {
974 /*
975 * Don't force eject: check that we are the only
976 * partition open. If so, unlock it.
977 */
978 if ((sd->sc_dk.dk_openmask & ~(1 << part)) == 0 &&
979 sd->sc_dk.dk_bopenmask + sd->sc_dk.dk_copenmask ==
980 sd->sc_dk.dk_openmask) {
981 error = scsipi_prevent(periph, PR_ALLOW,
982 XS_CTL_IGNORE_NOT_READY);
983 if (error)
984 return (error);
985 } else {
986 return (EBUSY);
987 }
988 }
989 /* FALLTHROUGH */
990 case ODIOCEJECT:
991 return ((periph->periph_flags & PERIPH_REMOVABLE) == 0 ?
992 ENOTTY : scsipi_start(periph, SSS_STOP|SSS_LOEJ, 0));
993
994 case DIOCGDEFLABEL:
995 sdgetdefaultlabel(sd, (struct disklabel *)addr);
996 return (0);
997
998 default:
999 if (part != RAW_PART)
1000 return (ENOTTY);
1001 return (scsipi_do_ioctl(periph, dev, cmd, addr, flag, p));
1002 }
1003
1004 #ifdef DIAGNOSTIC
1005 panic("sdioctl: impossible");
1006 #endif
1007 }
1008
1009 void
1010 sdgetdefaultlabel(sd, lp)
1011 struct sd_softc *sd;
1012 struct disklabel *lp;
1013 {
1014
1015 bzero(lp, sizeof(struct disklabel));
1016
1017 lp->d_secsize = sd->params.blksize;
1018 lp->d_ntracks = sd->params.heads;
1019 lp->d_nsectors = sd->params.sectors;
1020 lp->d_ncylinders = sd->params.cyls;
1021 lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
1022
1023 switch (scsipi_periph_bustype(sd->sc_periph)) {
1024 #if NSD_SCSIBUS > 0
1025 case SCSIPI_BUSTYPE_SCSI:
1026 lp->d_type = DTYPE_SCSI;
1027 break;
1028 #endif
1029 #if NSD_ATAPIBUS > 0
1030 case SCSIPI_BUSTYPE_ATAPI:
1031 lp->d_type = DTYPE_ATAPI;
1032 break;
1033 #endif
1034 }
1035 strncpy(lp->d_typename, sd->name, 16);
1036 strncpy(lp->d_packname, "fictitious", 16);
1037 lp->d_secperunit = sd->params.disksize;
1038 lp->d_rpm = sd->params.rot_rate;
1039 lp->d_interleave = 1;
1040 lp->d_flags = 0;
1041
1042 lp->d_partitions[RAW_PART].p_offset = 0;
1043 lp->d_partitions[RAW_PART].p_size =
1044 lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
1045 lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
1046 lp->d_npartitions = RAW_PART + 1;
1047
1048 lp->d_magic = DISKMAGIC;
1049 lp->d_magic2 = DISKMAGIC;
1050 lp->d_checksum = dkcksum(lp);
1051 }
1052
1053
1054 /*
1055 * Load the label information on the named device
1056 */
1057 void
1058 sdgetdisklabel(sd)
1059 struct sd_softc *sd;
1060 {
1061 struct disklabel *lp = sd->sc_dk.dk_label;
1062 char *errstring;
1063
1064 bzero(sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
1065
1066 sdgetdefaultlabel(sd, lp);
1067
1068 if (lp->d_secpercyl == 0) {
1069 lp->d_secpercyl = 100;
1070 /* as long as it's not 0 - readdisklabel divides by it (?) */
1071 }
1072
1073 /*
1074 * Call the generic disklabel extraction routine
1075 */
1076 errstring = readdisklabel(MAKESDDEV(0, sd->sc_dev.dv_unit, RAW_PART),
1077 sdstrategy, lp, sd->sc_dk.dk_cpulabel);
1078 if (errstring) {
1079 printf("%s: %s\n", sd->sc_dev.dv_xname, errstring);
1080 return;
1081 }
1082 }
1083
1084 void
1085 sd_shutdown(arg)
1086 void *arg;
1087 {
1088 struct sd_softc *sd = arg;
1089
1090 /*
1091 * If the disk cache needs to be flushed, and the disk supports
1092 * it, flush it. We're cold at this point, so we poll for
1093 * completion.
1094 */
1095 if ((sd->flags & SDF_DIRTY) != 0 && sd->sc_ops->sdo_flush != NULL) {
1096 if ((*sd->sc_ops->sdo_flush)(sd, XS_CTL_NOSLEEP|XS_CTL_POLL)) {
1097 printf("%s: cache synchronization failed\n",
1098 sd->sc_dev.dv_xname);
1099 sd->flags &= ~SDF_FLUSHING;
1100 } else
1101 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
1102 }
1103 }
1104
1105 /*
1106 * Tell the device to map out a defective block
1107 */
1108 int
1109 sd_reassign_blocks(sd, blkno)
1110 struct sd_softc *sd;
1111 u_long blkno;
1112 {
1113 struct scsi_reassign_blocks scsipi_cmd;
1114 struct scsi_reassign_blocks_data rbdata;
1115
1116 bzero(&scsipi_cmd, sizeof(scsipi_cmd));
1117 bzero(&rbdata, sizeof(rbdata));
1118 scsipi_cmd.opcode = SCSI_REASSIGN_BLOCKS;
1119
1120 _lto2b(sizeof(rbdata.defect_descriptor[0]), rbdata.length);
1121 _lto4b(blkno, rbdata.defect_descriptor[0].dlbaddr);
1122
1123 return (scsipi_command(sd->sc_periph,
1124 (struct scsipi_generic *)&scsipi_cmd, sizeof(scsipi_cmd),
1125 (u_char *)&rbdata, sizeof(rbdata), SDRETRIES, 5000, NULL,
1126 XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK));
1127 }
1128
1129 /*
1130 * Check Errors
1131 */
1132 int
1133 sd_interpret_sense(xs)
1134 struct scsipi_xfer *xs;
1135 {
1136 struct scsipi_periph *periph = xs->xs_periph;
1137 struct scsipi_sense_data *sense = &xs->sense.scsi_sense;
1138 struct sd_softc *sd = (void *)periph->periph_dev;
1139 int s, error, retval = EJUSTRETURN;
1140
1141 /*
1142 * If the periph is already recovering, just do the normal
1143 * error processing.
1144 */
1145 if (periph->periph_flags & PERIPH_RECOVERING)
1146 return (retval);
1147
1148 /*
1149 * If the device is not open yet, let the generic code handle it.
1150 */
1151 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
1152 return (retval);
1153
1154 /*
1155 * If it isn't a extended or extended/deferred error, let
1156 * the generic code handle it.
1157 */
1158 if ((sense->error_code & SSD_ERRCODE) != 0x70 &&
1159 (sense->error_code & SSD_ERRCODE) != 0x71)
1160 return (retval);
1161
1162 if ((sense->flags & SSD_KEY) == SKEY_NOT_READY &&
1163 sense->add_sense_code == 0x4) {
1164 if (sense->add_sense_code_qual == 0x01) {
1165 /*
1166 * Unit In The Process Of Becoming Ready.
1167 */
1168 printf("%s: waiting for pack to spin up...\n",
1169 sd->sc_dev.dv_xname);
1170 scsipi_periph_freeze(periph, 1);
1171 callout_reset(&periph->periph_callout,
1172 5 * hz, scsipi_periph_timed_thaw, periph);
1173 retval = ERESTART;
1174 } else if ((sense->add_sense_code_qual == 0x2) &&
1175 (periph->periph_quirks & PQUIRK_NOSTARTUNIT) == 0) {
1176 printf("%s: pack is stopped, restarting...\n",
1177 sd->sc_dev.dv_xname);
1178 s = splbio();
1179 periph->periph_flags |= PERIPH_RECOVERING;
1180 splx(s);
1181 error = scsipi_start(periph, SSS_START,
1182 XS_CTL_URGENT|XS_CTL_HEAD_TAG|
1183 XS_CTL_THAW_PERIPH|XS_CTL_FREEZE_PERIPH);
1184 if (error) {
1185 printf("%s: unable to restart pack\n",
1186 sd->sc_dev.dv_xname);
1187 retval = error;
1188 } else
1189 retval = ERESTART;
1190 s = splbio();
1191 periph->periph_flags &= ~PERIPH_RECOVERING;
1192 splx(s);
1193 }
1194 }
1195 return (retval);
1196 }
1197
1198
1199 int
1200 sdsize(dev)
1201 dev_t dev;
1202 {
1203 struct sd_softc *sd;
1204 int part, unit, omask;
1205 int size;
1206
1207 unit = SDUNIT(dev);
1208 if (unit >= sd_cd.cd_ndevs)
1209 return (-1);
1210 sd = sd_cd.cd_devs[unit];
1211 if (sd == NULL)
1212 return (-1);
1213
1214 if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
1215 return (-1);
1216
1217 part = SDPART(dev);
1218 omask = sd->sc_dk.dk_openmask & (1 << part);
1219
1220 if (omask == 0 && sdopen(dev, 0, S_IFBLK, NULL) != 0)
1221 return (-1);
1222 if ((sd->sc_periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
1223 size = -1;
1224 else if (sd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
1225 size = -1;
1226 else
1227 size = sd->sc_dk.dk_label->d_partitions[part].p_size *
1228 (sd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
1229 if (omask == 0 && sdclose(dev, 0, S_IFBLK, NULL) != 0)
1230 return (-1);
1231 return (size);
1232 }
1233
1234 /* #define SD_DUMP_NOT_TRUSTED if you just want to watch */
1235 static struct scsipi_xfer sx;
1236 static int sddoingadump;
1237
1238 /*
1239 * dump all of physical memory into the partition specified, starting
1240 * at offset 'dumplo' into the partition.
1241 */
1242 int
1243 sddump(dev, blkno, va, size)
1244 dev_t dev;
1245 daddr_t blkno;
1246 caddr_t va;
1247 size_t size;
1248 {
1249 struct sd_softc *sd; /* disk unit to do the I/O */
1250 struct disklabel *lp; /* disk's disklabel */
1251 int unit, part;
1252 int sectorsize; /* size of a disk sector */
1253 int nsects; /* number of sectors in partition */
1254 int sectoff; /* sector offset of partition */
1255 int totwrt; /* total number of sectors left to write */
1256 int nwrt; /* current number of sectors to write */
1257 struct scsipi_rw_big cmd; /* write command */
1258 struct scsipi_xfer *xs; /* ... convenience */
1259 struct scsipi_periph *periph = sd->sc_periph;
1260 struct scsipi_channel *chan = periph->periph_channel;
1261
1262 if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
1263 return (ENODEV);
1264
1265 /* Check if recursive dump; if so, punt. */
1266 if (sddoingadump)
1267 return (EFAULT);
1268
1269 /* Mark as active early. */
1270 sddoingadump = 1;
1271
1272 unit = SDUNIT(dev); /* Decompose unit & partition. */
1273 part = SDPART(dev);
1274
1275 /* Check for acceptable drive number. */
1276 if (unit >= sd_cd.cd_ndevs || (sd = sd_cd.cd_devs[unit]) == NULL)
1277 return (ENXIO);
1278
1279 if ((sd->sc_dev.dv_flags & DVF_ACTIVE) == 0)
1280 return (ENODEV);
1281
1282 /* Make sure it was initialized. */
1283 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) != 0)
1284 return (ENXIO);
1285
1286 /* Convert to disk sectors. Request must be a multiple of size. */
1287 lp = sd->sc_dk.dk_label;
1288 sectorsize = lp->d_secsize;
1289 if ((size % sectorsize) != 0)
1290 return (EFAULT);
1291 totwrt = size / sectorsize;
1292 blkno = dbtob(blkno) / sectorsize; /* blkno in DEV_BSIZE units */
1293
1294 nsects = lp->d_partitions[part].p_size;
1295 sectoff = lp->d_partitions[part].p_offset;
1296
1297 /* Check transfer bounds against partition size. */
1298 if ((blkno < 0) || ((blkno + totwrt) > nsects))
1299 return (EINVAL);
1300
1301 /* Offset block number to start of partition. */
1302 blkno += sectoff;
1303
1304 xs = &sx;
1305
1306 while (totwrt > 0) {
1307 nwrt = totwrt; /* XXX */
1308 #ifndef SD_DUMP_NOT_TRUSTED
1309 /*
1310 * Fill out the scsi command
1311 */
1312 bzero(&cmd, sizeof(cmd));
1313 cmd.opcode = WRITE_BIG;
1314 _lto4b(blkno, cmd.addr);
1315 _lto2b(nwrt, cmd.length);
1316 /*
1317 * Fill out the scsipi_xfer structure
1318 * Note: we cannot sleep as we may be an interrupt
1319 * don't use scsipi_command() as it may want to wait
1320 * for an xs.
1321 */
1322 bzero(xs, sizeof(sx));
1323 xs->xs_control |= XS_CTL_NOSLEEP | XS_CTL_POLL |
1324 XS_CTL_DATA_OUT;
1325 xs->xs_status = 0;
1326 xs->xs_periph = periph;
1327 xs->xs_retries = SDRETRIES;
1328 xs->timeout = 10000; /* 10000 millisecs for a disk ! */
1329 xs->cmd = (struct scsipi_generic *)&cmd;
1330 xs->cmdlen = sizeof(cmd);
1331 xs->resid = nwrt * sectorsize;
1332 xs->error = XS_NOERROR;
1333 xs->bp = 0;
1334 xs->data = va;
1335 xs->datalen = nwrt * sectorsize;
1336
1337 /*
1338 * Pass all this info to the scsi driver.
1339 */
1340 scsipi_adapter_request(chan, ADAPTER_REQ_RUN_XFER, xs);
1341 if ((xs->xs_status & XS_STS_DONE) == 0 ||
1342 xs->error != XS_NOERROR)
1343 return (EIO);
1344 #else /* SD_DUMP_NOT_TRUSTED */
1345 /* Let's just talk about this first... */
1346 printf("sd%d: dump addr 0x%x, blk %d\n", unit, va, blkno);
1347 delay(500 * 1000); /* half a second */
1348 #endif /* SD_DUMP_NOT_TRUSTED */
1349
1350 /* update block count */
1351 totwrt -= nwrt;
1352 blkno += nwrt;
1353 va += sectorsize * nwrt;
1354 }
1355 sddoingadump = 0;
1356 return (0);
1357 }
1358