sd.c revision 1.324.4.1 1 /* $NetBSD: sd.c,v 1.324.4.1 2017/04/27 05:36:36 pgoyette Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2003, 2004 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 *
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 * Originally written by Julian Elischer (julian (at) dialix.oz.au)
34 * for TRW Financial Systems for use under the MACH(2.5) operating system.
35 *
36 * TRW Financial Systems, in accordance with their agreement with Carnegie
37 * Mellon University, makes this software available to CMU to distribute
38 * or use in any manner that they see fit as long as this message is kept with
39 * the software. For this reason TFS also grants any other persons or
40 * organisations permission to use or modify this software.
41 *
42 * TFS supplies this software to be publicly redistributed
43 * on the understanding that TFS is not responsible for the correct
44 * functioning of this software in any circumstances.
45 *
46 * Ported to run under 386BSD by Julian Elischer (julian (at) dialix.oz.au) Sept 1992
47 */
48
49 #include <sys/cdefs.h>
50 __KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.324.4.1 2017/04/27 05:36:36 pgoyette Exp $");
51
52 #ifdef _KERNEL_OPT
53 #include "opt_scsi.h"
54 #endif
55
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/file.h>
60 #include <sys/stat.h>
61 #include <sys/ioctl.h>
62 #include <sys/scsiio.h>
63 #include <sys/buf.h>
64 #include <sys/bufq.h>
65 #include <sys/uio.h>
66 #include <sys/malloc.h>
67 #include <sys/errno.h>
68 #include <sys/device.h>
69 #include <sys/disklabel.h>
70 #include <sys/disk.h>
71 #include <sys/proc.h>
72 #include <sys/conf.h>
73 #include <sys/vnode.h>
74
75 #include <dev/scsipi/scsi_spc.h>
76 #include <dev/scsipi/scsipi_all.h>
77 #include <dev/scsipi/scsi_all.h>
78 #include <dev/scsipi/scsipi_disk.h>
79 #include <dev/scsipi/scsi_disk.h>
80 #include <dev/scsipi/scsiconf.h>
81 #include <dev/scsipi/scsipi_base.h>
82 #include <dev/scsipi/sdvar.h>
83
84 #include <prop/proplib.h>
85
86 #define SDUNIT(dev) DISKUNIT(dev)
87 #define SDPART(dev) DISKPART(dev)
88 #define SDMINOR(unit, part) DISKMINOR(unit, part)
89 #define MAKESDDEV(maj, unit, part) MAKEDISKDEV(maj, unit, part)
90
91 #define SDLABELDEV(dev) (MAKESDDEV(major(dev), SDUNIT(dev), RAW_PART))
92
93 #define SD_DEFAULT_BLKSIZE 512
94
95 static void sdminphys(struct buf *);
96 static void sdstart(struct scsipi_periph *);
97 static void sdrestart(void *);
98 static void sddone(struct scsipi_xfer *, int);
99 static bool sd_suspend(device_t, const pmf_qual_t *);
100 static bool sd_shutdown(device_t, int);
101 static int sd_interpret_sense(struct scsipi_xfer *);
102 static int sd_diskstart(device_t, struct buf *);
103 static int sd_dumpblocks(device_t, void *, daddr_t, int);
104 static void sd_iosize(device_t, int *);
105 static int sd_lastclose(device_t);
106 static int sd_firstopen(device_t, dev_t, int, int);
107 static void sd_label(device_t, struct disklabel *);
108
109 static int sd_mode_sense(struct sd_softc *, u_int8_t, void *, size_t, int,
110 int, int *);
111 static int sd_mode_select(struct sd_softc *, u_int8_t, void *, size_t, int,
112 int);
113 static int sd_validate_blksize(struct scsipi_periph *, int);
114 static u_int64_t sd_read_capacity(struct scsipi_periph *, int *, int flags);
115 static int sd_get_simplifiedparms(struct sd_softc *, struct disk_parms *,
116 int);
117 static int sd_get_capacity(struct sd_softc *, struct disk_parms *, int);
118 static int sd_get_parms(struct sd_softc *, struct disk_parms *, int);
119 static int sd_get_parms_page4(struct sd_softc *, struct disk_parms *,
120 int);
121 static int sd_get_parms_page5(struct sd_softc *, struct disk_parms *,
122 int);
123
124 static int sd_flush(struct sd_softc *, int);
125 static int sd_getcache(struct sd_softc *, int *);
126 static int sd_setcache(struct sd_softc *, int);
127
128 static int sdmatch(device_t, cfdata_t, void *);
129 static void sdattach(device_t, device_t, void *);
130 static int sddetach(device_t, int);
131 static void sd_set_geometry(struct sd_softc *);
132
133 CFATTACH_DECL3_NEW(sd, sizeof(struct sd_softc), sdmatch, sdattach, sddetach,
134 NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
135
136 extern struct cfdriver sd_cd;
137
138 static const struct scsipi_inquiry_pattern sd_patterns[] = {
139 {T_DIRECT, T_FIXED,
140 "", "", ""},
141 {T_DIRECT, T_REMOV,
142 "", "", ""},
143 {T_OPTICAL, T_FIXED,
144 "", "", ""},
145 {T_OPTICAL, T_REMOV,
146 "", "", ""},
147 {T_SIMPLE_DIRECT, T_FIXED,
148 "", "", ""},
149 {T_SIMPLE_DIRECT, T_REMOV,
150 "", "", ""},
151 };
152
153 static dev_type_open(sdopen);
154 static dev_type_close(sdclose);
155 static dev_type_read(sdread);
156 static dev_type_write(sdwrite);
157 static dev_type_ioctl(sdioctl);
158 static dev_type_strategy(sdstrategy);
159 static dev_type_dump(sddump);
160 static dev_type_size(sdsize);
161
162 const struct bdevsw sd_bdevsw = {
163 DEVSW_MODULE_INIT
164 .d_open = sdopen,
165 .d_close = sdclose,
166 .d_strategy = sdstrategy,
167 .d_ioctl = sdioctl,
168 .d_dump = sddump,
169 .d_psize = sdsize,
170 .d_discard = nodiscard,
171 .d_flag = D_DISK | D_MPSAFE
172 };
173
174 const struct cdevsw sd_cdevsw = {
175 DEVSW_MODULE_INIT
176 .d_open = sdopen,
177 .d_close = sdclose,
178 .d_read = sdread,
179 .d_write = sdwrite,
180 .d_ioctl = sdioctl,
181 .d_stop = nostop,
182 .d_tty = notty,
183 .d_poll = nopoll,
184 .d_mmap = nommap,
185 .d_kqfilter = nokqfilter,
186 .d_discard = nodiscard,
187 .d_flag = D_DISK | D_MPSAFE
188 };
189
190 static struct dkdriver sddkdriver = {
191 .d_open = sdopen,
192 .d_close = sdclose,
193 .d_strategy = sdstrategy,
194 .d_minphys = sdminphys,
195 .d_diskstart = sd_diskstart,
196 .d_dumpblocks = sd_dumpblocks,
197 .d_iosize = sd_iosize,
198 .d_firstopen = sd_firstopen,
199 .d_lastclose = sd_lastclose,
200 .d_label = sd_label,
201 };
202
203 static const struct scsipi_periphsw sd_switch = {
204 sd_interpret_sense, /* check our error handler first */
205 sdstart, /* have a queue, served by this */
206 NULL, /* have no async handler */
207 sddone, /* deal with stats at interrupt time */
208 };
209
210 struct sd_mode_sense_data {
211 /*
212 * XXX
213 * We are not going to parse this as-is -- it just has to be large
214 * enough.
215 */
216 union {
217 struct scsi_mode_parameter_header_6 small;
218 struct scsi_mode_parameter_header_10 big;
219 } header;
220 struct scsi_general_block_descriptor blk_desc;
221 union scsi_disk_pages pages;
222 };
223
224 /*
225 * The routine called by the low level scsi routine when it discovers
226 * A device suitable for this driver
227 */
228 static int
229 sdmatch(device_t parent, cfdata_t match,
230 void *aux)
231 {
232 struct scsipibus_attach_args *sa = aux;
233 int priority;
234
235 (void)scsipi_inqmatch(&sa->sa_inqbuf,
236 sd_patterns, sizeof(sd_patterns) / sizeof(sd_patterns[0]),
237 sizeof(sd_patterns[0]), &priority);
238
239 return (priority);
240 }
241
242 /*
243 * Attach routine common to atapi & scsi.
244 */
245 static void
246 sdattach(device_t parent, device_t self, void *aux)
247 {
248 struct sd_softc *sd = device_private(self);
249 struct dk_softc *dksc = &sd->sc_dksc;
250 struct scsipibus_attach_args *sa = aux;
251 struct scsipi_periph *periph = sa->sa_periph;
252 int error, result, dtype;
253 struct disk_parms *dp = &sd->params;
254 char pbuf[9];
255
256 SC_DEBUG(periph, SCSIPI_DB2, ("sdattach: "));
257
258 sd->type = (sa->sa_inqbuf.type & SID_TYPE);
259 strncpy(sd->name, sa->sa_inqbuf.product, sizeof(sd->name));
260
261 if (sd->type == T_SIMPLE_DIRECT)
262 periph->periph_quirks |= PQUIRK_ONLYBIG | PQUIRK_NOBIGMODESENSE;
263
264 switch (SCSIPI_BUSTYPE_TYPE(scsipi_periph_bustype(sa->sa_periph))) {
265 case SCSIPI_BUSTYPE_SCSI:
266 dtype = DKTYPE_SCSI;
267 if (periph->periph_version == 0)
268 sd->flags |= SDF_ANCIENT;
269 break;
270 case SCSIPI_BUSTYPE_ATAPI:
271 dtype = DKTYPE_ATAPI;
272 break;
273 default:
274 dtype = DKTYPE_UNKNOWN;
275 break;
276 }
277
278 /* Initialize dk and disk structure. */
279 dk_init(dksc, self, dtype);
280 disk_init(&dksc->sc_dkdev, dksc->sc_xname, &sddkdriver);
281
282 /* Attach dk and disk subsystems */
283 dk_attach(dksc);
284 disk_attach(&dksc->sc_dkdev);
285
286 bufq_alloc(&dksc->sc_bufq, BUFQ_DISK_DEFAULT_STRAT, BUFQ_SORT_RAWBLOCK);
287
288 callout_init(&sd->sc_callout, 0);
289
290 /*
291 * Store information needed to contact our base driver
292 */
293 sd->sc_periph = periph;
294
295 periph->periph_dev = dksc->sc_dev;
296 periph->periph_switch = &sd_switch;
297
298 /*
299 * Increase our openings to the maximum-per-periph
300 * supported by the adapter. This will either be
301 * clamped down or grown by the adapter if necessary.
302 */
303 periph->periph_openings =
304 SCSIPI_CHAN_MAX_PERIPH(periph->periph_channel);
305 periph->periph_flags |= PERIPH_GROW_OPENINGS;
306
307 /*
308 * Use the subdriver to request information regarding the drive.
309 */
310 aprint_naive("\n");
311 aprint_normal("\n");
312
313 if (periph->periph_quirks & PQUIRK_START)
314 (void)scsipi_start(periph, SSS_START, XS_CTL_SILENT);
315
316 error = scsipi_test_unit_ready(periph,
317 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
318 XS_CTL_IGNORE_MEDIA_CHANGE | XS_CTL_SILENT_NODEV);
319 if (error)
320 result = SDGP_RESULT_OFFLINE;
321 else
322 result = sd_get_parms(sd, &sd->params, XS_CTL_DISCOVERY);
323
324 aprint_normal_dev(dksc->sc_dev, "");
325 switch (result) {
326 case SDGP_RESULT_OK:
327 format_bytes(pbuf, sizeof(pbuf),
328 (u_int64_t)dp->disksize * dp->blksize);
329 aprint_normal(
330 "%s, %ld cyl, %ld head, %ld sec, %ld bytes/sect x %llu sectors",
331 pbuf, dp->cyls, dp->heads, dp->sectors, dp->blksize,
332 (unsigned long long)dp->disksize);
333 break;
334
335 case SDGP_RESULT_OFFLINE:
336 aprint_normal("drive offline");
337 break;
338
339 case SDGP_RESULT_UNFORMATTED:
340 aprint_normal("unformatted media");
341 break;
342
343 #ifdef DIAGNOSTIC
344 default:
345 panic("sdattach: unknown result from get_parms");
346 break;
347 #endif
348 }
349 aprint_normal("\n");
350
351 /* Discover wedges on this disk. */
352 dkwedge_discover(&dksc->sc_dkdev);
353
354 /*
355 * Establish a shutdown hook so that we can ensure that
356 * our data has actually made it onto the platter at
357 * shutdown time. Note that this relies on the fact
358 * that the shutdown hooks at the "leaves" of the device tree
359 * are run, first (thus guaranteeing that our hook runs before
360 * our ancestors').
361 */
362 if (!pmf_device_register1(self, sd_suspend, NULL, sd_shutdown))
363 aprint_error_dev(self, "couldn't establish power handler\n");
364 }
365
366 static int
367 sddetach(device_t self, int flags)
368 {
369 struct sd_softc *sd = device_private(self);
370 struct dk_softc *dksc = &sd->sc_dksc;
371 struct scsipi_periph *periph = sd->sc_periph;
372 struct scsipi_channel *chan = periph->periph_channel;
373 int bmaj, cmaj, i, mn, rc;
374
375 if ((rc = disk_begindetach(&dksc->sc_dkdev, sd_lastclose, self, flags)) != 0)
376 return rc;
377
378 /* locate the major number */
379 bmaj = bdevsw_lookup_major(&sd_bdevsw);
380 cmaj = cdevsw_lookup_major(&sd_cdevsw);
381
382 /* Nuke the vnodes for any open instances */
383 for (i = 0; i < MAXPARTITIONS; i++) {
384 mn = SDMINOR(device_unit(self), i);
385 vdevgone(bmaj, mn, mn, VBLK);
386 vdevgone(cmaj, mn, mn, VCHR);
387 }
388
389 /* kill any pending restart */
390 callout_stop(&sd->sc_callout);
391
392 dk_drain(dksc);
393
394 /* Kill off any pending commands. */
395 mutex_enter(chan_mtx(chan));
396 scsipi_kill_pending(periph);
397 mutex_exit(chan_mtx(chan));
398
399 bufq_free(dksc->sc_bufq);
400
401 /* Delete all of our wedges. */
402 dkwedge_delall(&dksc->sc_dkdev);
403
404 /* Detach from the disk list. */
405 disk_detach(&dksc->sc_dkdev);
406 disk_destroy(&dksc->sc_dkdev);
407
408 dk_detach(dksc);
409
410 callout_destroy(&sd->sc_callout);
411
412 pmf_device_deregister(self);
413
414 return (0);
415 }
416
417 /*
418 * Serialized by caller
419 */
420 static int
421 sd_firstopen(device_t self, dev_t dev, int flag, int fmt)
422 {
423 struct sd_softc *sd = device_private(self);
424 struct scsipi_periph *periph = sd->sc_periph;
425 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
426 int error, silent;
427 int part, removable;
428
429 part = SDPART(dev);
430
431 error = scsipi_adapter_addref(adapt);
432 if (error)
433 return error;
434
435 if ((part == RAW_PART && fmt == S_IFCHR) || (flag & FSILENT))
436 silent = XS_CTL_SILENT;
437 else
438 silent = 0;
439
440 /* Check that it is still responding and ok. */
441 error = scsipi_test_unit_ready(periph,
442 XS_CTL_IGNORE_ILLEGAL_REQUEST | XS_CTL_IGNORE_MEDIA_CHANGE |
443 silent);
444
445 /*
446 * Start the pack spinning if necessary. Always allow the
447 * raw parition to be opened, for raw IOCTLs. Data transfers
448 * will check for SDEV_MEDIA_LOADED.
449 */
450 if (error == EIO) {
451 error = scsipi_start(periph, SSS_START, silent);
452 if (error == EINVAL)
453 error = EIO;
454 }
455 if (error)
456 goto bad;
457
458 removable = (periph->periph_flags & PERIPH_REMOVABLE) != 0;
459 if (removable) {
460 /* Lock the pack in. */
461 error = scsipi_prevent(periph, SPAMR_PREVENT_DT,
462 XS_CTL_IGNORE_ILLEGAL_REQUEST |
463 XS_CTL_IGNORE_MEDIA_CHANGE |
464 XS_CTL_SILENT);
465 if (error)
466 goto bad;
467 }
468
469 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0) {
470 int param_error;
471
472 /*
473 * Load the physical device parameters.
474 *
475 * Note that if media is present but unformatted,
476 * we allow the open (so that it can be formatted!).
477 * The drive should refuse real I/O, if the media is
478 * unformatted.
479 */
480 param_error = sd_get_parms(sd, &sd->params, 0);
481 if (param_error == SDGP_RESULT_OFFLINE) {
482 error = ENXIO;
483 goto bad2;
484 }
485 periph->periph_flags |= PERIPH_MEDIA_LOADED;
486
487 SC_DEBUG(periph, SCSIPI_DB3, ("Params loaded "));
488 }
489
490 periph->periph_flags |= PERIPH_OPEN;
491 return 0;
492
493 bad2:
494 if (removable)
495 scsipi_prevent(periph, SPAMR_ALLOW,
496 XS_CTL_IGNORE_ILLEGAL_REQUEST |
497 XS_CTL_IGNORE_MEDIA_CHANGE |
498 XS_CTL_SILENT);
499
500 bad:
501 scsipi_adapter_delref(adapt);
502 return error;
503 }
504
505 /*
506 * open the device. Make sure the partition info is a up-to-date as can be.
507 */
508 static int
509 sdopen(dev_t dev, int flag, int fmt, struct lwp *l)
510 {
511 struct sd_softc *sd;
512 struct dk_softc *dksc;
513 struct scsipi_periph *periph;
514 int unit, part;
515 int error;
516
517 unit = SDUNIT(dev);
518 sd = device_lookup_private(&sd_cd, unit);
519 if (sd == NULL)
520 return (ENXIO);
521 dksc = &sd->sc_dksc;
522
523 if (!device_is_active(dksc->sc_dev))
524 return (ENODEV);
525
526 periph = sd->sc_periph;
527 part = SDPART(dev);
528
529 SC_DEBUG(periph, SCSIPI_DB1,
530 ("sdopen: dev=0x%"PRIx64" (unit %d (of %d), partition %d)\n",
531 dev, unit, sd_cd.cd_ndevs, SDPART(dev)));
532
533 /*
534 * If any partition is open, but the disk has been invalidated,
535 * disallow further opens of non-raw partition
536 */
537 if ((periph->periph_flags & (PERIPH_OPEN | PERIPH_MEDIA_LOADED)) ==
538 PERIPH_OPEN) {
539 if (part != RAW_PART || fmt != S_IFCHR)
540 return EIO;
541 }
542
543 error = dk_open(dksc, dev, flag, fmt, l);
544
545 SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
546
547 return error;
548 }
549
550 /*
551 * Serialized by caller
552 */
553 static int
554 sd_lastclose(device_t self)
555 {
556 struct sd_softc *sd = device_private(self);
557 struct dk_softc *dksc = &sd->sc_dksc;
558 struct scsipi_periph *periph = sd->sc_periph;
559 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
560
561 /*
562 * If the disk cache needs flushing, and the disk supports
563 * it, do it now.
564 */
565 if ((sd->flags & SDF_DIRTY) != 0) {
566 if (sd_flush(sd, 0)) {
567 aprint_error_dev(dksc->sc_dev,
568 "cache synchronization failed\n");
569 sd->flags &= ~SDF_FLUSHING;
570 } else
571 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
572 }
573
574 scsipi_wait_drain(periph);
575
576 if (periph->periph_flags & PERIPH_REMOVABLE)
577 scsipi_prevent(periph, SPAMR_ALLOW,
578 XS_CTL_IGNORE_ILLEGAL_REQUEST |
579 XS_CTL_IGNORE_NOT_READY |
580 XS_CTL_SILENT);
581 periph->periph_flags &= ~PERIPH_OPEN;
582
583 scsipi_wait_drain(periph);
584
585 scsipi_adapter_delref(adapt);
586
587 return 0;
588 }
589
590 /*
591 * close the device.. only called if we are the LAST occurence of an open
592 * device. Convenient now but usually a pain.
593 */
594 static int
595 sdclose(dev_t dev, int flag, int fmt, struct lwp *l)
596 {
597 struct sd_softc *sd;
598 struct dk_softc *dksc;
599 int unit;
600
601 unit = SDUNIT(dev);
602 sd = device_lookup_private(&sd_cd, unit);
603 dksc = &sd->sc_dksc;
604
605 return dk_close(dksc, dev, flag, fmt, l);
606 }
607
608 /*
609 * Actually translate the requested transfer into one the physical driver
610 * can understand. The transfer is described by a buf and will include
611 * only one physical transfer.
612 */
613 static void
614 sdstrategy(struct buf *bp)
615 {
616 struct sd_softc *sd = device_lookup_private(&sd_cd, SDUNIT(bp->b_dev));
617 struct dk_softc *dksc = &sd->sc_dksc;
618 struct scsipi_periph *periph = sd->sc_periph;
619
620 SC_DEBUG(sd->sc_periph, SCSIPI_DB2, ("sdstrategy "));
621 SC_DEBUG(sd->sc_periph, SCSIPI_DB1,
622 ("%d bytes @ blk %" PRId64 "\n", bp->b_bcount, bp->b_blkno));
623
624 /*
625 * If the device has been made invalid, error out
626 */
627 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0 ||
628 !device_is_active(dksc->sc_dev)) {
629 if (periph->periph_flags & PERIPH_OPEN)
630 bp->b_error = EIO;
631 else
632 bp->b_error = ENODEV;
633
634 bp->b_resid = bp->b_bcount;
635 biodone(bp);
636 return;
637 }
638
639 dk_strategy(dksc, bp);
640 }
641
642 /*
643 * Issue single I/O command
644 *
645 * Called from dk_start and implicitely from dk_strategy
646 */
647 static int
648 sd_diskstart(device_t dev, struct buf *bp)
649 {
650 struct sd_softc *sd = device_private(dev);
651 struct scsipi_periph *periph = sd->sc_periph;
652 struct scsipi_channel *chan = periph->periph_channel;
653 struct scsipi_rw_16 cmd16;
654 struct scsipi_rw_10 cmd_big;
655 struct scsi_rw_6 cmd_small;
656 struct scsipi_generic *cmdp;
657 struct scsipi_xfer *xs;
658 int error, flags, nblks, cmdlen;
659 int cdb_flags;
660
661 mutex_enter(chan_mtx(chan));
662
663 if (periph->periph_active >= periph->periph_openings) {
664 error = EAGAIN;
665 goto out;
666 }
667
668 /*
669 * there is excess capacity, but a special waits
670 * It'll need the adapter as soon as we clear out of the
671 * way and let it run (user level wait).
672 */
673 if (periph->periph_flags & PERIPH_WAITING) {
674 periph->periph_flags &= ~PERIPH_WAITING;
675 cv_broadcast(periph_cv_periph(periph));
676 error = EAGAIN;
677 goto out;
678 }
679
680 /*
681 * If the device has become invalid, abort all the
682 * reads and writes until all files have been closed and
683 * re-opened
684 */
685 if (__predict_false(
686 (periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)) {
687 error = EIO;
688 goto out;
689 }
690
691 /*
692 * Mark the disk dirty so that the cache will be
693 * flushed on close.
694 */
695 if ((bp->b_flags & B_READ) == 0)
696 sd->flags |= SDF_DIRTY;
697
698 if (sd->params.blksize == DEV_BSIZE)
699 nblks = bp->b_bcount >> DEV_BSHIFT;
700 else
701 nblks = howmany(bp->b_bcount, sd->params.blksize);
702
703 /*
704 * Pass FUA and/or DPO if requested. Must be done before CDB
705 * selection, as 6-byte CDB doesn't support the flags.
706 */
707 cdb_flags = 0;
708
709 if (bp->b_flags & B_MEDIA_FUA)
710 cdb_flags |= SRWB_FUA;
711
712 if (bp->b_flags & B_MEDIA_DPO)
713 cdb_flags |= SRWB_DPO;
714
715 /*
716 * Fill out the scsi command. Use the smallest CDB possible
717 * (6-byte, 10-byte, or 16-byte). If we need FUA or DPO,
718 * need to use 10-byte or bigger, as the 6-byte doesn't support
719 * the flags.
720 */
721 if (((bp->b_rawblkno & 0x1fffff) == bp->b_rawblkno) &&
722 ((nblks & 0xff) == nblks) &&
723 !(periph->periph_quirks & PQUIRK_ONLYBIG) &&
724 !cdb_flags) {
725 /* 6-byte CDB */
726 memset(&cmd_small, 0, sizeof(cmd_small));
727 cmd_small.opcode = (bp->b_flags & B_READ) ?
728 SCSI_READ_6_COMMAND : SCSI_WRITE_6_COMMAND;
729 _lto3b(bp->b_rawblkno, cmd_small.addr);
730 cmd_small.length = nblks & 0xff;
731 cmdlen = sizeof(cmd_small);
732 cmdp = (struct scsipi_generic *)&cmd_small;
733 } else if ((bp->b_rawblkno & 0xffffffff) == bp->b_rawblkno) {
734 /* 10-byte CDB */
735 memset(&cmd_big, 0, sizeof(cmd_big));
736 cmd_big.opcode = (bp->b_flags & B_READ) ?
737 READ_10 : WRITE_10;
738 _lto4b(bp->b_rawblkno, cmd_big.addr);
739 _lto2b(nblks, cmd_big.length);
740 cmdlen = sizeof(cmd_big);
741 cmdp = (struct scsipi_generic *)&cmd_big;
742 } else {
743 /* 16-byte CDB */
744 memset(&cmd16, 0, sizeof(cmd16));
745 cmd16.opcode = (bp->b_flags & B_READ) ?
746 READ_16 : WRITE_16;
747 _lto8b(bp->b_rawblkno, cmd16.addr);
748 _lto4b(nblks, cmd16.length);
749 cmdlen = sizeof(cmd16);
750 cmdp = (struct scsipi_generic *)&cmd16;
751 }
752
753 if (cdb_flags)
754 cmdp->bytes[0] = cdb_flags;
755
756 /*
757 * Figure out what flags to use.
758 */
759 flags = XS_CTL_NOSLEEP|XS_CTL_ASYNC|XS_CTL_SIMPLE_TAG;
760 if (bp->b_flags & B_READ)
761 flags |= XS_CTL_DATA_IN;
762 else
763 flags |= XS_CTL_DATA_OUT;
764
765 /*
766 * Call the routine that chats with the adapter.
767 * Note: we cannot sleep as we may be an interrupt
768 */
769 xs = scsipi_make_xs_locked(periph, cmdp, cmdlen,
770 (u_char *)bp->b_data, bp->b_bcount,
771 SDRETRIES, SD_IO_TIMEOUT, bp, flags);
772 if (__predict_false(xs == NULL)) {
773 /*
774 * out of memory. Keep this buffer in the queue, and
775 * retry later.
776 */
777 callout_reset(&sd->sc_callout, hz / 2, sdrestart, sd);
778 error = EAGAIN;
779 goto out;
780 }
781
782 error = scsipi_execute_xs(xs);
783 /* with a scsipi_xfer preallocated, scsipi_command can't fail */
784 KASSERT(error == 0);
785
786 out:
787 mutex_exit(chan_mtx(chan));
788
789 return error;
790 }
791
792 /*
793 * Recover I/O request after memory shortage
794 *
795 * Called from callout
796 */
797 static void
798 sdrestart(void *v)
799 {
800 struct sd_softc *sd = v;
801 struct dk_softc *dksc = &sd->sc_dksc;
802
803 dk_start(dksc, NULL);
804 }
805
806 /*
807 * Recover I/O request after memory shortage
808 *
809 * Called from scsipi midlayer when resources have been freed
810 * with channel lock held
811 */
812 static void
813 sdstart(struct scsipi_periph *periph)
814 {
815 struct sd_softc *sd = device_private(periph->periph_dev);
816 struct dk_softc *dksc = &sd->sc_dksc;
817 struct scsipi_channel *chan = periph->periph_channel;
818
819 /*
820 * release channel lock as dk_start may need to acquire
821 * other locks
822 *
823 * sdstart is called from scsipi_put_xs and all its callers
824 * release the lock afterwards. So releasing it here
825 * doesn't matter.
826 */
827 mutex_exit(chan_mtx(chan));
828
829 dk_start(dksc, NULL);
830
831 mutex_enter(chan_mtx(chan));
832 }
833
834 static void
835 sddone(struct scsipi_xfer *xs, int error)
836 {
837 struct sd_softc *sd = device_private(xs->xs_periph->periph_dev);
838 struct dk_softc *dksc = &sd->sc_dksc;
839 struct buf *bp = xs->bp;
840
841 if (sd->flags & SDF_FLUSHING) {
842 /* Flush completed, no longer dirty. */
843 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
844 }
845
846 if (bp) {
847 bp->b_error = error;
848 bp->b_resid = xs->resid;
849 if (error) {
850 /* on a read/write error bp->b_resid is zero, so fix */
851 bp->b_resid = bp->b_bcount;
852 }
853
854 dk_done(dksc, bp);
855 /* dk_start is called from scsipi_complete */
856 }
857 }
858
859 static void
860 sdminphys(struct buf *bp)
861 {
862 struct sd_softc *sd = device_lookup_private(&sd_cd, SDUNIT(bp->b_dev));
863 struct dk_softc *dksc = &sd->sc_dksc;
864 long xmax;
865
866 /*
867 * If the device is ancient, we want to make sure that
868 * the transfer fits into a 6-byte cdb.
869 *
870 * XXX Note that the SCSI-I spec says that 256-block transfers
871 * are allowed in a 6-byte read/write, and are specified
872 * by settng the "length" to 0. However, we're conservative
873 * here, allowing only 255-block transfers in case an
874 * ancient device gets confused by length == 0. A length of 0
875 * in a 10-byte read/write actually means 0 blocks.
876 */
877 if ((sd->flags & SDF_ANCIENT) &&
878 ((sd->sc_periph->periph_flags &
879 (PERIPH_REMOVABLE | PERIPH_MEDIA_LOADED)) != PERIPH_REMOVABLE)) {
880 xmax = dksc->sc_dkdev.dk_geom.dg_secsize * 0xff;
881
882 if (bp->b_bcount > xmax)
883 bp->b_bcount = xmax;
884 }
885
886 scsipi_adapter_minphys(sd->sc_periph->periph_channel, bp);
887 }
888
889 static void
890 sd_iosize(device_t dev, int *count)
891 {
892 struct buf B;
893 int bmaj;
894
895 bmaj = bdevsw_lookup_major(&sd_bdevsw);
896 B.b_dev = MAKESDDEV(bmaj,device_unit(dev),RAW_PART);
897 B.b_bcount = *count;
898
899 sdminphys(&B);
900
901 *count = B.b_bcount;
902 }
903
904 static int
905 sdread(dev_t dev, struct uio *uio, int ioflag)
906 {
907
908 return (physio(sdstrategy, NULL, dev, B_READ, sdminphys, uio));
909 }
910
911 static int
912 sdwrite(dev_t dev, struct uio *uio, int ioflag)
913 {
914
915 return (physio(sdstrategy, NULL, dev, B_WRITE, sdminphys, uio));
916 }
917
918 /*
919 * Perform special action on behalf of the user
920 * Knows about the internals of this device
921 */
922 static int
923 sdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
924 {
925 struct sd_softc *sd = device_lookup_private(&sd_cd, SDUNIT(dev));
926 struct dk_softc *dksc = &sd->sc_dksc;
927 struct scsipi_periph *periph = sd->sc_periph;
928
929 int part = SDPART(dev);
930 int error;
931
932 SC_DEBUG(sd->sc_periph, SCSIPI_DB2, ("sdioctl 0x%lx ", cmd));
933
934 /*
935 * If the device is not valid, some IOCTLs can still be
936 * handled on the raw partition. Check this here.
937 */
938 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0 &&
939 part != RAW_PART)
940 return (EIO);
941
942 switch (cmd) {
943 case DIOCLOCK:
944 if (periph->periph_flags & PERIPH_REMOVABLE)
945 return (scsipi_prevent(periph,
946 (*(int *)addr) ?
947 SPAMR_PREVENT_DT : SPAMR_ALLOW, 0));
948 else
949 return (ENOTTY);
950
951 case DIOCEJECT:
952 if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
953 return (ENOTTY);
954 if (*(int *)addr == 0) {
955 /*
956 * Don't force eject: check that we are the only
957 * partition open. If so, unlock it.
958 */
959 if (DK_BUSY(dksc, part) == 0) {
960 error = scsipi_prevent(periph, SPAMR_ALLOW,
961 XS_CTL_IGNORE_NOT_READY);
962 if (error)
963 return (error);
964 } else {
965 return (EBUSY);
966 }
967 }
968 /* FALLTHROUGH */
969 case ODIOCEJECT:
970 return ((periph->periph_flags & PERIPH_REMOVABLE) == 0 ?
971 ENOTTY : scsipi_start(periph, SSS_STOP|SSS_LOEJ, 0));
972
973 case DIOCGCACHE:
974 return (sd_getcache(sd, (int *) addr));
975
976 case DIOCSCACHE:
977 if ((flag & FWRITE) == 0)
978 return (EBADF);
979 return (sd_setcache(sd, *(int *) addr));
980
981 case DIOCCACHESYNC:
982 /*
983 * XXX Do we really need to care about having a writable
984 * file descriptor here?
985 */
986 if ((flag & FWRITE) == 0)
987 return (EBADF);
988 if (((sd->flags & SDF_DIRTY) != 0 || *(int *)addr != 0)) {
989 error = sd_flush(sd, 0);
990 if (error) {
991 sd->flags &= ~SDF_FLUSHING;
992 return (error);
993 }
994 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
995 }
996 return (0);
997
998 default:
999 error = dk_ioctl(dksc, dev, cmd, addr, flag, l);
1000 if (error == ENOTTY)
1001 error = scsipi_do_ioctl(periph, dev, cmd, addr, flag, l);
1002 return (error);
1003 }
1004
1005 #ifdef DIAGNOSTIC
1006 panic("sdioctl: impossible");
1007 #endif
1008 }
1009
1010 static void
1011 sd_label(device_t self, struct disklabel *lp)
1012 {
1013 struct sd_softc *sd = device_private(self);
1014
1015 strncpy(lp->d_typename, sd->name, 16);
1016 lp->d_rpm = sd->params.rot_rate;
1017 if (sd->sc_periph->periph_flags & PERIPH_REMOVABLE)
1018 lp->d_flags |= D_REMOVABLE;
1019 }
1020
1021 static bool
1022 sd_shutdown(device_t self, int how)
1023 {
1024 struct sd_softc *sd = device_private(self);
1025 struct dk_softc *dksc = &sd->sc_dksc;
1026
1027 /*
1028 * If the disk cache needs to be flushed, and the disk supports
1029 * it, flush it. We're cold at this point, so we poll for
1030 * completion.
1031 */
1032 if ((sd->flags & SDF_DIRTY) != 0) {
1033 if (sd_flush(sd, XS_CTL_NOSLEEP|XS_CTL_POLL)) {
1034 aprint_error_dev(dksc->sc_dev,
1035 "cache synchronization failed\n");
1036 sd->flags &= ~SDF_FLUSHING;
1037 } else
1038 sd->flags &= ~(SDF_FLUSHING|SDF_DIRTY);
1039 }
1040 return true;
1041 }
1042
1043 static bool
1044 sd_suspend(device_t dv, const pmf_qual_t *qual)
1045 {
1046 return sd_shutdown(dv, boothowto); /* XXX no need to poll */
1047 }
1048
1049 /*
1050 * Check Errors
1051 */
1052 static int
1053 sd_interpret_sense(struct scsipi_xfer *xs)
1054 {
1055 struct scsipi_periph *periph = xs->xs_periph;
1056 struct scsipi_channel *chan = periph->periph_channel;
1057 struct scsi_sense_data *sense = &xs->sense.scsi_sense;
1058 struct sd_softc *sd = device_private(periph->periph_dev);
1059 struct dk_softc *dksc = &sd->sc_dksc;
1060 int error, retval = EJUSTRETURN;
1061
1062 /*
1063 * If the periph is already recovering, just do the normal
1064 * error processing.
1065 */
1066 if (periph->periph_flags & PERIPH_RECOVERING)
1067 return (retval);
1068
1069 /*
1070 * Ignore errors from accessing illegal fields (e.g. trying to
1071 * lock the door of a digicam, which doesn't have a door that
1072 * can be locked) for the SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL command.
1073 */
1074 if (xs->cmd->opcode == SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL &&
1075 SSD_SENSE_KEY(sense->flags) == SKEY_ILLEGAL_REQUEST &&
1076 sense->asc == 0x24 &&
1077 sense->ascq == 0x00) { /* Illegal field in CDB */
1078 if (!(xs->xs_control & XS_CTL_SILENT)) {
1079 scsipi_printaddr(periph);
1080 printf("no door lock\n");
1081 }
1082 xs->xs_control |= XS_CTL_IGNORE_ILLEGAL_REQUEST;
1083 return (retval);
1084 }
1085
1086
1087
1088 /*
1089 * If the device is not open yet, let the generic code handle it.
1090 */
1091 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
1092 return (retval);
1093
1094 /*
1095 * If it isn't a extended or extended/deferred error, let
1096 * the generic code handle it.
1097 */
1098 if (SSD_RCODE(sense->response_code) != SSD_RCODE_CURRENT &&
1099 SSD_RCODE(sense->response_code) != SSD_RCODE_DEFERRED)
1100 return (retval);
1101
1102 if (SSD_SENSE_KEY(sense->flags) == SKEY_NOT_READY &&
1103 sense->asc == 0x4) {
1104 if (sense->ascq == 0x01) {
1105 /*
1106 * Unit In The Process Of Becoming Ready.
1107 */
1108 printf("%s: waiting for pack to spin up...\n",
1109 dksc->sc_xname);
1110 if (!callout_pending(&periph->periph_callout))
1111 scsipi_periph_freeze(periph, 1);
1112 callout_reset(&periph->periph_callout,
1113 5 * hz, scsipi_periph_timed_thaw, periph);
1114 retval = ERESTART;
1115 } else if (sense->ascq == 0x02) {
1116 printf("%s: pack is stopped, restarting...\n",
1117 dksc->sc_xname);
1118 mutex_enter(chan_mtx(chan));
1119 periph->periph_flags |= PERIPH_RECOVERING;
1120 mutex_exit(chan_mtx(chan));
1121 error = scsipi_start(periph, SSS_START,
1122 XS_CTL_URGENT|XS_CTL_HEAD_TAG|
1123 XS_CTL_THAW_PERIPH|XS_CTL_FREEZE_PERIPH);
1124 if (error) {
1125 aprint_error_dev(dksc->sc_dev,
1126 "unable to restart pack\n");
1127 retval = error;
1128 } else
1129 retval = ERESTART;
1130 mutex_enter(chan_mtx(chan));
1131 periph->periph_flags &= ~PERIPH_RECOVERING;
1132 mutex_exit(chan_mtx(chan));
1133 }
1134 }
1135 if (SSD_SENSE_KEY(sense->flags) == SKEY_MEDIUM_ERROR &&
1136 sense->asc == 0x31 &&
1137 sense->ascq == 0x00) { /* maybe for any asq ? */
1138 /* Medium Format Corrupted */
1139 retval = EFTYPE;
1140 }
1141 return (retval);
1142 }
1143
1144
1145 static int
1146 sdsize(dev_t dev)
1147 {
1148 struct sd_softc *sd;
1149 struct dk_softc *dksc;
1150 int unit;
1151
1152 unit = SDUNIT(dev);
1153 sd = device_lookup_private(&sd_cd, unit);
1154 if (sd == NULL)
1155 return (-1);
1156 dksc = &sd->sc_dksc;
1157
1158 if (!device_is_active(dksc->sc_dev))
1159 return (-1);
1160
1161 return dk_size(dksc, dev);
1162 }
1163
1164 /* #define SD_DUMP_NOT_TRUSTED if you just want to watch */
1165 static struct scsipi_xfer sx;
1166
1167 /*
1168 * dump all of physical memory into the partition specified, starting
1169 * at offset 'dumplo' into the partition.
1170 */
1171 static int
1172 sddump(dev_t dev, daddr_t blkno, void *va, size_t size)
1173 {
1174 struct sd_softc *sd;
1175 struct dk_softc *dksc;
1176 struct scsipi_periph *periph;
1177 int unit;
1178
1179 unit = SDUNIT(dev);
1180 if ((sd = device_lookup_private(&sd_cd, unit)) == NULL)
1181 return (ENXIO);
1182 dksc = &sd->sc_dksc;
1183
1184 if (!device_is_active(dksc->sc_dev))
1185 return (ENODEV);
1186
1187 periph = sd->sc_periph;
1188
1189 /* Make sure it was initialized. */
1190 if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
1191 return (ENXIO);
1192
1193 return dk_dump(dksc, dev, blkno, va, size);
1194 }
1195
1196 static int
1197 sd_dumpblocks(device_t dev, void *va, daddr_t blkno, int nblk)
1198 {
1199 struct sd_softc *sd = device_private(dev);
1200 struct dk_softc *dksc = &sd->sc_dksc;
1201 struct disk_geom *dg = &dksc->sc_dkdev.dk_geom;
1202 struct scsipi_rw_10 cmd; /* write command */
1203 struct scsipi_xfer *xs; /* ... convenience */
1204 struct scsipi_periph *periph;
1205 struct scsipi_channel *chan;
1206 size_t sectorsize;
1207
1208 periph = sd->sc_periph;
1209 chan = periph->periph_channel;
1210
1211 sectorsize = dg->dg_secsize;
1212
1213 xs = &sx;
1214
1215 #ifndef SD_DUMP_NOT_TRUSTED
1216 /*
1217 * Fill out the scsi command
1218 */
1219 memset(&cmd, 0, sizeof(cmd));
1220 cmd.opcode = WRITE_10;
1221 _lto4b(blkno, cmd.addr);
1222 _lto2b(nblk, cmd.length);
1223 /*
1224 * Fill out the scsipi_xfer structure
1225 * Note: we cannot sleep as we may be an interrupt
1226 * don't use scsipi_command() as it may want to wait
1227 * for an xs.
1228 */
1229 memset(xs, 0, sizeof(sx));
1230 xs->xs_control |= XS_CTL_NOSLEEP | XS_CTL_POLL |
1231 XS_CTL_DATA_OUT;
1232 xs->xs_status = 0;
1233 xs->xs_periph = periph;
1234 xs->xs_retries = SDRETRIES;
1235 xs->timeout = 10000; /* 10000 millisecs for a disk ! */
1236 xs->cmd = (struct scsipi_generic *)&cmd;
1237 xs->cmdlen = sizeof(cmd);
1238 xs->resid = nblk * sectorsize;
1239 xs->error = XS_NOERROR;
1240 xs->bp = 0;
1241 xs->data = va;
1242 xs->datalen = nblk * sectorsize;
1243 callout_init(&xs->xs_callout, 0);
1244
1245 /*
1246 * Pass all this info to the scsi driver.
1247 */
1248 scsipi_adapter_request(chan, ADAPTER_REQ_RUN_XFER, xs);
1249 if ((xs->xs_status & XS_STS_DONE) == 0 ||
1250 xs->error != XS_NOERROR)
1251 return (EIO);
1252 #else /* SD_DUMP_NOT_TRUSTED */
1253 /* Let's just talk about this first... */
1254 printf("sd%d: dump addr 0x%x, blk %d\n", unit, va, blkno);
1255 delay(500 * 1000); /* half a second */
1256 #endif /* SD_DUMP_NOT_TRUSTED */
1257
1258 return (0);
1259 }
1260
1261 static int
1262 sd_mode_sense(struct sd_softc *sd, u_int8_t byte2, void *sense, size_t size,
1263 int page, int flags, int *big)
1264 {
1265
1266 if ((sd->sc_periph->periph_quirks & PQUIRK_ONLYBIG) &&
1267 !(sd->sc_periph->periph_quirks & PQUIRK_NOBIGMODESENSE)) {
1268 *big = 1;
1269 return scsipi_mode_sense_big(sd->sc_periph, byte2, page, sense,
1270 size + sizeof(struct scsi_mode_parameter_header_10),
1271 flags, SDRETRIES, 6000);
1272 } else {
1273 *big = 0;
1274 return scsipi_mode_sense(sd->sc_periph, byte2, page, sense,
1275 size + sizeof(struct scsi_mode_parameter_header_6),
1276 flags, SDRETRIES, 6000);
1277 }
1278 }
1279
1280 static int
1281 sd_mode_select(struct sd_softc *sd, u_int8_t byte2, void *sense, size_t size,
1282 int flags, int big)
1283 {
1284
1285 if (big) {
1286 struct scsi_mode_parameter_header_10 *header = sense;
1287
1288 _lto2b(0, header->data_length);
1289 return scsipi_mode_select_big(sd->sc_periph, byte2, sense,
1290 size + sizeof(struct scsi_mode_parameter_header_10),
1291 flags, SDRETRIES, 6000);
1292 } else {
1293 struct scsi_mode_parameter_header_6 *header = sense;
1294
1295 header->data_length = 0;
1296 return scsipi_mode_select(sd->sc_periph, byte2, sense,
1297 size + sizeof(struct scsi_mode_parameter_header_6),
1298 flags, SDRETRIES, 6000);
1299 }
1300 }
1301
1302 /*
1303 * sd_validate_blksize:
1304 *
1305 * Validate the block size. Print error if periph is specified,
1306 */
1307 static int
1308 sd_validate_blksize(struct scsipi_periph *periph, int len)
1309 {
1310
1311 switch (len) {
1312 case 256:
1313 case 512:
1314 case 1024:
1315 case 2048:
1316 case 4096:
1317 return 1;
1318 }
1319
1320 if (periph) {
1321 scsipi_printaddr(periph);
1322 printf("%s sector size: 0x%x. Defaulting to %d bytes.\n",
1323 (len ^ (1 << (ffs(len) - 1))) ?
1324 "preposterous" : "unsupported",
1325 len, SD_DEFAULT_BLKSIZE);
1326 }
1327
1328 return 0;
1329 }
1330
1331 /*
1332 * sd_read_capacity:
1333 *
1334 * Find out from the device what its capacity is.
1335 */
1336 static u_int64_t
1337 sd_read_capacity(struct scsipi_periph *periph, int *blksize, int flags)
1338 {
1339 union {
1340 struct scsipi_read_capacity_10 cmd;
1341 struct scsipi_read_capacity_16 cmd16;
1342 } cmd;
1343 union {
1344 struct scsipi_read_capacity_10_data data;
1345 struct scsipi_read_capacity_16_data data16;
1346 } *datap;
1347 uint64_t rv;
1348
1349 memset(&cmd, 0, sizeof(cmd));
1350 cmd.cmd.opcode = READ_CAPACITY_10;
1351
1352 /*
1353 * Don't allocate data buffer on stack;
1354 * The lower driver layer might use the same stack and
1355 * if it uses region which is in the same cacheline,
1356 * cache flush ops against the data buffer won't work properly.
1357 */
1358 datap = malloc(sizeof(*datap), M_TEMP, M_WAITOK);
1359 if (datap == NULL)
1360 return 0;
1361
1362 /*
1363 * If the command works, interpret the result as a 4 byte
1364 * number of blocks
1365 */
1366 rv = 0;
1367 memset(datap, 0, sizeof(datap->data));
1368 if (scsipi_command(periph, (void *)&cmd.cmd, sizeof(cmd.cmd),
1369 (void *)datap, sizeof(datap->data), SCSIPIRETRIES, 20000, NULL,
1370 flags | XS_CTL_DATA_IN | XS_CTL_SILENT) != 0)
1371 goto out;
1372
1373 if (_4btol(datap->data.addr) != 0xffffffff) {
1374 *blksize = _4btol(datap->data.length);
1375 rv = _4btol(datap->data.addr) + 1;
1376 goto out;
1377 }
1378
1379 /*
1380 * Device is larger than can be reflected by READ CAPACITY (10).
1381 * Try READ CAPACITY (16).
1382 */
1383
1384 memset(&cmd, 0, sizeof(cmd));
1385 cmd.cmd16.opcode = READ_CAPACITY_16;
1386 cmd.cmd16.byte2 = SRC16_SERVICE_ACTION;
1387 _lto4b(sizeof(datap->data16), cmd.cmd16.len);
1388
1389 memset(datap, 0, sizeof(datap->data16));
1390 if (scsipi_command(periph, (void *)&cmd.cmd16, sizeof(cmd.cmd16),
1391 (void *)datap, sizeof(datap->data16), SCSIPIRETRIES, 20000, NULL,
1392 flags | XS_CTL_DATA_IN | XS_CTL_SILENT) != 0)
1393 goto out;
1394
1395 *blksize = _4btol(datap->data16.length);
1396 rv = _8btol(datap->data16.addr) + 1;
1397
1398 out:
1399 free(datap, M_TEMP);
1400 return rv;
1401 }
1402
1403 static int
1404 sd_get_simplifiedparms(struct sd_softc *sd, struct disk_parms *dp, int flags)
1405 {
1406 struct {
1407 struct scsi_mode_parameter_header_6 header;
1408 /* no block descriptor */
1409 u_int8_t pg_code; /* page code (should be 6) */
1410 u_int8_t pg_length; /* page length (should be 11) */
1411 u_int8_t wcd; /* bit0: cache disable */
1412 u_int8_t lbs[2]; /* logical block size */
1413 u_int8_t size[5]; /* number of log. blocks */
1414 u_int8_t pp; /* power/performance */
1415 u_int8_t flags;
1416 u_int8_t resvd;
1417 } scsipi_sense;
1418 u_int64_t blocks;
1419 int error, blksize;
1420
1421 /*
1422 * sd_read_capacity (ie "read capacity") and mode sense page 6
1423 * give the same information. Do both for now, and check
1424 * for consistency.
1425 * XXX probably differs for removable media
1426 */
1427 dp->blksize = SD_DEFAULT_BLKSIZE;
1428 if ((blocks = sd_read_capacity(sd->sc_periph, &blksize, flags)) == 0)
1429 return (SDGP_RESULT_OFFLINE); /* XXX? */
1430
1431 error = scsipi_mode_sense(sd->sc_periph, SMS_DBD, 6,
1432 &scsipi_sense.header, sizeof(scsipi_sense),
1433 flags, SDRETRIES, 6000);
1434
1435 if (error != 0)
1436 return (SDGP_RESULT_OFFLINE); /* XXX? */
1437
1438 dp->blksize = blksize;
1439 if (!sd_validate_blksize(NULL, dp->blksize))
1440 dp->blksize = _2btol(scsipi_sense.lbs);
1441 if (!sd_validate_blksize(sd->sc_periph, dp->blksize))
1442 dp->blksize = SD_DEFAULT_BLKSIZE;
1443
1444 /*
1445 * Create a pseudo-geometry.
1446 */
1447 dp->heads = 64;
1448 dp->sectors = 32;
1449 dp->cyls = blocks / (dp->heads * dp->sectors);
1450 dp->disksize = _5btol(scsipi_sense.size);
1451 if (dp->disksize <= UINT32_MAX && dp->disksize != blocks) {
1452 printf("RBC size: mode sense=%llu, get cap=%llu\n",
1453 (unsigned long long)dp->disksize,
1454 (unsigned long long)blocks);
1455 dp->disksize = blocks;
1456 }
1457 dp->disksize512 = (dp->disksize * dp->blksize) / DEV_BSIZE;
1458
1459 return (SDGP_RESULT_OK);
1460 }
1461
1462 /*
1463 * Get the scsi driver to send a full inquiry to the * device and use the
1464 * results to fill out the disk parameter structure.
1465 */
1466 static int
1467 sd_get_capacity(struct sd_softc *sd, struct disk_parms *dp, int flags)
1468 {
1469 u_int64_t blocks;
1470 int error, blksize;
1471 #if 0
1472 int i;
1473 u_int8_t *p;
1474 #endif
1475
1476 dp->disksize = blocks = sd_read_capacity(sd->sc_periph, &blksize,
1477 flags);
1478 if (blocks == 0) {
1479 struct scsipi_read_format_capacities cmd;
1480 struct {
1481 struct scsipi_capacity_list_header header;
1482 struct scsipi_capacity_descriptor desc;
1483 } __packed data;
1484
1485 memset(&cmd, 0, sizeof(cmd));
1486 memset(&data, 0, sizeof(data));
1487 cmd.opcode = READ_FORMAT_CAPACITIES;
1488 _lto2b(sizeof(data), cmd.length);
1489
1490 error = scsipi_command(sd->sc_periph,
1491 (void *)&cmd, sizeof(cmd), (void *)&data, sizeof(data),
1492 SDRETRIES, 20000, NULL,
1493 flags | XS_CTL_DATA_IN);
1494 if (error == EFTYPE) {
1495 /* Medium Format Corrupted, handle as not formatted */
1496 return (SDGP_RESULT_UNFORMATTED);
1497 }
1498 if (error || data.header.length == 0)
1499 return (SDGP_RESULT_OFFLINE);
1500
1501 #if 0
1502 printf("rfc: length=%d\n", data.header.length);
1503 printf("rfc result:"); for (i = sizeof(struct scsipi_capacity_list_header) + data.header.length, p = (void *)&data; i; i--, p++) printf(" %02x", *p); printf("\n");
1504 #endif
1505 switch (data.desc.byte5 & SCSIPI_CAP_DESC_CODE_MASK) {
1506 case SCSIPI_CAP_DESC_CODE_RESERVED:
1507 case SCSIPI_CAP_DESC_CODE_FORMATTED:
1508 break;
1509
1510 case SCSIPI_CAP_DESC_CODE_UNFORMATTED:
1511 return (SDGP_RESULT_UNFORMATTED);
1512
1513 case SCSIPI_CAP_DESC_CODE_NONE:
1514 return (SDGP_RESULT_OFFLINE);
1515 }
1516
1517 dp->disksize = blocks = _4btol(data.desc.nblks);
1518 if (blocks == 0)
1519 return (SDGP_RESULT_OFFLINE); /* XXX? */
1520
1521 blksize = _3btol(data.desc.blklen);
1522
1523 } else if (!sd_validate_blksize(NULL, blksize)) {
1524 struct sd_mode_sense_data scsipi_sense;
1525 int big, bsize;
1526 struct scsi_general_block_descriptor *bdesc;
1527
1528 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1529 error = sd_mode_sense(sd, 0, &scsipi_sense,
1530 sizeof(scsipi_sense.blk_desc), 0, flags | XS_CTL_SILENT, &big);
1531 if (!error) {
1532 if (big) {
1533 bdesc = (void *)(&scsipi_sense.header.big + 1);
1534 bsize = _2btol(scsipi_sense.header.big.blk_desc_len);
1535 } else {
1536 bdesc = (void *)(&scsipi_sense.header.small + 1);
1537 bsize = scsipi_sense.header.small.blk_desc_len;
1538 }
1539
1540 #if 0
1541 printf("page 0 sense:"); for (i = sizeof(scsipi_sense), p = (void *)&scsipi_sense; i; i--, p++) printf(" %02x", *p); printf("\n");
1542 printf("page 0 bsize=%d\n", bsize);
1543 printf("page 0 ok\n");
1544 #endif
1545
1546 if (bsize >= 8) {
1547 blksize = _3btol(bdesc->blklen);
1548 }
1549 }
1550 }
1551
1552 if (!sd_validate_blksize(sd->sc_periph, blksize))
1553 blksize = SD_DEFAULT_BLKSIZE;
1554
1555 dp->blksize = blksize;
1556 dp->disksize512 = (blocks * dp->blksize) / DEV_BSIZE;
1557 return (0);
1558 }
1559
1560 static int
1561 sd_get_parms_page4(struct sd_softc *sd, struct disk_parms *dp, int flags)
1562 {
1563 struct sd_mode_sense_data scsipi_sense;
1564 int error;
1565 int big, byte2;
1566 size_t poffset;
1567 union scsi_disk_pages *pages;
1568
1569 byte2 = SMS_DBD;
1570 again:
1571 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1572 error = sd_mode_sense(sd, byte2, &scsipi_sense,
1573 (byte2 ? 0 : sizeof(scsipi_sense.blk_desc)) +
1574 sizeof(scsipi_sense.pages.rigid_geometry), 4,
1575 flags | XS_CTL_SILENT, &big);
1576 if (error) {
1577 if (byte2 == SMS_DBD) {
1578 /* No result; try once more with DBD off */
1579 byte2 = 0;
1580 goto again;
1581 }
1582 return (error);
1583 }
1584
1585 if (big) {
1586 poffset = sizeof scsipi_sense.header.big;
1587 poffset += _2btol(scsipi_sense.header.big.blk_desc_len);
1588 } else {
1589 poffset = sizeof scsipi_sense.header.small;
1590 poffset += scsipi_sense.header.small.blk_desc_len;
1591 }
1592
1593 if (poffset > sizeof(scsipi_sense) - sizeof(pages->rigid_geometry))
1594 return ERESTART;
1595
1596 pages = (void *)((u_long)&scsipi_sense + poffset);
1597 #if 0
1598 {
1599 size_t i;
1600 u_int8_t *p;
1601
1602 printf("page 4 sense:");
1603 for (i = sizeof(scsipi_sense), p = (void *)&scsipi_sense; i;
1604 i--, p++)
1605 printf(" %02x", *p);
1606 printf("\n");
1607 printf("page 4 pg_code=%d sense=%p/%p\n",
1608 pages->rigid_geometry.pg_code, &scsipi_sense, pages);
1609 }
1610 #endif
1611
1612 if ((pages->rigid_geometry.pg_code & PGCODE_MASK) != 4)
1613 return (ERESTART);
1614
1615 SC_DEBUG(sd->sc_periph, SCSIPI_DB3,
1616 ("%d cyls, %d heads, %d precomp, %d red_write, %d land_zone\n",
1617 _3btol(pages->rigid_geometry.ncyl),
1618 pages->rigid_geometry.nheads,
1619 _2btol(pages->rigid_geometry.st_cyl_wp),
1620 _2btol(pages->rigid_geometry.st_cyl_rwc),
1621 _2btol(pages->rigid_geometry.land_zone)));
1622
1623 /*
1624 * KLUDGE!! (for zone recorded disks)
1625 * give a number of sectors so that sec * trks * cyls
1626 * is <= disk_size
1627 * can lead to wasted space! THINK ABOUT THIS !
1628 */
1629 dp->heads = pages->rigid_geometry.nheads;
1630 dp->cyls = _3btol(pages->rigid_geometry.ncyl);
1631 if (dp->heads == 0 || dp->cyls == 0)
1632 return (ERESTART);
1633 dp->sectors = dp->disksize / (dp->heads * dp->cyls); /* XXX */
1634
1635 dp->rot_rate = _2btol(pages->rigid_geometry.rpm);
1636 if (dp->rot_rate == 0)
1637 dp->rot_rate = 3600;
1638
1639 #if 0
1640 printf("page 4 ok\n");
1641 #endif
1642 return (0);
1643 }
1644
1645 static int
1646 sd_get_parms_page5(struct sd_softc *sd, struct disk_parms *dp, int flags)
1647 {
1648 struct sd_mode_sense_data scsipi_sense;
1649 int error;
1650 int big, byte2;
1651 size_t poffset;
1652 union scsi_disk_pages *pages;
1653
1654 byte2 = SMS_DBD;
1655 again:
1656 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1657 error = sd_mode_sense(sd, 0, &scsipi_sense,
1658 (byte2 ? 0 : sizeof(scsipi_sense.blk_desc)) +
1659 sizeof(scsipi_sense.pages.flex_geometry), 5,
1660 flags | XS_CTL_SILENT, &big);
1661 if (error) {
1662 if (byte2 == SMS_DBD) {
1663 /* No result; try once more with DBD off */
1664 byte2 = 0;
1665 goto again;
1666 }
1667 return (error);
1668 }
1669
1670 if (big) {
1671 poffset = sizeof scsipi_sense.header.big;
1672 poffset += _2btol(scsipi_sense.header.big.blk_desc_len);
1673 } else {
1674 poffset = sizeof scsipi_sense.header.small;
1675 poffset += scsipi_sense.header.small.blk_desc_len;
1676 }
1677
1678 if (poffset > sizeof(scsipi_sense) - sizeof(pages->flex_geometry))
1679 return ERESTART;
1680
1681 pages = (void *)((u_long)&scsipi_sense + poffset);
1682 #if 0
1683 {
1684 size_t i;
1685 u_int8_t *p;
1686
1687 printf("page 5 sense:");
1688 for (i = sizeof(scsipi_sense), p = (void *)&scsipi_sense; i;
1689 i--, p++)
1690 printf(" %02x", *p);
1691 printf("\n");
1692 printf("page 5 pg_code=%d sense=%p/%p\n",
1693 pages->flex_geometry.pg_code, &scsipi_sense, pages);
1694 }
1695 #endif
1696
1697 if ((pages->flex_geometry.pg_code & PGCODE_MASK) != 5)
1698 return (ERESTART);
1699
1700 SC_DEBUG(sd->sc_periph, SCSIPI_DB3,
1701 ("%d cyls, %d heads, %d sec, %d bytes/sec\n",
1702 _3btol(pages->flex_geometry.ncyl),
1703 pages->flex_geometry.nheads,
1704 pages->flex_geometry.ph_sec_tr,
1705 _2btol(pages->flex_geometry.bytes_s)));
1706
1707 dp->heads = pages->flex_geometry.nheads;
1708 dp->cyls = _2btol(pages->flex_geometry.ncyl);
1709 dp->sectors = pages->flex_geometry.ph_sec_tr;
1710 if (dp->heads == 0 || dp->cyls == 0 || dp->sectors == 0)
1711 return (ERESTART);
1712
1713 dp->rot_rate = _2btol(pages->rigid_geometry.rpm);
1714 if (dp->rot_rate == 0)
1715 dp->rot_rate = 3600;
1716
1717 #if 0
1718 printf("page 5 ok\n");
1719 #endif
1720 return (0);
1721 }
1722
1723 static int
1724 sd_get_parms(struct sd_softc *sd, struct disk_parms *dp, int flags)
1725 {
1726 struct dk_softc *dksc = &sd->sc_dksc;
1727 int error;
1728
1729 /*
1730 * If offline, the SDEV_MEDIA_LOADED flag will be
1731 * cleared by the caller if necessary.
1732 */
1733 if (sd->type == T_SIMPLE_DIRECT) {
1734 error = sd_get_simplifiedparms(sd, dp, flags);
1735 if (!error)
1736 goto setprops;
1737 return (error);
1738 }
1739
1740 error = sd_get_capacity(sd, dp, flags);
1741 if (error)
1742 return (error);
1743
1744 if (sd->type == T_OPTICAL)
1745 goto page0;
1746
1747 if (sd->sc_periph->periph_flags & PERIPH_REMOVABLE) {
1748 if (!sd_get_parms_page5(sd, dp, flags) ||
1749 !sd_get_parms_page4(sd, dp, flags))
1750 goto setprops;
1751 } else {
1752 if (!sd_get_parms_page4(sd, dp, flags) ||
1753 !sd_get_parms_page5(sd, dp, flags))
1754 goto setprops;
1755 }
1756
1757 page0:
1758 printf("%s: fabricating a geometry\n", dksc->sc_xname);
1759 /* Try calling driver's method for figuring out geometry. */
1760 if (!sd->sc_periph->periph_channel->chan_adapter->adapt_getgeom ||
1761 !(*sd->sc_periph->periph_channel->chan_adapter->adapt_getgeom)
1762 (sd->sc_periph, dp, dp->disksize)) {
1763 /*
1764 * Use adaptec standard fictitious geometry
1765 * this depends on which controller (e.g. 1542C is
1766 * different. but we have to put SOMETHING here..)
1767 */
1768 dp->heads = 64;
1769 dp->sectors = 32;
1770 dp->cyls = dp->disksize / (64 * 32);
1771 }
1772 dp->rot_rate = 3600;
1773
1774 setprops:
1775 sd_set_geometry(sd);
1776
1777 return (SDGP_RESULT_OK);
1778 }
1779
1780 static int
1781 sd_flush(struct sd_softc *sd, int flags)
1782 {
1783 struct scsipi_periph *periph = sd->sc_periph;
1784 struct scsi_synchronize_cache_10 cmd;
1785
1786 /*
1787 * If the device is SCSI-2, issue a SYNCHRONIZE CACHE.
1788 * We issue with address 0 length 0, which should be
1789 * interpreted by the device as "all remaining blocks
1790 * starting at address 0". We ignore ILLEGAL REQUEST
1791 * in the event that the command is not supported by
1792 * the device, and poll for completion so that we know
1793 * that the cache has actually been flushed.
1794 *
1795 * Unless, that is, the device can't handle the SYNCHRONIZE CACHE
1796 * command, as indicated by our quirks flags.
1797 *
1798 * XXX What about older devices?
1799 */
1800 if (periph->periph_version < 2 ||
1801 (periph->periph_quirks & PQUIRK_NOSYNCCACHE))
1802 return (0);
1803
1804 sd->flags |= SDF_FLUSHING;
1805 memset(&cmd, 0, sizeof(cmd));
1806 cmd.opcode = SCSI_SYNCHRONIZE_CACHE_10;
1807
1808 return (scsipi_command(periph, (void *)&cmd, sizeof(cmd), 0, 0,
1809 SDRETRIES, 100000, NULL, flags | XS_CTL_IGNORE_ILLEGAL_REQUEST));
1810 }
1811
1812 static int
1813 sd_getcache(struct sd_softc *sd, int *bitsp)
1814 {
1815 struct scsipi_periph *periph = sd->sc_periph;
1816 struct sd_mode_sense_data scsipi_sense;
1817 int error, bits = 0;
1818 int big;
1819 union scsi_disk_pages *pages;
1820 uint8_t dev_spec;
1821
1822 /* only SCSI-2 and later supported */
1823 if (periph->periph_version < 2)
1824 return (EOPNOTSUPP);
1825
1826 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1827 error = sd_mode_sense(sd, SMS_DBD, &scsipi_sense,
1828 sizeof(scsipi_sense.pages.caching_params), 8, XS_CTL_SILENT, &big);
1829 if (error)
1830 return (error);
1831
1832 if (big) {
1833 pages = (void *)(&scsipi_sense.header.big + 1);
1834 dev_spec = scsipi_sense.header.big.dev_spec;
1835 } else {
1836 pages = (void *)(&scsipi_sense.header.small + 1);
1837 dev_spec = scsipi_sense.header.small.dev_spec;
1838 }
1839
1840 if ((pages->caching_params.flags & CACHING_RCD) == 0)
1841 bits |= DKCACHE_READ;
1842 if (pages->caching_params.flags & CACHING_WCE)
1843 bits |= DKCACHE_WRITE;
1844 if (pages->caching_params.pg_code & PGCODE_PS)
1845 bits |= DKCACHE_SAVE;
1846
1847 /*
1848 * Support for FUA/DPO, defined starting with SCSI-2. Use only
1849 * if device claims to support it, according to the MODE SENSE.
1850 */
1851 if (ISSET(dev_spec, SMH_DSP_DPOFUA))
1852 bits |= DKCACHE_FUA | DKCACHE_DPO;
1853
1854 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1855 error = sd_mode_sense(sd, SMS_DBD, &scsipi_sense,
1856 sizeof(scsipi_sense.pages.caching_params),
1857 SMS_PCTRL_CHANGEABLE|8, XS_CTL_SILENT, &big);
1858 if (error == 0) {
1859 if (big)
1860 pages = (void *)(&scsipi_sense.header.big + 1);
1861 else
1862 pages = (void *)(&scsipi_sense.header.small + 1);
1863
1864 if (pages->caching_params.flags & CACHING_RCD)
1865 bits |= DKCACHE_RCHANGE;
1866 if (pages->caching_params.flags & CACHING_WCE)
1867 bits |= DKCACHE_WCHANGE;
1868 }
1869
1870 *bitsp = bits;
1871
1872 return (0);
1873 }
1874
1875 static int
1876 sd_setcache(struct sd_softc *sd, int bits)
1877 {
1878 struct scsipi_periph *periph = sd->sc_periph;
1879 struct sd_mode_sense_data scsipi_sense;
1880 int error;
1881 uint8_t oflags, byte2 = 0;
1882 int big;
1883 union scsi_disk_pages *pages;
1884
1885 if (periph->periph_version < 2)
1886 return (EOPNOTSUPP);
1887
1888 memset(&scsipi_sense, 0, sizeof(scsipi_sense));
1889 error = sd_mode_sense(sd, SMS_DBD, &scsipi_sense,
1890 sizeof(scsipi_sense.pages.caching_params), 8, 0, &big);
1891 if (error)
1892 return (error);
1893
1894 if (big)
1895 pages = (void *)(&scsipi_sense.header.big + 1);
1896 else
1897 pages = (void *)(&scsipi_sense.header.small + 1);
1898
1899 oflags = pages->caching_params.flags;
1900
1901 if (bits & DKCACHE_READ)
1902 pages->caching_params.flags &= ~CACHING_RCD;
1903 else
1904 pages->caching_params.flags |= CACHING_RCD;
1905
1906 if (bits & DKCACHE_WRITE)
1907 pages->caching_params.flags |= CACHING_WCE;
1908 else
1909 pages->caching_params.flags &= ~CACHING_WCE;
1910
1911 if (oflags == pages->caching_params.flags)
1912 return (0);
1913
1914 pages->caching_params.pg_code &= PGCODE_MASK;
1915
1916 if (bits & DKCACHE_SAVE)
1917 byte2 |= SMS_SP;
1918
1919 return (sd_mode_select(sd, byte2|SMS_PF, &scsipi_sense,
1920 sizeof(struct scsi_mode_page_header) +
1921 pages->caching_params.pg_length, 0, big));
1922 }
1923
1924 static void
1925 sd_set_geometry(struct sd_softc *sd)
1926 {
1927 struct dk_softc *dksc = &sd->sc_dksc;
1928 struct disk_geom *dg = &dksc->sc_dkdev.dk_geom;
1929
1930 memset(dg, 0, sizeof(*dg));
1931
1932 dg->dg_secperunit = sd->params.disksize;
1933 dg->dg_secsize = sd->params.blksize;
1934 dg->dg_nsectors = sd->params.sectors;
1935 dg->dg_ntracks = sd->params.heads;
1936 dg->dg_ncylinders = sd->params.cyls;
1937
1938 disk_set_info(dksc->sc_dev, &dksc->sc_dkdev, NULL);
1939 }
1940