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