uk.c revision 1.27.10.1 1 /* $NetBSD: uk.c,v 1.27.10.1 1999/10/19 17:39:46 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Dummy driver for a device we can't identify.
41 * Originally by Julian Elischer (julian (at) tfs.com)
42 */
43
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/systm.h>
47
48 #include <sys/errno.h>
49 #include <sys/ioctl.h>
50 #include <sys/device.h>
51 #include <sys/conf.h>
52
53 #include <dev/scsipi/scsi_all.h>
54 #include <dev/scsipi/scsipi_all.h>
55 #include <dev/scsipi/scsiconf.h>
56
57 #define UKUNIT(z) (minor(z))
58
59 struct uk_softc {
60 struct device sc_dev;
61
62 struct scsipi_periph *sc_periph; /* all the inter level info */
63 };
64
65 int ukmatch __P((struct device *, struct cfdata *, void *));
66 void ukattach __P((struct device *, struct device *, void *));
67
68 struct cfattach uk_scsibus_ca = {
69 sizeof(struct uk_softc), ukmatch, ukattach
70 };
71 struct cfattach uk_atapibus_ca = {
72 sizeof(struct uk_softc), ukmatch, ukattach
73 };
74
75 extern struct cfdriver uk_cd;
76
77 cdev_decl(uk);
78
79 int
80 ukmatch(parent, match, aux)
81 struct device *parent;
82 struct cfdata *match;
83 void *aux;
84 {
85
86 return (1);
87 }
88
89 /*
90 * The routine called by the low level scsi routine when it discovers
91 * a device suitable for this driver.
92 */
93 void
94 ukattach(parent, self, aux)
95 struct device *parent, *self;
96 void *aux;
97 {
98 struct uk_softc *uk = (void *)self;
99 struct scsipibus_attach_args *sa = aux;
100 struct scsipi_periph *periph = sa->sa_periph;
101
102 SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
103
104 /*
105 * Store information needed to contact our base driver
106 */
107 uk->sc_periph = periph;
108 periph->periph_dev = &uk->sc_dev;
109
110 printf("\n");
111 printf("%s: unknown device\n", uk->sc_dev.dv_xname);
112 }
113
114 /*
115 * open the device.
116 */
117 int
118 ukopen(dev, flag, fmt, p)
119 dev_t dev;
120 int flag, fmt;
121 struct proc *p;
122 {
123 int unit, error;
124 struct uk_softc *uk;
125 struct scsipi_periph *periph;
126 struct scsipi_adapter *adapt;
127
128 unit = UKUNIT(dev);
129 if (unit >= uk_cd.cd_ndevs)
130 return (ENXIO);
131 uk = uk_cd.cd_devs[unit];
132 if (uk == NULL)
133 return (ENXIO);
134
135 periph = uk->sc_periph;
136 adapt = periph->periph_channel->chan_adapter;
137
138 SC_DEBUG(sc_link, SDEV_DB1,
139 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
140 uk_cd.cd_ndevs));
141
142 /*
143 * Only allow one at a time
144 */
145 if (periph->periph_flags & PERIPH_OPEN) {
146 printf("%s: already open\n", uk->sc_dev.dv_xname);
147 return (EBUSY);
148 }
149
150 if ((error = scsipi_adapter_addref(adapt)) != 0)
151 return (error);
152 periph->periph_flags |= PERIPH_OPEN;
153
154 SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
155 return (0);
156 }
157
158 /*
159 * close the device.. only called if we are the LAST
160 * occurence of an open device
161 */
162 int
163 ukclose(dev, flag, fmt, p)
164 dev_t dev;
165 int flag, fmt;
166 struct proc *p;
167 {
168 struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
169 struct scsipi_periph *periph = uk->sc_periph;
170 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
171
172 SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n"));
173
174 scsipi_wait_drain(periph);
175
176 scsipi_adapter_delref(adapt);
177 periph->periph_flags &= ~PERIPH_OPEN;
178
179 return (0);
180 }
181
182 /*
183 * Perform special action on behalf of the user
184 * Only does generic scsi ioctls.
185 */
186 int
187 ukioctl(dev, cmd, addr, flag, p)
188 dev_t dev;
189 u_long cmd;
190 caddr_t addr;
191 int flag;
192 struct proc *p;
193 {
194 register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
195
196 return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, p));
197 }
198