uk.c revision 1.2 1
2 /*
3 * Dummy driver for a device we can't identify.
4 * by Julian Elischer (julian (at) tfs.com)
5 *
6 * $Id: uk.c,v 1.2 1993/12/17 08:51:13 mycroft Exp $
7 */
8
9
10 #include <sys/types.h>
11 #include <sys/param.h>
12 #include <sys/errno.h>
13 #include <sys/ioctl.h>
14
15 #include <scsi/scsi_all.h>
16 #include <scsi/scsiconf.h>
17
18 #define NUK 16
19
20 /*
21 * This driver is so simple it uses all the default services
22 */
23 struct scsi_device uk_switch =
24 {
25 NULL,
26 NULL,
27 NULL,
28 NULL,
29 "uk",
30 0,
31 0, 0
32 };
33
34 struct uk_data {
35 u_int32 flags;
36 struct scsi_link *sc_link; /* all the inter level info */
37 } uk_data[NUK];
38
39 #define UK_KNOWN 0x02
40
41 static u_int32 next_uk_unit = 0;
42
43 /*
44 * The routine called by the low level scsi routine when it discovers
45 * a device suitable for this driver.
46 */
47 errval
48 ukattach(sc_link)
49 struct scsi_link *sc_link;
50 {
51 u_int32 unit, i, stat;
52 unsigned char *tbl;
53
54 SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
55 /*
56 * Check we have the resources for another drive
57 */
58 unit = next_uk_unit++;
59 if (unit >= NUK) {
60 printf("Too many unknown devices..(%d > %d) reconfigure kernel\n",
61 (unit + 1), NUK);
62 return (0);
63 }
64 /*
65 * Store information needed to contact our base driver
66 */
67 uk_data[unit].sc_link = sc_link;
68 sc_link->device = &uk_switch;
69 sc_link->dev_unit = unit;
70
71 printf("uk%d: unknown device\n", unit);
72 uk_data[unit].flags = UK_KNOWN;
73
74 return;
75
76 }
77
78 /*
79 * open the device.
80 */
81 errval
82 ukopen(dev)
83 {
84 errval errcode = 0;
85 u_int32 unit, mode;
86 struct scsi_link *sc_link;
87 unit = minor(dev);
88
89 /*
90 * Check the unit is legal
91 */
92 if (unit >= NUK) {
93 printf("uk%d: uk %d > %d\n", unit, unit, NUK);
94 return ENXIO;
95 }
96
97 /*
98 * Make sure the device has been initialised
99 */
100 if((uk_data[unit].flags & UK_KNOWN) == 0) {
101 printf("uk%d: not set up\n", unit);
102 return ENXIO;
103 }
104
105 /*
106 * Only allow one at a time
107 */
108 sc_link = uk_data[unit].sc_link;
109 if (sc_link->flags & SDEV_OPEN) {
110 printf("uk%d: already open\n", unit);
111 return ENXIO;
112 }
113 sc_link->flags |= SDEV_OPEN;
114 SC_DEBUG(sc_link, SDEV_DB1, ("ukopen: dev=0x%x (unit %d (of %d))\n"
115 ,dev, unit, NUK));
116 /*
117 * Catch any unit attention errors.
118 */
119 return 0;
120 }
121
122 /*
123 * close the device.. only called if we are the LAST
124 * occurence of an open device
125 */
126 errval
127 ukclose(dev)
128 {
129 unsigned char unit, mode;
130 struct scsi_link *sc_link;
131
132 sc_link = uk_data[unit].sc_link;
133
134 SC_DEBUG(sc_link, SDEV_DB1, ("Closing device"));
135 sc_link->flags &= ~SDEV_OPEN;
136 return (0);
137 }
138
139 /*
140 * Perform special action on behalf of the user
141 * Only does generic scsi ioctls.
142 */
143 errval
144 ukioctl(dev, cmd, arg, mode)
145 dev_t dev;
146 u_int32 cmd;
147 caddr_t arg;
148 {
149 unsigned char unit;
150 struct scsi_link *sc_link;
151
152 /*
153 * Find the device that the user is talking about
154 */
155 unit = minor(dev);
156 sc_link = uk_data[unit].sc_link;
157 return(scsi_do_ioctl(sc_link,cmd,arg,mode));
158 }
159
160