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