ch.c revision 1.46.2.4 1 /* $NetBSD: ch.c,v 1.46.2.4 2002/01/10 19:58:18 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.46.2.4 2002/01/10 19:58:18 thorpej Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/buf.h>
49 #include <sys/proc.h>
50 #include <sys/user.h>
51 #include <sys/chio.h>
52 #include <sys/device.h>
53 #include <sys/malloc.h>
54 #include <sys/conf.h>
55 #include <sys/fcntl.h>
56 #include <sys/vnode.h>
57 #include <sys/time.h>
58 #include <sys/select.h>
59 #include <sys/poll.h>
60
61 #include <dev/scsipi/scsipi_all.h>
62 #include <dev/scsipi/scsi_all.h>
63 #include <dev/scsipi/scsi_changer.h>
64 #include <dev/scsipi/scsiconf.h>
65
66 #define CHRETRIES 2
67 #define CHUNIT(x) (minor((x)))
68
69 struct ch_softc {
70 struct device sc_dev; /* generic device info */
71 struct scsipi_periph *sc_periph;/* our periph data */
72
73 u_int sc_events; /* event bitmask */
74 struct selinfo sc_selq; /* select/poll queue for events */
75
76 int sc_flags; /* misc. info */
77
78 int sc_picker; /* current picker */
79
80 /*
81 * The following information is obtained from the
82 * element address assignment page.
83 */
84 int sc_firsts[4]; /* firsts, indexed by CHET_* */
85 int sc_counts[4]; /* counts, indexed by CHET_* */
86
87 /*
88 * The following mask defines the legal combinations
89 * of elements for the MOVE MEDIUM command.
90 */
91 u_int8_t sc_movemask[4];
92
93 /*
94 * As above, but for EXCHANGE MEDIUM.
95 */
96 u_int8_t sc_exchangemask[4];
97
98 /*
99 * Quirks; see below.
100 */
101 int sc_settledelay; /* delay for settle */
102
103 };
104
105 /* sc_flags */
106 #define CHF_ROTATE 0x01 /* picker can rotate */
107
108 /* Autoconfiguration glue */
109 int chmatch __P((struct device *, struct cfdata *, void *));
110 void chattach __P((struct device *, struct device *, void *));
111
112 struct cfattach ch_ca = {
113 sizeof(struct ch_softc), chmatch, chattach
114 };
115
116 extern struct cfdriver ch_cd;
117
118 struct scsipi_inquiry_pattern ch_patterns[] = {
119 {T_CHANGER, T_REMOV,
120 "", "", ""},
121 };
122
123 /* SCSI glue */
124 int ch_interpret_sense __P((struct scsipi_xfer *));
125
126 const struct scsipi_periphsw ch_switch = {
127 ch_interpret_sense, /* check our error handler first */
128 NULL, /* no queue; our commands are synchronous */
129 NULL, /* have no async handler */
130 NULL, /* nothing to be done when xfer is done */
131 };
132
133 int ch_move __P((struct ch_softc *, struct changer_move_request *));
134 int ch_exchange __P((struct ch_softc *, struct changer_exchange_request *));
135 int ch_position __P((struct ch_softc *, struct changer_position_request *));
136 int ch_ielem __P((struct ch_softc *));
137 int ch_ousergetelemstatus __P((struct ch_softc *, int, u_int8_t *));
138 int ch_usergetelemstatus __P((struct ch_softc *,
139 struct changer_element_status_request *));
140 int ch_getelemstatus __P((struct ch_softc *, int, int, void *,
141 size_t, int, int));
142 int ch_setvoltag __P((struct ch_softc *,
143 struct changer_set_voltag_request *));
144 int ch_get_params __P((struct ch_softc *, int));
145 void ch_get_quirks __P((struct ch_softc *,
146 struct scsipi_inquiry_pattern *));
147 void ch_event __P((struct ch_softc *, u_int));
148 int ch_map_element __P((struct ch_softc *, u_int16_t, int *, int *));
149
150 void ch_voltag_convert_in __P((const struct changer_volume_tag *,
151 struct changer_voltag *));
152 int ch_voltag_convert_out __P((const struct changer_voltag *,
153 struct changer_volume_tag *));
154
155 /*
156 * SCSI changer quirks.
157 */
158 struct chquirk {
159 struct scsipi_inquiry_pattern cq_match; /* device id pattern */
160 int cq_settledelay; /* settle delay, in seconds */
161 };
162
163 struct chquirk chquirks[] = {
164 {{T_CHANGER, T_REMOV,
165 "SPECTRA", "9000", "0200"},
166 75},
167 };
168
169 int
170 chmatch(parent, match, aux)
171 struct device *parent;
172 struct cfdata *match;
173 void *aux;
174 {
175 struct scsipibus_attach_args *sa = aux;
176 int priority;
177
178 (void)scsipi_inqmatch(&sa->sa_inqbuf,
179 (caddr_t)ch_patterns, sizeof(ch_patterns) / sizeof(ch_patterns[0]),
180 sizeof(ch_patterns[0]), &priority);
181
182 return (priority);
183 }
184
185 void
186 chattach(parent, self, aux)
187 struct device *parent, *self;
188 void *aux;
189 {
190 struct ch_softc *sc = (struct ch_softc *)self;
191 struct scsipibus_attach_args *sa = aux;
192 struct scsipi_periph *periph = sa->sa_periph;
193
194 /* Glue into the SCSI bus */
195 sc->sc_periph = periph;
196 periph->periph_dev = &sc->sc_dev;
197 periph->periph_switch = &ch_switch;
198
199 printf("\n");
200
201 /*
202 * Find out our device's quirks.
203 */
204 ch_get_quirks(sc, &sa->sa_inqbuf);
205
206 /*
207 * Some changers require a long time to settle out, to do
208 * tape inventory, for instance.
209 */
210 if (sc->sc_settledelay) {
211 printf("%s: waiting %d seconds for changer to settle...\n",
212 sc->sc_dev.dv_xname, sc->sc_settledelay);
213 delay(1000000 * sc->sc_settledelay);
214 }
215
216 /*
217 * Get information about the device. Note we can't use
218 * interrupts yet.
219 */
220 if (ch_get_params(sc, XS_CTL_DISCOVERY|XS_CTL_IGNORE_MEDIA_CHANGE))
221 printf("%s: offline\n", sc->sc_dev.dv_xname);
222 else {
223 #define PLURAL(c) (c) == 1 ? "" : "s"
224 printf("%s: %d slot%s, %d drive%s, %d picker%s, %d portal%s\n",
225 sc->sc_dev.dv_xname,
226 sc->sc_counts[CHET_ST], PLURAL(sc->sc_counts[CHET_ST]),
227 sc->sc_counts[CHET_DT], PLURAL(sc->sc_counts[CHET_DT]),
228 sc->sc_counts[CHET_MT], PLURAL(sc->sc_counts[CHET_MT]),
229 sc->sc_counts[CHET_IE], PLURAL(sc->sc_counts[CHET_IE]));
230 #undef PLURAL
231 #ifdef CHANGER_DEBUG
232 printf("%s: move mask: 0x%x 0x%x 0x%x 0x%x\n",
233 sc->sc_dev.dv_xname,
234 sc->sc_movemask[CHET_MT], sc->sc_movemask[CHET_ST],
235 sc->sc_movemask[CHET_IE], sc->sc_movemask[CHET_DT]);
236 printf("%s: exchange mask: 0x%x 0x%x 0x%x 0x%x\n",
237 sc->sc_dev.dv_xname,
238 sc->sc_exchangemask[CHET_MT], sc->sc_exchangemask[CHET_ST],
239 sc->sc_exchangemask[CHET_IE], sc->sc_exchangemask[CHET_DT]);
240 #endif /* CHANGER_DEBUG */
241 }
242
243 /* Default the current picker. */
244 sc->sc_picker = sc->sc_firsts[CHET_MT];
245 }
246
247 int
248 chopen(dev, flags, fmt, p)
249 dev_t dev;
250 int flags, fmt;
251 struct proc *p;
252 {
253 struct ch_softc *sc;
254 struct scsipi_periph *periph;
255 struct scsipi_adapter *adapt;
256 int unit, error;
257
258 unit = CHUNIT(dev);
259 if ((unit >= ch_cd.cd_ndevs) ||
260 ((sc = ch_cd.cd_devs[unit]) == NULL))
261 return (ENXIO);
262
263 periph = sc->sc_periph;
264 adapt = periph->periph_channel->chan_adapter;
265
266 /*
267 * Only allow one open at a time.
268 */
269 if (periph->periph_flags & PERIPH_OPEN)
270 return (EBUSY);
271
272 if ((error = scsipi_adapter_addref(adapt)) != 0)
273 return (error);
274
275 periph->periph_flags |= PERIPH_OPEN;
276
277 /*
278 * Make sure the unit is on-line. If a UNIT ATTENTION
279 * occurs, we will mark that an Init-Element-Status is
280 * needed in ch_get_params().
281 *
282 * We ignore NOT READY in case e.g a magazine isn't actually
283 * loaded into the changer or a tape isn't in the drive.
284 */
285 error = scsipi_test_unit_ready(periph, XS_CTL_IGNORE_NOT_READY);
286 if (error)
287 goto bad;
288
289 /*
290 * Make sure our parameters are up to date.
291 */
292 if ((error = ch_get_params(sc, 0)) != 0)
293 goto bad;
294
295 return (0);
296
297 bad:
298 scsipi_adapter_delref(adapt);
299 periph->periph_flags &= ~PERIPH_OPEN;
300 return (error);
301 }
302
303 int
304 chclose(dev, flags, fmt, p)
305 dev_t dev;
306 int flags, fmt;
307 struct proc *p;
308 {
309 struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
310 struct scsipi_periph *periph = sc->sc_periph;
311 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
312
313 scsipi_wait_drain(periph);
314
315 scsipi_adapter_delref(adapt);
316
317 sc->sc_events = 0;
318
319 periph->periph_flags &= ~PERIPH_OPEN;
320 return (0);
321 }
322
323 int
324 chread(dev, uio, flags)
325 dev_t dev;
326 struct uio *uio;
327 int flags;
328 {
329 struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
330 int error;
331
332 if (uio->uio_resid != CHANGER_EVENT_SIZE)
333 return (EINVAL);
334
335 /*
336 * Read never blocks; if there are no events pending, we just
337 * return an all-clear bitmask.
338 */
339 error = uiomove(&sc->sc_events, CHANGER_EVENT_SIZE, uio);
340 if (error == 0)
341 sc->sc_events = 0;
342 return (error);
343 }
344
345 int
346 chioctl(dev, cmd, data, flags, p)
347 dev_t dev;
348 u_long cmd;
349 caddr_t data;
350 int flags;
351 struct proc *p;
352 {
353 struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
354 int error = 0;
355
356 /*
357 * If this command can change the device's state, we must
358 * have the device open for writing.
359 */
360 switch (cmd) {
361 case CHIOGPICKER:
362 case CHIOGPARAMS:
363 case OCHIOGSTATUS:
364 break;
365
366 default:
367 if ((flags & FWRITE) == 0)
368 return (EBADF);
369 }
370
371 switch (cmd) {
372 case CHIOMOVE:
373 error = ch_move(sc, (struct changer_move_request *)data);
374 break;
375
376 case CHIOEXCHANGE:
377 error = ch_exchange(sc,
378 (struct changer_exchange_request *)data);
379 break;
380
381 case CHIOPOSITION:
382 error = ch_position(sc,
383 (struct changer_position_request *)data);
384 break;
385
386 case CHIOGPICKER:
387 *(int *)data = sc->sc_picker - sc->sc_firsts[CHET_MT];
388 break;
389
390 case CHIOSPICKER:
391 {
392 int new_picker = *(int *)data;
393
394 if (new_picker > (sc->sc_counts[CHET_MT] - 1))
395 return (EINVAL);
396 sc->sc_picker = sc->sc_firsts[CHET_MT] + new_picker;
397 break;
398 }
399
400 case CHIOGPARAMS:
401 {
402 struct changer_params *cp = (struct changer_params *)data;
403
404 cp->cp_curpicker = sc->sc_picker - sc->sc_firsts[CHET_MT];
405 cp->cp_npickers = sc->sc_counts[CHET_MT];
406 cp->cp_nslots = sc->sc_counts[CHET_ST];
407 cp->cp_nportals = sc->sc_counts[CHET_IE];
408 cp->cp_ndrives = sc->sc_counts[CHET_DT];
409 break;
410 }
411
412 case CHIOIELEM:
413 error = ch_ielem(sc);
414 if (error == 0) {
415 sc->sc_periph->periph_flags |= PERIPH_MEDIA_LOADED;
416 }
417 break;
418
419 case OCHIOGSTATUS:
420 {
421 struct ochanger_element_status_request *cesr =
422 (struct ochanger_element_status_request *)data;
423
424 error = ch_ousergetelemstatus(sc, cesr->cesr_type,
425 cesr->cesr_data);
426 break;
427 }
428
429 case CHIOGSTATUS:
430 error = ch_usergetelemstatus(sc,
431 (struct changer_element_status_request *)data);
432 break;
433
434 case CHIOSVOLTAG:
435 error = ch_setvoltag(sc,
436 (struct changer_set_voltag_request *)data);
437 break;
438
439 /* Implement prevent/allow? */
440
441 default:
442 error = scsipi_do_ioctl(sc->sc_periph, dev, cmd, data,
443 flags, p);
444 break;
445 }
446
447 return (error);
448 }
449
450 int
451 chpoll(dev, events, p)
452 dev_t dev;
453 int events;
454 struct proc *p;
455 {
456 struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
457 int revents;
458
459 revents = events & (POLLOUT | POLLWRNORM);
460
461 if ((events & (POLLIN | POLLRDNORM)) == 0)
462 return (revents);
463
464 if (sc->sc_events == 0)
465 revents |= events & (POLLIN | POLLRDNORM);
466 else
467 selrecord(p, &sc->sc_selq);
468
469 return (revents);
470 }
471
472 static void
473 filt_chdetach(struct knote *kn)
474 {
475 struct ch_softc *sc = (void *) kn->kn_hook;
476
477 SLIST_REMOVE(&sc->sc_selq.si_klist, kn, knote, kn_selnext);
478 }
479
480 static int
481 filt_chread(struct knote *kn, long hint)
482 {
483 struct ch_softc *sc = (void *) kn->kn_hook;
484
485 if (sc->sc_events == 0)
486 return (0);
487 kn->kn_data = CHANGER_EVENT_SIZE;
488 return (1);
489 }
490
491 static const struct filterops chread_filtops =
492 { 1, NULL, filt_chdetach, filt_chread };
493
494 static const struct filterops chwrite_filtops =
495 { 1, NULL, filt_chdetach, filt_seltrue };
496
497 int
498 chkqfilter(dev_t dev, struct knote *kn)
499 {
500 struct ch_softc *sc = ch_cd.cd_devs[CHUNIT(dev)];
501 struct klist *klist;
502
503 switch (kn->kn_filter) {
504 case EVFILT_READ:
505 klist = &sc->sc_selq.si_klist;
506 kn->kn_fop = &chread_filtops;
507 break;
508
509 case EVFILT_WRITE:
510 klist = &sc->sc_selq.si_klist;
511 kn->kn_fop = &chwrite_filtops;
512 break;
513
514 default:
515 return (1);
516 }
517
518 kn->kn_hook = (void *) sc;
519
520 SLIST_INSERT_HEAD(klist, kn, kn_selnext);
521
522 return (0);
523 }
524
525 int
526 ch_interpret_sense(xs)
527 struct scsipi_xfer *xs;
528 {
529 struct scsipi_periph *periph = xs->xs_periph;
530 struct scsipi_sense_data *sense = &xs->sense.scsi_sense;
531 struct ch_softc *sc = (void *)periph->periph_dev;
532 u_int16_t asc_ascq;
533
534 /*
535 * If the periph is already recovering, just do the
536 * normal error recovering.
537 */
538 if (periph->periph_flags & PERIPH_RECOVERING)
539 return (EJUSTRETURN);
540
541 /*
542 * If it isn't an extended or extended/deferred error, let
543 * the generic code handle it.
544 */
545 if ((sense->error_code & SSD_ERRCODE) != 0x70 &&
546 (sense->error_code & SSD_ERRCODE) != 0x71)
547 return (EJUSTRETURN);
548
549 /*
550 * We're only interested in condtions that
551 * indicate potential inventory violation.
552 *
553 * We use ASC/ASCQ codes for this.
554 */
555
556 asc_ascq = (((u_int16_t) sense->add_sense_code) << 8) |
557 sense->add_sense_code_qual;
558
559 switch (asc_ascq) {
560 case 0x2800:
561 /* "Not Ready To Ready Transition (Medium May Have Changed)" */
562 case 0x2900:
563 /* "Power On, Reset, or Bus Device Reset Occurred" */
564 sc->sc_periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
565 /*
566 * Enqueue an Element-Status-Changed event, and
567 * wake up any processes waiting for them.
568 */
569 /*
570 * Enqueue an Element-Status-Changed event, and wake up
571 * any processes waiting for them.
572 */
573 if ((xs->xs_control & XS_CTL_IGNORE_MEDIA_CHANGE) == 0)
574 ch_event(sc, CHEV_ELEMENT_STATUS_CHANGED);
575 break;
576 default:
577 break;
578 }
579
580 return (EJUSTRETURN);
581 }
582
583 void
584 ch_event(sc, event)
585 struct ch_softc *sc;
586 u_int event;
587 {
588
589 sc->sc_events |= event;
590 selnotify(&sc->sc_selq, 0);
591 }
592
593 int
594 ch_move(sc, cm)
595 struct ch_softc *sc;
596 struct changer_move_request *cm;
597 {
598 struct scsi_move_medium cmd;
599 u_int16_t fromelem, toelem;
600
601 /*
602 * Check arguments.
603 */
604 if ((cm->cm_fromtype > CHET_DT) || (cm->cm_totype > CHET_DT))
605 return (EINVAL);
606 if ((cm->cm_fromunit > (sc->sc_counts[cm->cm_fromtype] - 1)) ||
607 (cm->cm_tounit > (sc->sc_counts[cm->cm_totype] - 1)))
608 return (ENODEV);
609
610 /*
611 * Check the request against the changer's capabilities.
612 */
613 if ((sc->sc_movemask[cm->cm_fromtype] & (1 << cm->cm_totype)) == 0)
614 return (ENODEV);
615
616 /*
617 * Calculate the source and destination elements.
618 */
619 fromelem = sc->sc_firsts[cm->cm_fromtype] + cm->cm_fromunit;
620 toelem = sc->sc_firsts[cm->cm_totype] + cm->cm_tounit;
621
622 /*
623 * Build the SCSI command.
624 */
625 memset(&cmd, 0, sizeof(cmd));
626 cmd.opcode = MOVE_MEDIUM;
627 _lto2b(sc->sc_picker, cmd.tea);
628 _lto2b(fromelem, cmd.src);
629 _lto2b(toelem, cmd.dst);
630 if (cm->cm_flags & CM_INVERT)
631 cmd.flags |= MOVE_MEDIUM_INVERT;
632
633 /*
634 * Send command to changer.
635 */
636 return (scsipi_command(sc->sc_periph,
637 (struct scsipi_generic *)&cmd, sizeof(cmd), NULL, 0, CHRETRIES,
638 100000, NULL, 0));
639 }
640
641 int
642 ch_exchange(sc, ce)
643 struct ch_softc *sc;
644 struct changer_exchange_request *ce;
645 {
646 struct scsi_exchange_medium cmd;
647 u_int16_t src, dst1, dst2;
648
649 /*
650 * Check arguments.
651 */
652 if ((ce->ce_srctype > CHET_DT) || (ce->ce_fdsttype > CHET_DT) ||
653 (ce->ce_sdsttype > CHET_DT))
654 return (EINVAL);
655 if ((ce->ce_srcunit > (sc->sc_counts[ce->ce_srctype] - 1)) ||
656 (ce->ce_fdstunit > (sc->sc_counts[ce->ce_fdsttype] - 1)) ||
657 (ce->ce_sdstunit > (sc->sc_counts[ce->ce_sdsttype] - 1)))
658 return (ENODEV);
659
660 /*
661 * Check the request against the changer's capabilities.
662 */
663 if (((sc->sc_exchangemask[ce->ce_srctype] &
664 (1 << ce->ce_fdsttype)) == 0) ||
665 ((sc->sc_exchangemask[ce->ce_fdsttype] &
666 (1 << ce->ce_sdsttype)) == 0))
667 return (ENODEV);
668
669 /*
670 * Calculate the source and destination elements.
671 */
672 src = sc->sc_firsts[ce->ce_srctype] + ce->ce_srcunit;
673 dst1 = sc->sc_firsts[ce->ce_fdsttype] + ce->ce_fdstunit;
674 dst2 = sc->sc_firsts[ce->ce_sdsttype] + ce->ce_sdstunit;
675
676 /*
677 * Build the SCSI command.
678 */
679 memset(&cmd, 0, sizeof(cmd));
680 cmd.opcode = EXCHANGE_MEDIUM;
681 _lto2b(sc->sc_picker, cmd.tea);
682 _lto2b(src, cmd.src);
683 _lto2b(dst1, cmd.fdst);
684 _lto2b(dst2, cmd.sdst);
685 if (ce->ce_flags & CE_INVERT1)
686 cmd.flags |= EXCHANGE_MEDIUM_INV1;
687 if (ce->ce_flags & CE_INVERT2)
688 cmd.flags |= EXCHANGE_MEDIUM_INV2;
689
690 /*
691 * Send command to changer.
692 */
693 return (scsipi_command(sc->sc_periph,
694 (struct scsipi_generic *)&cmd, sizeof(cmd), NULL, 0, CHRETRIES,
695 100000, NULL, 0));
696 }
697
698 int
699 ch_position(sc, cp)
700 struct ch_softc *sc;
701 struct changer_position_request *cp;
702 {
703 struct scsi_position_to_element cmd;
704 u_int16_t dst;
705
706 /*
707 * Check arguments.
708 */
709 if (cp->cp_type > CHET_DT)
710 return (EINVAL);
711 if (cp->cp_unit > (sc->sc_counts[cp->cp_type] - 1))
712 return (ENODEV);
713
714 /*
715 * Calculate the destination element.
716 */
717 dst = sc->sc_firsts[cp->cp_type] + cp->cp_unit;
718
719 /*
720 * Build the SCSI command.
721 */
722 memset(&cmd, 0, sizeof(cmd));
723 cmd.opcode = POSITION_TO_ELEMENT;
724 _lto2b(sc->sc_picker, cmd.tea);
725 _lto2b(dst, cmd.dst);
726 if (cp->cp_flags & CP_INVERT)
727 cmd.flags |= POSITION_TO_ELEMENT_INVERT;
728
729 /*
730 * Send command to changer.
731 */
732 return (scsipi_command(sc->sc_periph,
733 (struct scsipi_generic *)&cmd, sizeof(cmd), NULL, 0, CHRETRIES,
734 100000, NULL, 0));
735 }
736
737 /*
738 * Perform a READ ELEMENT STATUS on behalf of the user, and return to
739 * the user only the data the user is interested in. This returns the
740 * old data format.
741 */
742 int
743 ch_ousergetelemstatus(sc, chet, uptr)
744 struct ch_softc *sc;
745 int chet;
746 u_int8_t *uptr;
747 {
748 struct read_element_status_header *st_hdrp, st_hdr;
749 struct read_element_status_page_header *pg_hdrp;
750 struct read_element_status_descriptor *desc;
751 size_t size, desclen;
752 caddr_t data;
753 int avail, i, error = 0;
754 u_int8_t user_data;
755
756 /*
757 * If there are no elements of the requested type in the changer,
758 * the request is invalid.
759 */
760 if (sc->sc_counts[chet] == 0)
761 return (EINVAL);
762
763 /*
764 * Do the request the user wants, but only read the status header.
765 * This will tell us the amount of storage we must allocate in
766 * order to read all data.
767 */
768 error = ch_getelemstatus(sc, sc->sc_firsts[chet],
769 sc->sc_counts[chet], &st_hdr, sizeof(st_hdr),
770 XS_CTL_DATA_ONSTACK, 0);
771 if (error)
772 return (error);
773
774 size = sizeof(struct read_element_status_header) +
775 _3btol(st_hdr.nbytes);
776
777 /*
778 * We must have at least room for the status header and
779 * one page header (since we only ask for one element type
780 * at a time).
781 */
782 if (size < (sizeof(struct read_element_status_header) +
783 sizeof(struct read_element_status_page_header)))
784 return (EIO);
785
786 /*
787 * Allocate the storage and do the request again.
788 */
789 data = malloc(size, M_DEVBUF, M_WAITOK);
790 error = ch_getelemstatus(sc, sc->sc_firsts[chet],
791 sc->sc_counts[chet], data, size, 0, 0);
792 if (error)
793 goto done;
794
795 st_hdrp = (struct read_element_status_header *)data;
796 pg_hdrp = (struct read_element_status_page_header *)((u_long)st_hdrp +
797 sizeof(struct read_element_status_header));
798 desclen = _2btol(pg_hdrp->edl);
799
800 /*
801 * Fill in the user status array.
802 */
803 avail = _2btol(st_hdrp->count);
804
805 if (avail != sc->sc_counts[chet])
806 printf("%s: warning, READ ELEMENT STATUS avail != count\n",
807 sc->sc_dev.dv_xname);
808
809 desc = (struct read_element_status_descriptor *)((u_long)data +
810 sizeof(struct read_element_status_header) +
811 sizeof(struct read_element_status_page_header));
812 for (i = 0; i < avail; ++i) {
813 user_data = desc->flags1;
814 error = copyout(&user_data, &uptr[i], avail);
815 if (error)
816 break;
817 desc = (struct read_element_status_descriptor *)((u_long)desc
818 + desclen);
819 }
820
821 done:
822 if (data != NULL)
823 free(data, M_DEVBUF);
824 return (error);
825 }
826
827 /*
828 * Perform a READ ELEMENT STATUS on behalf of the user. This returns
829 * the new (more complete) data format.
830 */
831 int
832 ch_usergetelemstatus(sc, cesr)
833 struct ch_softc *sc;
834 struct changer_element_status_request *cesr;
835 {
836 struct scsipi_channel *chan = sc->sc_periph->periph_channel;
837 struct scsipi_periph *dtperiph;
838 struct read_element_status_header *st_hdrp, st_hdr;
839 struct read_element_status_page_header *pg_hdrp;
840 struct read_element_status_descriptor *desc;
841 struct changer_volume_tag *avol, *pvol;
842 size_t size, desclen, stddesclen, offset;
843 int first, avail, i, error = 0;
844 caddr_t data;
845 void *uvendptr;
846 struct changer_element_status ces;
847
848 /*
849 * Check arguments.
850 */
851 if (cesr->cesr_type > CHET_DT)
852 return (EINVAL);
853 if (sc->sc_counts[cesr->cesr_type] == 0)
854 return (ENODEV);
855 if (cesr->cesr_unit > (sc->sc_counts[cesr->cesr_type] - 1))
856 return (ENODEV);
857 if (cesr->cesr_count >
858 (sc->sc_counts[cesr->cesr_type] + cesr->cesr_unit))
859 return (EINVAL);
860
861 /*
862 * Do the request the user wants, but only read the status header.
863 * This will tell us the amount of storage we must allocate
864 * in order to read all the data.
865 */
866 error = ch_getelemstatus(sc, sc->sc_firsts[cesr->cesr_type] +
867 cesr->cesr_unit, cesr->cesr_count, &st_hdr, sizeof(st_hdr), 0,
868 cesr->cesr_flags);
869 if (error)
870 return (error);
871
872 size = sizeof(struct read_element_status_header) +
873 _3btol(st_hdr.nbytes);
874
875 /*
876 * We must have at least room for the status header and
877 * one page header (since we only ask for oen element type
878 * at a time).
879 */
880 if (size < (sizeof(struct read_element_status_header) +
881 sizeof(struct read_element_status_page_header)))
882 return (EIO);
883
884 /*
885 * Allocate the storage and do the request again.
886 */
887 data = malloc(size, M_DEVBUF, M_WAITOK);
888 error = ch_getelemstatus(sc, sc->sc_firsts[cesr->cesr_type] +
889 cesr->cesr_unit, cesr->cesr_count, data, size, 0,
890 cesr->cesr_flags);
891 if (error)
892 goto done;
893
894 st_hdrp = (struct read_element_status_header *)data;
895 pg_hdrp = (struct read_element_status_page_header *)((u_long)st_hdrp +
896 sizeof(struct read_element_status_header));
897 desclen = _2btol(pg_hdrp->edl);
898
899 /*
900 * Fill in the user status array.
901 */
902 first = _2btol(st_hdrp->fear);
903 if (first < (sc->sc_firsts[cesr->cesr_type] + cesr->cesr_unit) ||
904 first >= (sc->sc_firsts[cesr->cesr_type] + cesr->cesr_unit +
905 cesr->cesr_count)) {
906 error = EIO;
907 goto done;
908 }
909 first -= sc->sc_firsts[cesr->cesr_type] + cesr->cesr_unit;
910
911 avail = _2btol(st_hdrp->count);
912 if (avail <= 0 || avail > cesr->cesr_count) {
913 error = EIO;
914 goto done;
915 }
916
917 offset = sizeof(struct read_element_status_header) +
918 sizeof(struct read_element_status_page_header);
919
920 for (i = 0; i < cesr->cesr_count; i++) {
921 memset(&ces, 0, sizeof(ces));
922 if (i < first || i >= (first + avail)) {
923 error = copyout(&ces, &cesr->cesr_data[i],
924 sizeof(ces));
925 if (error)
926 goto done;
927 }
928
929 desc = (struct read_element_status_descriptor *)
930 (data + offset);
931 stddesclen = sizeof(struct read_element_status_descriptor);
932 offset += desclen;
933
934 ces.ces_flags = CESTATUS_STATUS_VALID;
935
936 /*
937 * The SCSI flags conveniently map directly to the
938 * chio API flags.
939 */
940 ces.ces_flags |= (desc->flags1 & 0x3f);
941
942 ces.ces_asc = desc->sense_code;
943 ces.ces_ascq = desc->sense_qual;
944
945 /*
946 * For Data Transport elemenets, get the SCSI ID and LUN,
947 * and attempt to map them to a device name if they're
948 * on the same SCSI bus.
949 */
950 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_IDVALID) {
951 ces.ces_target = desc->dt_scsi_addr;
952 ces.ces_flags |= CESTATUS_TARGET_VALID;
953 }
954 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_LUVALID) {
955 ces.ces_lun = desc->dt_scsi_flags &
956 READ_ELEMENT_STATUS_DT_LUNMASK;
957 ces.ces_flags |= CESTATUS_LUN_VALID;
958 }
959 if (desc->dt_scsi_flags & READ_ELEMENT_STATUS_DT_NOTBUS)
960 ces.ces_flags |= CESTATUS_NOTBUS;
961 else if ((ces.ces_flags &
962 (CESTATUS_TARGET_VALID|CESTATUS_LUN_VALID)) ==
963 (CESTATUS_TARGET_VALID|CESTATUS_LUN_VALID)) {
964 if (ces.ces_target < chan->chan_ntargets &&
965 ces.ces_lun < chan->chan_nluns &&
966 (dtperiph = scsipi_lookup_periph(chan,
967 ces.ces_target, ces.ces_lun)) != NULL &&
968 dtperiph->periph_dev != NULL) {
969 strcpy(ces.ces_xname,
970 dtperiph->periph_dev->dv_xname);
971 ces.ces_flags |= CESTATUS_XNAME_VALID;
972 }
973 }
974
975 if (desc->flags2 & READ_ELEMENT_STATUS_INVERT)
976 ces.ces_flags |= CESTATUS_INVERTED;
977
978 if (desc->flags2 & READ_ELEMENT_STATUS_SVALID) {
979 if (ch_map_element(sc, _2btol(desc->ssea),
980 &ces.ces_from_type, &ces.ces_from_unit))
981 ces.ces_flags |= CESTATUS_FROM_VALID;
982 }
983
984 /*
985 * Extract volume tag information.
986 */
987 switch (pg_hdrp->flags &
988 (READ_ELEMENT_STATUS_PVOLTAG|READ_ELEMENT_STATUS_AVOLTAG)) {
989 case (READ_ELEMENT_STATUS_PVOLTAG|READ_ELEMENT_STATUS_AVOLTAG):
990 pvol = (struct changer_volume_tag *)(desc + 1);
991 avol = pvol + 1;
992 break;
993
994 case READ_ELEMENT_STATUS_PVOLTAG:
995 pvol = (struct changer_volume_tag *)(desc + 1);
996 avol = NULL;
997 break;
998
999 case READ_ELEMENT_STATUS_AVOLTAG:
1000 pvol = NULL;
1001 avol = (struct changer_volume_tag *)(desc + 1);
1002 break;
1003
1004 default:
1005 avol = pvol = NULL;
1006 break;
1007 }
1008
1009 if (pvol != NULL) {
1010 ch_voltag_convert_in(pvol, &ces.ces_pvoltag);
1011 ces.ces_flags |= CESTATUS_PVOL_VALID;
1012 stddesclen += sizeof(struct changer_volume_tag);
1013 }
1014 if (avol != NULL) {
1015 ch_voltag_convert_in(avol, &ces.ces_avoltag);
1016 ces.ces_flags |= CESTATUS_AVOL_VALID;
1017 stddesclen += sizeof(struct changer_volume_tag);
1018 }
1019
1020 /*
1021 * Compute vendor-specific length. Note the 4 reserved
1022 * bytes between the volume tags and the vendor-specific
1023 * data. Copy it out of the user wants it.
1024 */
1025 stddesclen += 4;
1026 if (desclen > stddesclen)
1027 ces.ces_vendor_len = desclen - stddesclen;
1028
1029 if (ces.ces_vendor_len != 0 && cesr->cesr_vendor_data != NULL) {
1030 error = copyin(&cesr->cesr_vendor_data[i], &uvendptr,
1031 sizeof(uvendptr));
1032 if (error)
1033 goto done;
1034 error = copyout((void *)((u_long)desc + stddesclen),
1035 uvendptr, ces.ces_vendor_len);
1036 if (error)
1037 goto done;
1038 }
1039
1040 /*
1041 * Now copy out the status descriptor we've constructed.
1042 */
1043 error = copyout(&ces, &cesr->cesr_data[i], sizeof(ces));
1044 if (error)
1045 goto done;
1046 }
1047
1048 done:
1049 if (data != NULL)
1050 free(data, M_DEVBUF);
1051 return (error);
1052 }
1053
1054 int
1055 ch_getelemstatus(sc, first, count, data, datalen, scsiflags, flags)
1056 struct ch_softc *sc;
1057 int first, count;
1058 void *data;
1059 size_t datalen;
1060 int scsiflags;
1061 int flags;
1062 {
1063 struct scsi_read_element_status cmd;
1064
1065 /*
1066 * Build SCSI command.
1067 */
1068 memset(&cmd, 0, sizeof(cmd));
1069 cmd.opcode = READ_ELEMENT_STATUS;
1070 cmd.byte2 = ELEMENT_TYPE_ALL;
1071 if (flags & CESR_VOLTAGS)
1072 cmd.byte2 |= READ_ELEMENT_STATUS_VOLTAG;
1073 _lto2b(first, cmd.sea);
1074 _lto2b(count, cmd.count);
1075 _lto3b(datalen, cmd.len);
1076
1077 /*
1078 * Send command to changer.
1079 */
1080 return (scsipi_command(sc->sc_periph,
1081 (struct scsipi_generic *)&cmd, sizeof(cmd),
1082 (u_char *)data, datalen, CHRETRIES, 100000, NULL,
1083 scsiflags | XS_CTL_DATA_IN));
1084 }
1085
1086 int
1087 ch_setvoltag(sc, csvr)
1088 struct ch_softc *sc;
1089 struct changer_set_voltag_request *csvr;
1090 {
1091 struct scsi_send_volume_tag cmd;
1092 struct changer_volume_tag voltag;
1093 void *data = NULL;
1094 size_t datalen = 0;
1095 int error;
1096 u_int16_t dst;
1097
1098 /*
1099 * Check arguments.
1100 */
1101 if (csvr->csvr_type > CHET_DT)
1102 return (EINVAL);
1103 if (csvr->csvr_unit > (sc->sc_counts[csvr->csvr_type] - 1))
1104 return (ENODEV);
1105
1106 dst = sc->sc_firsts[csvr->csvr_type] + csvr->csvr_unit;
1107
1108 /*
1109 * Build the SCSI command.
1110 */
1111 memset(&cmd, 0, sizeof(cmd));
1112 cmd.opcode = SEND_VOLUME_TAG;
1113 _lto2b(dst, cmd.eaddr);
1114
1115 #define ALTERNATE (csvr->csvr_flags & CSVR_ALTERNATE)
1116
1117 switch (csvr->csvr_flags & CSVR_MODE_MASK) {
1118 case CSVR_MODE_SET:
1119 cmd.sac = ALTERNATE ? SAC_ASSERT_ALT : SAC_ASSERT_PRIMARY;
1120 break;
1121
1122 case CSVR_MODE_REPLACE:
1123 cmd.sac = ALTERNATE ? SAC_REPLACE_ALT : SAC_REPLACE_PRIMARY;
1124 break;
1125
1126 case CSVR_MODE_CLEAR:
1127 cmd.sac = ALTERNATE ? SAC_UNDEFINED_ALT : SAC_UNDEFINED_PRIMARY;
1128 break;
1129
1130 default:
1131 return (EINVAL);
1132 }
1133
1134 #undef ALTERNATE
1135
1136 if (cmd.sac < SAC_UNDEFINED_PRIMARY) {
1137 error = ch_voltag_convert_out(&csvr->csvr_voltag, &voltag);
1138 if (error)
1139 return (error);
1140 data = &voltag;
1141 datalen = sizeof(voltag);
1142 _lto2b(datalen, cmd.length);
1143 }
1144
1145 /*
1146 * Send command to changer.
1147 */
1148 return (scsipi_command(sc->sc_periph,
1149 (struct scsipi_generic *)&cmd, sizeof(cmd),
1150 (u_char *)data, datalen, CHRETRIES, 100000, NULL,
1151 datalen ? XS_CTL_DATA_OUT | XS_CTL_DATA_ONSTACK : 0));
1152 }
1153
1154 int
1155 ch_ielem(sc)
1156 struct ch_softc *sc;
1157 {
1158 int tmo;
1159 struct scsi_initialize_element_status cmd;
1160
1161 /*
1162 * Build SCSI command.
1163 */
1164 memset(&cmd, 0, sizeof(cmd));
1165 cmd.opcode = INITIALIZE_ELEMENT_STATUS;
1166
1167 /*
1168 * Send command to changer.
1169 *
1170 * The problem is, how long to allow for the command?
1171 * It can take a *really* long time, and also depends
1172 * on unknowable factors such as whether there are
1173 * *almost* readable labels on tapes that a barcode
1174 * reader is trying to decipher.
1175 *
1176 * I'm going to make this long enough to allow 5 minutes
1177 * per element plus an initial 10 minute wait.
1178 */
1179 tmo = sc->sc_counts[CHET_MT] +
1180 sc->sc_counts[CHET_ST] +
1181 sc->sc_counts[CHET_IE] +
1182 sc->sc_counts[CHET_DT];
1183 tmo *= 5 * 60 * 1000;
1184 tmo += (10 * 60 * 1000);
1185
1186 return (scsipi_command(sc->sc_periph,
1187 (struct scsipi_generic *)&cmd, sizeof(cmd),
1188 NULL, 0, CHRETRIES, tmo, NULL, XS_CTL_IGNORE_ILLEGAL_REQUEST));
1189 }
1190
1191 /*
1192 * Ask the device about itself and fill in the parameters in our
1193 * softc.
1194 */
1195 int
1196 ch_get_params(sc, scsiflags)
1197 struct ch_softc *sc;
1198 int scsiflags;
1199 {
1200 struct scsi_mode_sense_data {
1201 struct scsipi_mode_header header;
1202 union {
1203 struct page_element_address_assignment ea;
1204 struct page_transport_geometry_parameters tg;
1205 struct page_device_capabilities cap;
1206 } pages;
1207 } sense_data;
1208 int error, from;
1209 u_int8_t *moves, *exchanges;
1210
1211 /*
1212 * Grab info from the element address assignment page.
1213 */
1214 memset(&sense_data, 0, sizeof(sense_data));
1215 error = scsipi_mode_sense(sc->sc_periph, SMS_DBD, 0x1d,
1216 &sense_data.header, sizeof(sense_data),
1217 scsiflags | XS_CTL_DATA_ONSTACK, CHRETRIES, 6000);
1218 if (error) {
1219 printf("%s: could not sense element address page\n",
1220 sc->sc_dev.dv_xname);
1221 return (error);
1222 }
1223
1224 sc->sc_firsts[CHET_MT] = _2btol(sense_data.pages.ea.mtea);
1225 sc->sc_counts[CHET_MT] = _2btol(sense_data.pages.ea.nmte);
1226 sc->sc_firsts[CHET_ST] = _2btol(sense_data.pages.ea.fsea);
1227 sc->sc_counts[CHET_ST] = _2btol(sense_data.pages.ea.nse);
1228 sc->sc_firsts[CHET_IE] = _2btol(sense_data.pages.ea.fieea);
1229 sc->sc_counts[CHET_IE] = _2btol(sense_data.pages.ea.niee);
1230 sc->sc_firsts[CHET_DT] = _2btol(sense_data.pages.ea.fdtea);
1231 sc->sc_counts[CHET_DT] = _2btol(sense_data.pages.ea.ndte);
1232
1233 /* XXX ask for transport geometry page XXX */
1234
1235 /*
1236 * Grab info from the capabilities page.
1237 */
1238 memset(&sense_data, 0, sizeof(sense_data));
1239 /*
1240 * XXX: Note: not all changers can deal with disabled block descriptors
1241 */
1242 error = scsipi_mode_sense(sc->sc_periph, SMS_DBD, 0x1f,
1243 &sense_data.header, sizeof(sense_data),
1244 scsiflags | XS_CTL_DATA_ONSTACK, CHRETRIES, 6000);
1245 if (error) {
1246 printf("%s: could not sense capabilities page\n",
1247 sc->sc_dev.dv_xname);
1248 return (error);
1249 }
1250
1251 memset(sc->sc_movemask, 0, sizeof(sc->sc_movemask));
1252 memset(sc->sc_exchangemask, 0, sizeof(sc->sc_exchangemask));
1253 moves = &sense_data.pages.cap.move_from_mt;
1254 exchanges = &sense_data.pages.cap.exchange_with_mt;
1255 for (from = CHET_MT; from <= CHET_DT; ++from) {
1256 sc->sc_movemask[from] = moves[from];
1257 sc->sc_exchangemask[from] = exchanges[from];
1258 }
1259
1260 #ifdef CH_AUTOMATIC_IELEM_POLICY
1261 /*
1262 * If we need to do an Init-Element-Status,
1263 * do that now that we know what's in the changer.
1264 */
1265 if ((scsiflags & XS_CTL_IGNORE_MEDIA_CHANGE) == 0) {
1266 if ((sc->sc_periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
1267 error = ch_ielem(sc);
1268 if (error == 0)
1269 sc->sc_periph->periph_flags |= PERIPH_MEDIA_LOADED;
1270 else
1271 sc->sc_periph->periph_flags &= ~PERIPH_MEDIA_LOADED;
1272 }
1273 #endif
1274 return (error);
1275 }
1276
1277 void
1278 ch_get_quirks(sc, inqbuf)
1279 struct ch_softc *sc;
1280 struct scsipi_inquiry_pattern *inqbuf;
1281 {
1282 struct chquirk *match;
1283 int priority;
1284
1285 sc->sc_settledelay = 0;
1286
1287 match = (struct chquirk *)scsipi_inqmatch(inqbuf,
1288 (caddr_t)chquirks,
1289 sizeof(chquirks) / sizeof(chquirks[0]),
1290 sizeof(chquirks[0]), &priority);
1291 if (priority != 0)
1292 sc->sc_settledelay = match->cq_settledelay;
1293 }
1294
1295 int
1296 ch_map_element(sc, elem, typep, unitp)
1297 struct ch_softc *sc;
1298 u_int16_t elem;
1299 int *typep, *unitp;
1300 {
1301 int chet;
1302
1303 for (chet = CHET_MT; chet <= CHET_DT; chet++) {
1304 if (elem >= sc->sc_firsts[chet] &&
1305 elem < (sc->sc_firsts[chet] + sc->sc_counts[chet])) {
1306 *typep = chet;
1307 *unitp = elem - sc->sc_firsts[chet];
1308 return (1);
1309 }
1310 }
1311 return (0);
1312 }
1313
1314 void
1315 ch_voltag_convert_in(sv, cv)
1316 const struct changer_volume_tag *sv;
1317 struct changer_voltag *cv;
1318 {
1319 int i;
1320
1321 memset(cv, 0, sizeof(struct changer_voltag));
1322
1323 /*
1324 * Copy the volume tag string from the SCSI representation.
1325 * Per the SCSI-2 spec, we stop at the first blank character.
1326 */
1327 for (i = 0; i < sizeof(sv->volid); i++) {
1328 if (sv->volid[i] == ' ')
1329 break;
1330 cv->cv_tag[i] = sv->volid[i];
1331 }
1332 cv->cv_tag[i] = '\0';
1333
1334 cv->cv_serial = _2btol(sv->volseq);
1335 }
1336
1337 int
1338 ch_voltag_convert_out(cv, sv)
1339 const struct changer_voltag *cv;
1340 struct changer_volume_tag *sv;
1341 {
1342 int i;
1343
1344 memset(sv, ' ', sizeof(struct changer_volume_tag));
1345
1346 for (i = 0; i < sizeof(sv->volid); i++) {
1347 if (cv->cv_tag[i] == '\0')
1348 break;
1349 /*
1350 * Limit the character set to what is suggested in
1351 * the SCSI-2 spec.
1352 */
1353 if ((cv->cv_tag[i] < '0' || cv->cv_tag[i] > '9') &&
1354 (cv->cv_tag[i] < 'A' || cv->cv_tag[i] > 'Z') &&
1355 (cv->cv_tag[i] != '_'))
1356 return (EINVAL);
1357 sv->volid[i] = cv->cv_tag[i];
1358 }
1359
1360 _lto2b(cv->cv_serial, sv->volseq);
1361
1362 return (0);
1363 }
1364