st_atapi.c revision 1.3 1 /* $NetBSD: st_atapi.c,v 1.3 2001/06/18 09:41:06 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 2001 Manuel Bouyer.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35
36 #include "opt_scsi.h"
37 #include "rnd.h"
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/device.h>
42 #include <sys/buf.h>
43 #include <sys/conf.h>
44 #include <sys/kernel.h>
45 #include <sys/systm.h>
46
47 #include <dev/scsipi/stvar.h>
48 #include <dev/scsipi/atapi_tape.h>
49
50 int st_atapibus_match __P((struct device *, struct cfdata *, void *));
51 void st_atapibus_attach __P((struct device *, struct device *, void *));
52 int st_atapibus_ops __P((struct st_softc *, int, int));
53 int st_atapibus_mode_sense __P((struct st_softc *, int));
54 int st_atapibus_mode_select __P((struct st_softc *, int));
55 int st_atapibus_do_ms __P((struct st_softc *, int, void *, int, int));
56
57 struct cfattach st_atapibus_ca = {
58 sizeof(struct st_softc), st_atapibus_match, st_atapibus_attach
59 };
60
61 const struct scsipi_inquiry_pattern st_atapibus_patterns[] = {
62 {T_SEQUENTIAL, T_REMOV,
63 "", "", ""},
64 };
65
66 int
67 st_atapibus_match(parent, match, aux)
68 struct device *parent;
69 struct cfdata *match;
70 void *aux;
71 {
72 struct scsipibus_attach_args *sa = aux;
73 int priority;
74
75 if (scsipi_periph_bustype(sa->sa_periph) != SCSIPI_BUSTYPE_ATAPI)
76 return (0);
77
78 (void)scsipi_inqmatch(&sa->sa_inqbuf,
79 (caddr_t)st_atapibus_patterns,
80 sizeof(st_atapibus_patterns)/sizeof(st_atapibus_patterns[0]),
81 sizeof(st_atapibus_patterns[0]), &priority);
82 return (priority);
83 }
84
85 void
86 st_atapibus_attach(parent, self, aux)
87 struct device *parent, *self;
88 void *aux;
89 {
90 struct st_softc *st = (void *)self;
91
92 st->ops = st_atapibus_ops;
93 stattach(parent, st, aux);
94 }
95
96 int
97 st_atapibus_ops(st, op, flags)
98 struct st_softc *st;
99 int op;
100 int flags;
101 {
102 switch(op) {
103 case ST_OPS_RBL:
104 /* done in mode_sense */
105 return 0;
106 case ST_OPS_MODESENSE:
107 return st_atapibus_mode_sense(st, flags);
108 case ST_OPS_MODESELECT:
109 return st_atapibus_mode_select(st, flags);
110 case ST_OPS_CMPRSS_ON:
111 case ST_OPS_CMPRSS_OFF:
112 return ENODEV;
113 default:
114 panic("st_scsibus_ops: invalid op");
115 /* NOTREACHED */
116 }
117 }
118
119 int
120 st_atapibus_mode_sense(st, flags)
121 struct st_softc *st;
122 int flags;
123 {
124 int count, error;
125 struct atapi_cappage cappage;
126 struct scsipi_periph *periph = st->sc_periph;
127
128 /* get drive capabilities, some drives needs this repeated */
129 for (count = 0 ; count < 5 ; count++) {
130 error = scsipi_mode_sense(periph, SMS_DBD,
131 ATAPI_TAPE_CAP_PAGE, &cappage.header, sizeof(cappage),
132 flags | XS_CTL_DATA_ONSTACK, ST_RETRIES, ST_CTL_TIME);
133 if (error == 0) {
134 st->numblks = 0; /* unused anyway */
135 if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK32K)
136 st->media_blksize = 32768;
137 else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK1K)
138 st->media_blksize = 1024;
139 else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK512)
140 st->media_blksize = 512;
141 else {
142 error = ENODEV;
143 continue;
144 }
145 st->blkmin = st->blkmax = st->media_blksize;
146 st->media_density = 0;
147 if (cappage.header.dev_spec & SMH_DSP_WRITE_PROT)
148 st->flags |= ST_READONLY;
149 else
150 st->flags &= ~ST_READONLY;
151 SC_DEBUG(periph, SCSIPI_DB3,
152 ("density code %d, %d-byte blocks, write-%s, ",
153 st->media_density, st->media_blksize,
154 st->flags & ST_READONLY ? "protected" : "enabled"));
155 SC_DEBUG(periph, SCSIPI_DB3,
156 ("%sbuffered\n",
157 cappage.header.dev_spec & SMH_DSP_BUFF_MODE ?
158 "" : "un"));
159 periph->periph_flags |= PERIPH_MEDIA_LOADED;
160 return 0;
161 }
162 }
163 return error;
164 }
165
166 int
167 st_atapibus_mode_select(st, flags)
168 struct st_softc *st;
169 int flags;
170 {
171 return ENODEV; /* for now ... */
172 }
173