FreeBSD/Linux Kernel Cross Reference
sys/dev/scsipi/uk.c
1 /* $NetBSD: uk.c,v 1.45 2005/02/27 00:27:48 perry 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@tfs.com)
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.45 2005/02/27 00:27:48 perry Exp $");
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49
50 #include <sys/errno.h>
51 #include <sys/ioctl.h>
52 #include <sys/device.h>
53 #include <sys/conf.h>
54 #include <sys/vnode.h>
55
56 #include <dev/scsipi/scsi_all.h>
57 #include <dev/scsipi/scsipi_all.h>
58 #include <dev/scsipi/scsiconf.h>
59
60 #define UKUNIT(z) (minor(z))
61
62 struct uk_softc {
63 struct device sc_dev;
64
65 struct scsipi_periph *sc_periph; /* all the inter level info */
66 };
67
68 static int ukmatch(struct device *, struct cfdata *, void *);
69 static void ukattach(struct device *, struct device *, void *);
70 static int ukactivate(struct device *, enum devact);
71 static int ukdetach(struct device *, int);
72
73
74 CFATTACH_DECL(uk, sizeof(struct uk_softc), ukmatch, ukattach, ukdetach,
75 ukactivate);
76
77 extern struct cfdriver uk_cd;
78
79 static dev_type_open(ukopen);
80 static dev_type_close(ukclose);
81 static dev_type_ioctl(ukioctl);
82
83 const struct cdevsw uk_cdevsw = {
84 ukopen, ukclose, noread, nowrite, ukioctl,
85 nostop, notty, nopoll, nommap, nokqfilter,
86 };
87
88 static int
89 ukmatch(struct device *parent, struct cfdata *match, void *aux)
90 {
91
92 return (1);
93 }
94
95 /*
96 * The routine called by the low level scsi routine when it discovers
97 * a device suitable for this driver.
98 */
99 static void
100 ukattach(struct device *parent, struct device *self, void *aux)
101 {
102 struct uk_softc *uk = (void *)self;
103 struct scsipibus_attach_args *sa = aux;
104 struct scsipi_periph *periph = sa->sa_periph;
105
106 SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: "));
107
108 /*
109 * Store information needed to contact our base driver
110 */
111 uk->sc_periph = periph;
112 periph->periph_dev = &uk->sc_dev;
113
114 printf("\n");
115 }
116
117 static int
118 ukactivate(struct device *self, enum devact act)
119 {
120 int rv = 0;
121
122 switch (act) {
123 case DVACT_ACTIVATE:
124 rv = EOPNOTSUPP;
125 break;
126
127 case DVACT_DEACTIVATE:
128 /*
129 * Nothing to do; we key off the device's DVF_ACTIVE.
130 */
131 break;
132 }
133 return (rv);
134 }
135
136 static int
137 ukdetach(struct device *self, int flags)
138 {
139 /*struct uk_softc *uk = (struct uk_softc *) self;*/
140 int cmaj, mn;
141
142 /* locate the major number */
143 cmaj = cdevsw_lookup_major(&uk_cdevsw);
144
145 /* Nuke the vnodes for any open instances */
146 mn = self->dv_unit;
147 vdevgone(cmaj, mn, mn, VCHR);
148
149 return (0);
150 }
151
152 /*
153 * open the device.
154 */
155 static int
156 ukopen(dev_t dev, int flag, int fmt, struct proc *p)
157 {
158 int unit, error;
159 struct uk_softc *uk;
160 struct scsipi_periph *periph;
161 struct scsipi_adapter *adapt;
162
163 unit = UKUNIT(dev);
164 if (unit >= uk_cd.cd_ndevs)
165 return (ENXIO);
166 uk = uk_cd.cd_devs[unit];
167 if (uk == NULL)
168 return (ENXIO);
169
170 periph = uk->sc_periph;
171 adapt = periph->periph_channel->chan_adapter;
172
173 SC_DEBUG(periph, SCSIPI_DB1,
174 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
175 uk_cd.cd_ndevs));
176
177 /*
178 * Only allow one at a time
179 */
180 if (periph->periph_flags & PERIPH_OPEN) {
181 printf("%s: already open\n", uk->sc_dev.dv_xname);
182 return (EBUSY);
183 }
184
185 if ((error = scsipi_adapter_addref(adapt)) != 0)
186 return (error);
187 periph->periph_flags |= PERIPH_OPEN;
188
189 SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
190 return (0);
191 }
192
193 /*
194 * close the device.. only called if we are the LAST
195 * occurence of an open device
196 */
197 static int
198 ukclose(dev_t dev, int flag, int fmt, struct proc *p)
199 {
200 struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
201 struct scsipi_periph *periph = uk->sc_periph;
202 struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
203
204 SC_DEBUG(uk->sc_periph, SCSIPI_DB1, ("closing\n"));
205
206 scsipi_wait_drain(periph);
207
208 scsipi_adapter_delref(adapt);
209 periph->periph_flags &= ~PERIPH_OPEN;
210
211 return (0);
212 }
213
214 /*
215 * Perform special action on behalf of the user
216 * Only does generic scsi ioctls.
217 */
218 static int
219 ukioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
220 {
221 register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
222
223 return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, p));
224 }
Cache object: e2719318491da010eb405a68eb023a83
|