FreeBSD/Linux Kernel Cross Reference
sys/dev/iir/iir_ctrl.c
1 /*-
2 * Copyright (c) 2000-03 ICP vortex GmbH
3 * Copyright (c) 2002-03 Intel Corporation
4 * Copyright (c) 2003 Adaptec Inc.
5 * All Rights Reserved
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*
33 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
34 *
35 * Written by: Achim Leubner <achim_leubner@adaptec.com>
36 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
37 *
38 * $Id: iir_ctrl.c 1.3 2003/08/26 12:31:15 achim Exp $"
39 */
40
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/endian.h>
47 #include <sys/malloc.h>
48 #include <sys/kernel.h>
49 #include <sys/uio.h>
50 #include <sys/conf.h>
51 #include <sys/disk.h>
52 #include <sys/stat.h>
53 #include <sys/disklabel.h>
54 #include <machine/bus.h>
55
56 #include <dev/iir/iir.h>
57
58 /* Entry points and other prototypes */
59 static struct gdt_softc *gdt_minor2softc(int minor_no);
60
61 static d_open_t iir_open;
62 static d_close_t iir_close;
63 static d_write_t iir_write;
64 static d_read_t iir_read;
65 static d_ioctl_t iir_ioctl;
66
67 /* Normally, this is a static structure. But we need it in pci/iir_pci.c */
68 static struct cdevsw iir_cdevsw = {
69 .d_version = D_VERSION,
70 .d_flags = D_NEEDGIANT,
71 .d_open = iir_open,
72 .d_close = iir_close,
73 .d_read = iir_read,
74 .d_write = iir_write,
75 .d_ioctl = iir_ioctl,
76 .d_name = "iir",
77 };
78
79 /*
80 static int iir_devsw_installed = 0;
81 */
82 #ifndef SDEV_PER_HBA
83 static int sdev_made = 0;
84 #endif
85 extern int gdt_cnt;
86 extern char ostype[];
87 extern char osrelease[];
88 extern gdt_statist_t gdt_stat;
89
90 /*
91 * Given a controller number,
92 * make a special device and return the dev_t
93 */
94 struct cdev *
95 gdt_make_dev(int unit)
96 {
97 struct cdev *dev;
98
99 #ifdef SDEV_PER_HBA
100 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
101 S_IRUSR | S_IWUSR, "iir%d", unit);
102 #else
103 if (sdev_made)
104 return (0);
105 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
106 S_IRUSR | S_IWUSR, "iir");
107 sdev_made = 1;
108 #endif
109 return (dev);
110 }
111
112 void
113 gdt_destroy_dev(struct cdev *dev)
114 {
115 if (dev != NULL)
116 destroy_dev(dev);
117 }
118
119 /*
120 * Given a minor device number,
121 * return the pointer to its softc structure
122 */
123 static struct gdt_softc *
124 gdt_minor2softc(int minor_no)
125 {
126 struct gdt_softc *gdt;
127 int hanum;
128
129 #ifdef SDEV_PER_HBA
130 hanum = minor2hba(minor_no);
131 #else
132 hanum = minor_no;
133 #endif
134
135 for (gdt = TAILQ_FIRST(&gdt_softcs);
136 gdt != NULL && gdt->sc_hanum != hanum;
137 gdt = TAILQ_NEXT(gdt, links));
138
139 return (gdt);
140 }
141
142 static int
143 iir_open(struct cdev *dev, int flags, int fmt, d_thread_t * p)
144 {
145 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
146
147 #ifdef SDEV_PER_HBA
148 int minor_no;
149 struct gdt_softc *gdt;
150
151 minor_no = minor(dev);
152 gdt = gdt_minor2softc(minor_no);
153 if (gdt == NULL)
154 return (ENXIO);
155 #endif
156
157 return (0);
158 }
159
160 static int
161 iir_close(struct cdev *dev, int flags, int fmt, d_thread_t * p)
162 {
163 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
164
165 #ifdef SDEV_PER_HBA
166 int minor_no;
167 struct gdt_softc *gdt;
168
169 minor_no = minor(dev);
170 gdt = gdt_minor2softc(minor_no);
171 if (gdt == NULL)
172 return (ENXIO);
173 #endif
174
175 return (0);
176 }
177
178 static int
179 iir_write(struct cdev *dev, struct uio * uio, int ioflag)
180 {
181 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
182
183 #ifdef SDEV_PER_HBA
184 int minor_no;
185 struct gdt_softc *gdt;
186
187 minor_no = minor(dev);
188 gdt = gdt_minor2softc(minor_no);
189 if (gdt == NULL)
190 return (ENXIO);
191 #endif
192
193 return (0);
194 }
195
196 static int
197 iir_read(struct cdev *dev, struct uio * uio, int ioflag)
198 {
199 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
200
201 #ifdef SDEV_PER_HBA
202 int minor_no;
203 struct gdt_softc *gdt;
204
205 minor_no = minor(dev);
206 gdt = gdt_minor2softc(minor_no);
207 if (gdt == NULL)
208 return (ENXIO);
209 #endif
210
211 return (0);
212 }
213
214 /**
215 * This is the control syscall interface.
216 * It should be binary compatible with UnixWare,
217 * if not totally syntatically so.
218 */
219
220 static int
221 iir_ioctl(struct cdev *dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
222 {
223 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
224
225 #ifdef SDEV_PER_HBA
226 int minor_no;
227 struct gdt_softc *gdt;
228
229 minor_no = minor(dev);
230 gdt = gdt_minor2softc(minor_no);
231 if (gdt == NULL)
232 return (ENXIO);
233 #endif
234 ++gdt_stat.io_count_act;
235 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
236 gdt_stat.io_count_max = gdt_stat.io_count_act;
237
238 switch (cmd) {
239 case GDT_IOCTL_GENERAL:
240 {
241 gdt_ucmd_t *ucmd;
242 struct gdt_softc *gdt;
243 int lock;
244
245 ucmd = (gdt_ucmd_t *)cmdarg;
246 gdt = gdt_minor2softc(ucmd->io_node);
247 if (gdt == NULL)
248 return (ENXIO);
249 lock = splcam();
250 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
251 ucmd->complete_flag = FALSE;
252 splx(lock);
253 gdt_next(gdt);
254 if (!ucmd->complete_flag)
255 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
256 break;
257 }
258
259 case GDT_IOCTL_DRVERS:
260 case GDT_IOCTL_DRVERS_OLD:
261 *(int *)cmdarg =
262 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
263 break;
264
265 case GDT_IOCTL_CTRTYPE:
266 case GDT_IOCTL_CTRTYPE_OLD:
267 {
268 gdt_ctrt_t *p;
269 struct gdt_softc *gdt;
270
271 p = (gdt_ctrt_t *)cmdarg;
272 gdt = gdt_minor2softc(p->io_node);
273 if (gdt == NULL)
274 return (ENXIO);
275 /* only RP controllers */
276 p->ext_type = 0x6000 | gdt->sc_device;
277 if (gdt->sc_vendor == INTEL_VENDOR_ID) {
278 p->oem_id = OEM_ID_INTEL;
279 p->type = 0xfd;
280 /* new -> subdevice into ext_type */
281 if (gdt->sc_device >= 0x600)
282 p->ext_type = 0x6000 | gdt->sc_subdevice;
283 } else {
284 p->oem_id = OEM_ID_ICP;
285 p->type = 0xfe;
286 /* new -> subdevice into ext_type */
287 if (gdt->sc_device >= 0x300)
288 p->ext_type = 0x6000 | gdt->sc_subdevice;
289 }
290 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
291 p->device_id = gdt->sc_device;
292 p->sub_device_id = gdt->sc_subdevice;
293 break;
294 }
295
296 case GDT_IOCTL_OSVERS:
297 {
298 gdt_osv_t *p;
299
300 p = (gdt_osv_t *)cmdarg;
301 p->oscode = 10;
302 p->version = osrelease[0] - '';
303 if (osrelease[1] == '.')
304 p->subversion = osrelease[2] - '';
305 else
306 p->subversion = 0;
307 if (osrelease[3] == '.')
308 p->revision = osrelease[4] - '';
309 else
310 p->revision = 0;
311 strcpy(p->name, ostype);
312 break;
313 }
314
315 case GDT_IOCTL_CTRCNT:
316 *(int *)cmdarg = gdt_cnt;
317 break;
318
319 case GDT_IOCTL_EVENT:
320 {
321 gdt_event_t *p;
322 int lock;
323
324 p = (gdt_event_t *)cmdarg;
325 if (p->erase == 0xff) {
326 if (p->dvr.event_source == GDT_ES_TEST)
327 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
328 else if (p->dvr.event_source == GDT_ES_DRIVER)
329 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
330 else if (p->dvr.event_source == GDT_ES_SYNC)
331 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
332 else
333 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
334 lock = splcam();
335 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
336 &p->dvr.event_data);
337 splx(lock);
338 } else if (p->erase == 0xfe) {
339 lock = splcam();
340 gdt_clear_events();
341 splx(lock);
342 } else if (p->erase == 0) {
343 p->handle = gdt_read_event(p->handle, &p->dvr);
344 } else {
345 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
346 }
347 break;
348 }
349
350 case GDT_IOCTL_STATIST:
351 {
352 gdt_statist_t *p;
353
354 p = (gdt_statist_t *)cmdarg;
355 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
356 break;
357 }
358
359 default:
360 break;
361 }
362
363 --gdt_stat.io_count_act;
364 return (0);
365 }
366
367 /*
368 static void
369 iir_drvinit(void *unused)
370 {
371 GDT_DPRINTF(GDT_D_DEBUG, ("iir_drvinit()\n"));
372
373 if (!iir_devsw_installed) {
374 cdevsw_add(&iir_cdevsw);
375 iir_devsw_installed = 1;
376 }
377 }
378
379 SYSINIT(iir_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, iir_drvinit, NULL)
380 */
Cache object: 229b9b21f450414214a5150b10c2b023
|