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