xref: /netbsd-src/sys/dev/scsipi/uk.c (revision ae9172d6cd9432a6a1a56760d86b32c57a66c39c)
1 /*	$NetBSD: uk.c,v 1.11 1994/11/21 11:28:57 mycroft 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@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_data {
49 	struct device sc_dev;
50 
51 	struct scsi_link *sc_link;	/* all the inter level info */
52 };
53 
54 void ukattach __P((struct device *, struct device *, void *));
55 
56 struct cfdriver ukcd = {
57 	NULL, "uk", scsi_targmatch, ukattach, DV_DULL, sizeof(struct uk_data)
58 };
59 
60 /*
61  * This driver is so simple it uses all the default services
62  */
63 struct scsi_device uk_switch = {
64 	NULL,
65 	NULL,
66 	NULL,
67 	NULL,
68 	"uk",
69 	0
70 };
71 
72 /*
73  * The routine called by the low level scsi routine when it discovers
74  * a device suitable for this driver.
75  */
76 void
77 ukattach(parent, self, aux)
78 	struct device *parent, *self;
79 	void *aux;
80 {
81 	struct uk_data *uk = (void *)self;
82 	struct scsi_link *sc_link = aux;
83 
84 	SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
85 
86 	/*
87 	 * Store information needed to contact our base driver
88 	 */
89 	uk->sc_link = sc_link;
90 	sc_link->device = &uk_switch;
91 	sc_link->device_softc = uk;
92 
93 	printf(": unknown device\n");
94 }
95 
96 /*
97  * open the device.
98  */
99 int
100 ukopen(dev)
101 	dev_t dev;
102 {
103 	int unit;
104 	struct uk_data *uk;
105 	struct scsi_link *sc_link;
106 
107 	unit = UKUNIT(dev);
108 	if (unit >= ukcd.cd_ndevs)
109 		return ENXIO;
110 	uk = ukcd.cd_devs[unit];
111 	if (!uk)
112 		return ENXIO;
113 
114 	sc_link = uk->sc_link;
115 
116 	SC_DEBUG(sc_link, SDEV_DB1,
117 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit, ukcd.cd_ndevs));
118 
119 	/*
120 	 * Only allow one at a time
121 	 */
122 	if (sc_link->flags & SDEV_OPEN) {
123 		printf("%s: already open\n", uk->sc_dev.dv_xname);
124 		return EBUSY;
125 	}
126 
127 	sc_link->flags |= SDEV_OPEN;
128 
129 	SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
130 	return 0;
131 }
132 
133 /*
134  * close the device.. only called if we are the LAST
135  * occurence of an open device
136  */
137 int
138 ukclose(dev)
139 	dev_t dev;
140 {
141 	struct uk_data *uk = ukcd.cd_devs[UKUNIT(dev)];
142 
143 	SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n"));
144 	uk->sc_link->flags &= ~SDEV_OPEN;
145 
146 	return 0;
147 }
148 
149 /*
150  * Perform special action on behalf of the user
151  * Only does generic scsi ioctls.
152  */
153 int
154 ukioctl(dev, cmd, addr, flag)
155 	dev_t dev;
156 	u_long cmd;
157 	caddr_t addr;
158 	int flag;
159 {
160 	register struct uk_data *uk = ukcd.cd_devs[UKUNIT(dev)];
161 
162 	return scsi_do_ioctl(uk->sc_link, dev, cmd, addr, flag));
163 }
164