uk.c revision 1.13 1 /* $NetBSD: uk.c,v 1.13 1995/03/24 20:17:15 glass Exp $ */
2
3 /*
4 * Copyright (c) 1994 Charles Hannum. All rights reserved.
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 Charles Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Dummy driver for a device we can't identify.
34 * Originally by Julian Elischer (julian (at) tfs.com)
35 */
36
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/device.h>
42
43 #include <scsi/scsi_all.h>
44 #include <scsi/scsiconf.h>
45
46 #define UKUNIT(z) (minor(z))
47
48 struct uk_softc {
49 struct device sc_dev;
50
51 struct scsi_link *sc_link; /* all the inter level info */
52 };
53
54 int ukmatch __P((struct device *, void *, void *));
55 void ukattach __P((struct device *, struct device *, void *));
56
57 struct cfdriver ukcd = {
58 NULL, "uk", ukmatch, ukattach, DV_DULL, sizeof(struct uk_softc)
59 };
60
61 /*
62 * This driver is so simple it uses all the default services
63 */
64 struct scsi_device uk_switch = {
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 };
70
71 int
72 ukmatch(parent, match, aux)
73 struct device *parent;
74 void *match, *aux;
75 {
76
77 return 1;
78 }
79
80 /*
81 * The routine called by the low level scsi routine when it discovers
82 * a device suitable for this driver.
83 */
84 void
85 ukattach(parent, self, aux)
86 struct device *parent, *self;
87 void *aux;
88 {
89 struct uk_softc *uk = (void *)self;
90 struct scsibus_attach_args *sa = aux;
91 struct scsi_link *sc_link = sa->sa_sc_link;
92
93 SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
94
95 /*
96 * Store information needed to contact our base driver
97 */
98 uk->sc_link = sc_link;
99 sc_link->device = &uk_switch;
100 sc_link->device_softc = uk;
101 sc_link->openings = 1;
102
103 printf(": unknown device\n");
104 }
105
106 /*
107 * open the device.
108 */
109 int
110 ukopen(dev)
111 dev_t dev;
112 {
113 int unit;
114 struct uk_softc *uk;
115 struct scsi_link *sc_link;
116
117 unit = UKUNIT(dev);
118 if (unit >= ukcd.cd_ndevs)
119 return ENXIO;
120 uk = ukcd.cd_devs[unit];
121 if (!uk)
122 return ENXIO;
123
124 sc_link = uk->sc_link;
125
126 SC_DEBUG(sc_link, SDEV_DB1,
127 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit, ukcd.cd_ndevs));
128
129 /*
130 * Only allow one at a time
131 */
132 if (sc_link->flags & SDEV_OPEN) {
133 printf("%s: already open\n", uk->sc_dev.dv_xname);
134 return EBUSY;
135 }
136
137 sc_link->flags |= SDEV_OPEN;
138
139 SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
140 return 0;
141 }
142
143 /*
144 * close the device.. only called if we are the LAST
145 * occurence of an open device
146 */
147 int
148 ukclose(dev)
149 dev_t dev;
150 {
151 struct uk_softc *uk = ukcd.cd_devs[UKUNIT(dev)];
152
153 SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n"));
154 uk->sc_link->flags &= ~SDEV_OPEN;
155
156 return 0;
157 }
158
159 /*
160 * Perform special action on behalf of the user
161 * Only does generic scsi ioctls.
162 */
163 int
164 ukioctl(dev, cmd, addr, flag, p)
165 dev_t dev;
166 u_long cmd;
167 caddr_t addr;
168 int flag;
169 struct proc *p;
170 {
171 register struct uk_softc *uk = ukcd.cd_devs[UKUNIT(dev)];
172
173 return scsi_do_ioctl(uk->sc_link, dev, cmd, addr, flag, p);
174 }
175