1 /* $FreeBSD: src/sys/dev/iir/iir_ctrl.c,v 1.2.2.4 2002/05/05 08:18:12 asmodai Exp $ */
2 /* $DragonFly: src/sys/dev/raid/iir/iir_ctrl.c,v 1.7 2004/05/19 22:52:47 dillon Exp $ */
4 * Copyright (c) 2000-01 Intel Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
33 * iir_ctrl.c: Control functions and /dev entry points for /dev/iir*
35 * Written by: Achim Leubner <achim.leubner@intel.com>
36 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
41 #ident "$Id: iir_ctrl.c 1.2 2001/07/18 11:17:22 achim Exp $"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/malloc.h>
46 #include <sys/kernel.h>
50 #include <sys/disklabel.h>
51 #include <machine/bus.h>
53 #include <vm/vm_kern.h>
54 #include <vm/vm_extern.h>
59 /* Entry points and other prototypes */
60 static struct gdt_softc *gdt_minor2softc(int minor_no);
62 static d_open_t iir_open;
63 static d_close_t iir_close;
64 static d_write_t iir_write;
65 static d_read_t iir_read;
66 static d_ioctl_t iir_ioctl;
68 #define CDEV_MAJOR IIR_CDEV_MAJOR
70 /* Normally, this is a static structure. But we need it in pci/iir_pci.c */
71 static struct cdevsw iir_cdevsw = {
79 /* close */ iir_close,
81 /* write */ iir_write,
82 /* ioctl */ iir_ioctl,
85 /* strategy */ nostrategy,
90 static int iir_devsw_installed = 0;
92 static int sdev_made = 0;
96 extern char osrelease[];
97 extern gdt_statist_t gdt_stat;
100 * Given a controller number,
101 * make a special device and return the dev_t
104 gdt_make_dev(int unit)
109 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
110 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir%d", unit);
114 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
115 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, "iir");
123 gdt_destroy_dev(dev_t dev)
130 * Given a minor device number,
131 * return the pointer to its softc structure
133 static struct gdt_softc *
134 gdt_minor2softc(int minor_no)
136 struct gdt_softc *gdt;
140 hanum = minor2hba(minor_no);
145 for (gdt = TAILQ_FIRST(&gdt_softcs);
146 gdt != NULL && gdt->sc_hanum != hanum;
147 gdt = TAILQ_NEXT(gdt, links));
153 iir_open(dev_t dev, int flags, int fmt, d_thread_t * p)
155 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
159 struct gdt_softc *gdt;
161 minor_no = minor(dev);
162 gdt = gdt_minor2softc(minor_no);
171 iir_close(dev_t dev, int flags, int fmt, d_thread_t * p)
173 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
177 struct gdt_softc *gdt;
179 minor_no = minor(dev);
180 gdt = gdt_minor2softc(minor_no);
189 iir_write(dev_t dev, struct uio * uio, int ioflag)
191 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
195 struct gdt_softc *gdt;
197 minor_no = minor(dev);
198 gdt = gdt_minor2softc(minor_no);
207 iir_read(dev_t dev, struct uio * uio, int ioflag)
209 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
213 struct gdt_softc *gdt;
215 minor_no = minor(dev);
216 gdt = gdt_minor2softc(minor_no);
225 * This is the control syscall interface.
226 * It should be binary compatible with UnixWare,
227 * if not totally syntatically so.
231 iir_ioctl(dev_t dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
233 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
237 struct gdt_softc *gdt;
239 minor_no = minor(dev);
240 gdt = gdt_minor2softc(minor_no);
244 ++gdt_stat.io_count_act;
245 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
246 gdt_stat.io_count_max = gdt_stat.io_count_act;
249 case GDT_IOCTL_GENERAL:
252 struct gdt_softc *gdt;
255 ucmd = (gdt_ucmd_t *)cmdarg;
256 gdt = gdt_minor2softc(ucmd->io_node);
260 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
261 ucmd->complete_flag = FALSE;
264 if (!ucmd->complete_flag)
265 (void) tsleep((void *)ucmd, PCATCH, "iirucw", 0);
269 case GDT_IOCTL_DRVERS:
271 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
274 case GDT_IOCTL_CTRTYPE:
277 struct gdt_softc *gdt;
279 p = (gdt_ctrt_t *)cmdarg;
280 gdt = gdt_minor2softc(p->io_node);
285 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
286 p->ext_type = 0x6000 | gdt->sc_subdevice;
287 p->device_id = gdt->sc_device;
288 p->sub_device_id = gdt->sc_subdevice;
292 case GDT_IOCTL_OSVERS:
296 p = (gdt_osv_t *)cmdarg;
298 p->version = osrelease[0] - '0';
299 if (osrelease[1] == '.')
300 p->subversion = osrelease[2] - '0';
303 if (osrelease[3] == '.')
304 p->revision = osrelease[4] - '0';
307 strcpy(p->name, ostype);
311 case GDT_IOCTL_CTRCNT:
312 *(int *)cmdarg = gdt_cnt;
315 case GDT_IOCTL_EVENT:
320 p = (gdt_event_t *)cmdarg;
321 if (p->erase == 0xff) {
322 if (p->dvr.event_source == GDT_ES_TEST)
323 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
324 else if (p->dvr.event_source == GDT_ES_DRIVER)
325 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
326 else if (p->dvr.event_source == GDT_ES_SYNC)
327 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
329 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
331 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
334 } else if (p->erase == 0xfe) {
338 } else if (p->erase == 0) {
339 p->handle = gdt_read_event(p->handle, &p->dvr);
341 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
346 case GDT_IOCTL_STATIST:
350 p = (gdt_statist_t *)cmdarg;
351 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
359 --gdt_stat.io_count_act;
364 iir_drvinit(void *unused)
366 GDT_DPRINTF(GDT_D_DEBUG, ("iir_drvinit()\n"));
368 if (!iir_devsw_installed) {
369 /* Add the I/O (data) channel */
370 cdevsw_add(&iir_cdevsw, 0, 0);
371 iir_devsw_installed = 1;
375 SYSINIT(iir_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR, iir_drvinit, NULL)