uk.c revision 1.5 1 1.5 mycroft /*
2 1.5 mycroft * Copyright (c) 1994 Charles Hannum. All rights reserved.
3 1.5 mycroft *
4 1.5 mycroft * Redistribution and use in source and binary forms, with or without
5 1.5 mycroft * modification, are permitted provided that the following conditions
6 1.5 mycroft * are met:
7 1.5 mycroft * 1. Redistributions of source code must retain the above copyright
8 1.5 mycroft * notice, this list of conditions and the following disclaimer.
9 1.5 mycroft * 2. Redistributions in binary form must reproduce the above copyright
10 1.5 mycroft * notice, this list of conditions and the following disclaimer in the
11 1.5 mycroft * documentation and/or other materials provided with the distribution.
12 1.5 mycroft * 3. All advertising materials mentioning features or use of this software
13 1.5 mycroft * must display the following acknowledgement:
14 1.5 mycroft * This product includes software developed by Charles Hannum.
15 1.5 mycroft * 4. The name of the author may not be used to endorse or promote products
16 1.5 mycroft * derived from this software without specific prior written permission.
17 1.5 mycroft *
18 1.5 mycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.5 mycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.5 mycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.5 mycroft * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.5 mycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.5 mycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.5 mycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.5 mycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.5 mycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.5 mycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.5 mycroft *
29 1.5 mycroft * $Id: uk.c,v 1.5 1994/03/29 04:29:45 mycroft Exp $
30 1.5 mycroft */
31 1.5 mycroft
32 1.1 mycroft /*
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.1 mycroft #include <sys/errno.h>
40 1.1 mycroft #include <sys/ioctl.h>
41 1.4 mycroft #include <sys/device.h>
42 1.2 mycroft
43 1.1 mycroft #include <scsi/scsi_all.h>
44 1.1 mycroft #include <scsi/scsiconf.h>
45 1.2 mycroft
46 1.4 mycroft #define UKUNIT(z) (minor(z))
47 1.4 mycroft
48 1.4 mycroft struct uk_data {
49 1.4 mycroft struct device sc_dev;
50 1.4 mycroft
51 1.4 mycroft u_int32 flags;
52 1.4 mycroft #define UKINIT 0x01
53 1.4 mycroft struct scsi_link *sc_link; /* all the inter level info */
54 1.4 mycroft };
55 1.4 mycroft
56 1.4 mycroft void ukattach __P((struct device *, struct device *, void *));
57 1.4 mycroft
58 1.5 mycroft struct cfdriver ukcd = {
59 1.5 mycroft NULL, "uk", scsi_targmatch, ukattach, DV_DULL, sizeof(struct uk_data)
60 1.5 mycroft };
61 1.1 mycroft
62 1.1 mycroft /*
63 1.1 mycroft * This driver is so simple it uses all the default services
64 1.1 mycroft */
65 1.4 mycroft struct scsi_device uk_switch = {
66 1.3 mycroft NULL,
67 1.3 mycroft NULL,
68 1.3 mycroft NULL,
69 1.3 mycroft NULL,
70 1.3 mycroft "uk",
71 1.4 mycroft 0
72 1.1 mycroft };
73 1.1 mycroft
74 1.1 mycroft /*
75 1.1 mycroft * The routine called by the low level scsi routine when it discovers
76 1.1 mycroft * a device suitable for this driver.
77 1.1 mycroft */
78 1.4 mycroft void
79 1.4 mycroft ukattach(parent, self, aux)
80 1.4 mycroft struct device *parent, *self;
81 1.4 mycroft void *aux;
82 1.1 mycroft {
83 1.5 mycroft struct uk_data *uk = (void *)self;
84 1.4 mycroft struct scsi_link *sc_link = aux;
85 1.1 mycroft
86 1.1 mycroft SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
87 1.4 mycroft
88 1.1 mycroft /*
89 1.1 mycroft * Store information needed to contact our base driver
90 1.1 mycroft */
91 1.4 mycroft uk->sc_link = sc_link;
92 1.1 mycroft sc_link->device = &uk_switch;
93 1.4 mycroft sc_link->dev_unit = uk->sc_dev.dv_unit;
94 1.1 mycroft
95 1.4 mycroft printf(": unknown device\n");
96 1.4 mycroft uk->flags |= UKINIT;
97 1.1 mycroft }
98 1.1 mycroft
99 1.1 mycroft /*
100 1.4 mycroft * open the device.
101 1.1 mycroft */
102 1.4 mycroft int
103 1.1 mycroft ukopen(dev)
104 1.4 mycroft dev_t dev;
105 1.1 mycroft {
106 1.4 mycroft int unit;
107 1.4 mycroft struct uk_data *uk;
108 1.1 mycroft struct scsi_link *sc_link;
109 1.1 mycroft
110 1.4 mycroft unit = UKUNIT(dev);
111 1.4 mycroft
112 1.4 mycroft if (unit >= ukcd.cd_ndevs)
113 1.1 mycroft return ENXIO;
114 1.4 mycroft uk = ukcd.cd_devs[unit];
115 1.1 mycroft /*
116 1.1 mycroft * Make sure the device has been initialised
117 1.1 mycroft */
118 1.4 mycroft if (!uk || !(uk->cflags & UKINIT))
119 1.1 mycroft return ENXIO;
120 1.1 mycroft
121 1.4 mycroft sc_link = uk->sc_link;
122 1.4 mycroft
123 1.1 mycroft /*
124 1.1 mycroft * Only allow one at a time
125 1.1 mycroft */
126 1.1 mycroft if (sc_link->flags & SDEV_OPEN) {
127 1.4 mycroft printf("%s: already open\n", uk->sc_dev.dv_xname);
128 1.4 mycroft return EBUSY;
129 1.1 mycroft }
130 1.4 mycroft
131 1.1 mycroft sc_link->flags |= SDEV_OPEN;
132 1.4 mycroft SC_DEBUG(sc_link, SDEV_DB1,
133 1.4 mycroft ("ukopen: dev=0x%x (unit %d (of %d))\n", unit, ukcd.cd_ndevs));
134 1.4 mycroft
135 1.1 mycroft return 0;
136 1.1 mycroft }
137 1.1 mycroft
138 1.1 mycroft /*
139 1.1 mycroft * close the device.. only called if we are the LAST
140 1.1 mycroft * occurence of an open device
141 1.1 mycroft */
142 1.4 mycroft int
143 1.1 mycroft ukclose(dev)
144 1.4 mycroft dev_t dev;
145 1.1 mycroft {
146 1.4 mycroft int unit;
147 1.4 mycroft struct uk_data *uk;
148 1.1 mycroft
149 1.4 mycroft unit = UKUNIT(dev);
150 1.4 mycroft uk = ukcd.cd_devs[unit];
151 1.4 mycroft uk->sc_link->flags &= ~SDEV_OPEN;
152 1.4 mycroft SC_DEBUG(uk->sc_link, SDEV_DB1, ("closed\n"));
153 1.4 mycroft return 0;
154 1.1 mycroft }
155 1.1 mycroft
156 1.1 mycroft /*
157 1.1 mycroft * Perform special action on behalf of the user
158 1.1 mycroft * Only does generic scsi ioctls.
159 1.1 mycroft */
160 1.4 mycroft int
161 1.4 mycroft ukioctl(dev, cmd, addr, flag)
162 1.4 mycroft dev_t dev;
163 1.4 mycroft int cmd;
164 1.4 mycroft caddr_t addr;
165 1.4 mycroft int flag;
166 1.1 mycroft {
167 1.4 mycroft int unit;
168 1.4 mycroft register struct uk_data *uk;
169 1.1 mycroft struct scsi_link *sc_link;
170 1.1 mycroft
171 1.1 mycroft /*
172 1.1 mycroft * Find the device that the user is talking about
173 1.1 mycroft */
174 1.4 mycroft unit = UKUNIT(dev);
175 1.4 mycroft uk = ukcd.cd_devs[unit];
176 1.4 mycroft return scsi_do_ioctl(uk->sc_link, cmd, addr, flag));
177 1.1 mycroft }
178