uk.c revision 1.14 1 /* $NetBSD: uk.c,v 1.14 1996/03/05 00:15:33 thorpej 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("\n");
104 printf("%s: unknown device\n", uk->sc_dev.dv_xname);
105 }
106
107 /*
108 * open the device.
109 */
110 int
111 ukopen(dev)
112 dev_t dev;
113 {
114 int unit;
115 struct uk_softc *uk;
116 struct scsi_link *sc_link;
117
118 unit = UKUNIT(dev);
119 if (unit >= ukcd.cd_ndevs)
120 return ENXIO;
121 uk = ukcd.cd_devs[unit];
122 if (!uk)
123 return ENXIO;
124
125 sc_link = uk->sc_link;
126
127 SC_DEBUG(sc_link, SDEV_DB1,
128 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit, ukcd.cd_ndevs));
129
130 /*
131 * Only allow one at a time
132 */
133 if (sc_link->flags & SDEV_OPEN) {
134 printf("%s: already open\n", uk->sc_dev.dv_xname);
135 return EBUSY;
136 }
137
138 sc_link->flags |= SDEV_OPEN;
139
140 SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
141 return 0;
142 }
143
144 /*
145 * close the device.. only called if we are the LAST
146 * occurence of an open device
147 */
148 int
149 ukclose(dev)
150 dev_t dev;
151 {
152 struct uk_softc *uk = ukcd.cd_devs[UKUNIT(dev)];
153
154 SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n"));
155 uk->sc_link->flags &= ~SDEV_OPEN;
156
157 return 0;
158 }
159
160 /*
161 * Perform special action on behalf of the user
162 * Only does generic scsi ioctls.
163 */
164 int
165 ukioctl(dev, cmd, addr, flag, p)
166 dev_t dev;
167 u_long cmd;
168 caddr_t addr;
169 int flag;
170 struct proc *p;
171 {
172 register struct uk_softc *uk = ukcd.cd_devs[UKUNIT(dev)];
173
174 return scsi_do_ioctl(uk->sc_link, dev, cmd, addr, flag, p);
175 }
176