2 * Copyright (c) 2000-03 ICP vortex GmbH
3 * Copyright (c) 2002-03 Intel Corporation
4 * Copyright (c) 2003 Adaptec Inc.
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@adaptec.com>
36 * Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
38 * $Id: iir_ctrl.c 1.3 2003/08/26 12:31:15 achim Exp $"
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
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>
53 #include <sys/disklabel.h>
54 #include <machine/bus.h>
56 #include <vm/vm_kern.h>
57 #include <vm/vm_extern.h>
60 #include <dev/iir/iir.h>
62 /* Entry points and other prototypes */
63 static struct gdt_softc *gdt_minor2softc(int minor_no);
65 static d_open_t iir_open;
66 static d_close_t iir_close;
67 static d_write_t iir_write;
68 static d_read_t iir_read;
69 static d_ioctl_t iir_ioctl;
71 /* Normally, this is a static structure. But we need it in pci/iir_pci.c */
72 static struct cdevsw iir_cdevsw = {
73 .d_version = D_VERSION,
74 .d_flags = D_NEEDGIANT,
84 static int iir_devsw_installed = 0;
87 static int sdev_made = 0;
91 extern char osrelease[];
92 extern gdt_statist_t gdt_stat;
95 * Given a controller number,
96 * make a special device and return the dev_t
99 gdt_make_dev(int unit)
104 dev = make_dev(&iir_cdevsw, hba2minor(unit), UID_ROOT, GID_OPERATOR,
105 S_IRUSR | S_IWUSR, "iir%d", unit);
109 dev = make_dev(&iir_cdevsw, 0, UID_ROOT, GID_OPERATOR,
110 S_IRUSR | S_IWUSR, "iir");
117 gdt_destroy_dev(struct cdev *dev)
124 * Given a minor device number,
125 * return the pointer to its softc structure
127 static struct gdt_softc *
128 gdt_minor2softc(int minor_no)
130 struct gdt_softc *gdt;
134 hanum = minor2hba(minor_no);
139 for (gdt = TAILQ_FIRST(&gdt_softcs);
140 gdt != NULL && gdt->sc_hanum != hanum;
141 gdt = TAILQ_NEXT(gdt, links));
147 iir_open(struct cdev *dev, int flags, int fmt, d_thread_t * p)
149 GDT_DPRINTF(GDT_D_DEBUG, ("iir_open()\n"));
153 struct gdt_softc *gdt;
155 minor_no = minor(dev);
156 gdt = gdt_minor2softc(minor_no);
165 iir_close(struct cdev *dev, int flags, int fmt, d_thread_t * p)
167 GDT_DPRINTF(GDT_D_DEBUG, ("iir_close()\n"));
171 struct gdt_softc *gdt;
173 minor_no = minor(dev);
174 gdt = gdt_minor2softc(minor_no);
183 iir_write(struct cdev *dev, struct uio * uio, int ioflag)
185 GDT_DPRINTF(GDT_D_DEBUG, ("iir_write()\n"));
189 struct gdt_softc *gdt;
191 minor_no = minor(dev);
192 gdt = gdt_minor2softc(minor_no);
201 iir_read(struct cdev *dev, struct uio * uio, int ioflag)
203 GDT_DPRINTF(GDT_D_DEBUG, ("iir_read()\n"));
207 struct gdt_softc *gdt;
209 minor_no = minor(dev);
210 gdt = gdt_minor2softc(minor_no);
219 * This is the control syscall interface.
220 * It should be binary compatible with UnixWare,
221 * if not totally syntatically so.
225 iir_ioctl(struct cdev *dev, u_long cmd, caddr_t cmdarg, int flags, d_thread_t * p)
227 GDT_DPRINTF(GDT_D_DEBUG, ("iir_ioctl() cmd 0x%lx\n",cmd));
231 struct gdt_softc *gdt;
233 minor_no = minor(dev);
234 gdt = gdt_minor2softc(minor_no);
238 ++gdt_stat.io_count_act;
239 if (gdt_stat.io_count_act > gdt_stat.io_count_max)
240 gdt_stat.io_count_max = gdt_stat.io_count_act;
243 case GDT_IOCTL_GENERAL:
246 struct gdt_softc *gdt;
249 ucmd = (gdt_ucmd_t *)cmdarg;
250 gdt = gdt_minor2softc(ucmd->io_node);
254 TAILQ_INSERT_TAIL(&gdt->sc_ucmd_queue, ucmd, links);
255 ucmd->complete_flag = FALSE;
258 if (!ucmd->complete_flag)
259 (void) tsleep((void *)ucmd, PCATCH | PRIBIO, "iirucw", 0);
263 case GDT_IOCTL_DRVERS:
264 case GDT_IOCTL_DRVERS_OLD:
266 (IIR_DRIVER_VERSION << 8) | IIR_DRIVER_SUBVERSION;
269 case GDT_IOCTL_CTRTYPE:
270 case GDT_IOCTL_CTRTYPE_OLD:
273 struct gdt_softc *gdt;
275 p = (gdt_ctrt_t *)cmdarg;
276 gdt = gdt_minor2softc(p->io_node);
279 /* only RP controllers */
280 p->ext_type = 0x6000 | gdt->sc_device;
281 if (gdt->sc_vendor == INTEL_VENDOR_ID) {
282 p->oem_id = OEM_ID_INTEL;
284 /* new -> subdevice into ext_type */
285 if (gdt->sc_device >= 0x600)
286 p->ext_type = 0x6000 | gdt->sc_subdevice;
288 p->oem_id = OEM_ID_ICP;
290 /* new -> subdevice into ext_type */
291 if (gdt->sc_device >= 0x300)
292 p->ext_type = 0x6000 | gdt->sc_subdevice;
294 p->info = (gdt->sc_bus << 8) | (gdt->sc_slot << 3);
295 p->device_id = gdt->sc_device;
296 p->sub_device_id = gdt->sc_subdevice;
300 case GDT_IOCTL_OSVERS:
304 p = (gdt_osv_t *)cmdarg;
306 p->version = osrelease[0] - '0';
307 if (osrelease[1] == '.')
308 p->subversion = osrelease[2] - '0';
311 if (osrelease[3] == '.')
312 p->revision = osrelease[4] - '0';
315 strcpy(p->name, ostype);
319 case GDT_IOCTL_CTRCNT:
320 *(int *)cmdarg = gdt_cnt;
323 case GDT_IOCTL_EVENT:
328 p = (gdt_event_t *)cmdarg;
329 if (p->erase == 0xff) {
330 if (p->dvr.event_source == GDT_ES_TEST)
331 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.test);
332 else if (p->dvr.event_source == GDT_ES_DRIVER)
333 p->dvr.event_data.size= sizeof(p->dvr.event_data.eu.driver);
334 else if (p->dvr.event_source == GDT_ES_SYNC)
335 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.sync);
337 p->dvr.event_data.size = sizeof(p->dvr.event_data.eu.async);
339 gdt_store_event(p->dvr.event_source, p->dvr.event_idx,
342 } else if (p->erase == 0xfe) {
346 } else if (p->erase == 0) {
347 p->handle = gdt_read_event(p->handle, &p->dvr);
349 gdt_readapp_event((u_int8_t)p->erase, &p->dvr);
354 case GDT_IOCTL_STATIST:
358 p = (gdt_statist_t *)cmdarg;
359 bcopy(&gdt_stat, p, sizeof(gdt_statist_t));
367 --gdt_stat.io_count_act;
373 iir_drvinit(void *unused)
375 GDT_DPRINTF(GDT_D_DEBUG, ("iir_drvinit()\n"));
377 if (!iir_devsw_installed) {
378 cdevsw_add(&iir_cdevsw);
379 iir_devsw_installed = 1;
383 SYSINIT(iir_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, iir_drvinit, NULL)