st_atapi.c revision 1.4 1 /* $NetBSD: st_atapi.c,v 1.4 2001/11/13 06:56:41 lukem 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 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: st_atapi.c,v 1.4 2001/11/13 06:56:41 lukem Exp $");
37
38 #include "opt_scsi.h"
39 #include "rnd.h"
40
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <sys/device.h>
44 #include <sys/buf.h>
45 #include <sys/conf.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48
49 #include <dev/scsipi/stvar.h>
50 #include <dev/scsipi/atapi_tape.h>
51
52 int st_atapibus_match __P((struct device *, struct cfdata *, void *));
53 void st_atapibus_attach __P((struct device *, struct device *, void *));
54 int st_atapibus_ops __P((struct st_softc *, int, int));
55 int st_atapibus_mode_sense __P((struct st_softc *, int));
56 int st_atapibus_mode_select __P((struct st_softc *, int));
57 int st_atapibus_do_ms __P((struct st_softc *, int, void *, int, int));
58
59 struct cfattach st_atapibus_ca = {
60 sizeof(struct st_softc), st_atapibus_match, st_atapibus_attach
61 };
62
63 const struct scsipi_inquiry_pattern st_atapibus_patterns[] = {
64 {T_SEQUENTIAL, T_REMOV,
65 "", "", ""},
66 };
67
68 int
69 st_atapibus_match(parent, match, aux)
70 struct device *parent;
71 struct cfdata *match;
72 void *aux;
73 {
74 struct scsipibus_attach_args *sa = aux;
75 int priority;
76
77 if (scsipi_periph_bustype(sa->sa_periph) != SCSIPI_BUSTYPE_ATAPI)
78 return (0);
79
80 (void)scsipi_inqmatch(&sa->sa_inqbuf,
81 (caddr_t)st_atapibus_patterns,
82 sizeof(st_atapibus_patterns)/sizeof(st_atapibus_patterns[0]),
83 sizeof(st_atapibus_patterns[0]), &priority);
84 return (priority);
85 }
86
87 void
88 st_atapibus_attach(parent, self, aux)
89 struct device *parent, *self;
90 void *aux;
91 {
92 struct st_softc *st = (void *)self;
93
94 st->ops = st_atapibus_ops;
95 stattach(parent, st, aux);
96 }
97
98 int
99 st_atapibus_ops(st, op, flags)
100 struct st_softc *st;
101 int op;
102 int flags;
103 {
104 switch(op) {
105 case ST_OPS_RBL:
106 /* done in mode_sense */
107 return 0;
108 case ST_OPS_MODESENSE:
109 return st_atapibus_mode_sense(st, flags);
110 case ST_OPS_MODESELECT:
111 return st_atapibus_mode_select(st, flags);
112 case ST_OPS_CMPRSS_ON:
113 case ST_OPS_CMPRSS_OFF:
114 return ENODEV;
115 default:
116 panic("st_scsibus_ops: invalid op");
117 /* NOTREACHED */
118 }
119 }
120
121 int
122 st_atapibus_mode_sense(st, flags)
123 struct st_softc *st;
124 int flags;
125 {
126 int count, error;
127 struct atapi_cappage cappage;
128 struct scsipi_periph *periph = st->sc_periph;
129
130 /* get drive capabilities, some drives needs this repeated */
131 for (count = 0 ; count < 5 ; count++) {
132 error = scsipi_mode_sense(periph, SMS_DBD,
133 ATAPI_TAPE_CAP_PAGE, &cappage.header, sizeof(cappage),
134 flags | XS_CTL_DATA_ONSTACK, ST_RETRIES, ST_CTL_TIME);
135 if (error == 0) {
136 st->numblks = 0; /* unused anyway */
137 if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK32K)
138 st->media_blksize = 32768;
139 else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK1K)
140 st->media_blksize = 1024;
141 else if (cappage.cap4 & ATAPI_TAPE_CAP_PAGE_BLK512)
142 st->media_blksize = 512;
143 else {
144 error = ENODEV;
145 continue;
146 }
147 st->blkmin = st->blkmax = st->media_blksize;
148 st->media_density = 0;
149 if (cappage.header.dev_spec & SMH_DSP_WRITE_PROT)
150 st->flags |= ST_READONLY;
151 else
152 st->flags &= ~ST_READONLY;
153 SC_DEBUG(periph, SCSIPI_DB3,
154 ("density code %d, %d-byte blocks, write-%s, ",
155 st->media_density, st->media_blksize,
156 st->flags & ST_READONLY ? "protected" : "enabled"));
157 SC_DEBUG(periph, SCSIPI_DB3,
158 ("%sbuffered\n",
159 cappage.header.dev_spec & SMH_DSP_BUFF_MODE ?
160 "" : "un"));
161 periph->periph_flags |= PERIPH_MEDIA_LOADED;
162 return 0;
163 }
164 }
165 return error;
166 }
167
168 int
169 st_atapibus_mode_select(st, flags)
170 struct st_softc *st;
171 int flags;
172 {
173 return ENODEV; /* for now ... */
174 }
175