2 * Written by: David Jeffery
3 * Copyright (c) 2002 Adaptec Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/ips/ips_disk.c,v 1.4 2003/09/22 04:59:07 njl $
28 * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.3 2004/07/09 16:15:27 dillon Exp $
31 #include <sys/cdefs.h>
33 #include <dev/raid/ips/ips.h>
34 #include <dev/raid/ips/ips_disk.h>
37 static int ipsd_probe(device_t dev);
38 static int ipsd_attach(device_t dev);
39 static int ipsd_detach(device_t dev);
41 static disk_open_t ipsd_open;
42 static disk_close_t ipsd_close;
43 static disk_strategy_t ipsd_strategy;
45 static struct cdevsw ipsd_cdevsw = {
47 .d_maj = IPSD_CDEV_MAJOR,
51 .old_open = ipsd_open,
52 .old_close = ipsd_close,
53 .old_strategy = ipsd_strategy,
55 .old_write = physwrite,
58 static device_method_t ipsd_methods[] = {
59 DEVMETHOD(device_probe, ipsd_probe),
60 DEVMETHOD(device_attach, ipsd_attach),
61 DEVMETHOD(device_detach, ipsd_detach),
66 static driver_t ipsd_driver = {
69 sizeof(ipsdisk_softc_t)
72 static devclass_t ipsd_devclass;
73 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
76 * handle opening of disk device. It must set up all information about
77 * the geometry and size of the disk
80 ipsd_open(dev_t dev, int oflags, int devtype, d_thread_t *td)
82 ipsdisk_softc_t *dsc = dev->si_drv1;
86 dsc->state |= IPS_DEV_OPEN;
87 DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
92 ipsd_close(dev_t dev, int oflags, int devtype, d_thread_t *td)
94 ipsdisk_softc_t *dsc = dev->si_drv1;
96 dsc->state &= ~IPS_DEV_OPEN;
97 DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
101 /* ipsd_finish is called to clean up and return a completed IO request */
103 ipsd_finish(struct bio *iobuf)
105 if (iobuf->bio_flags & BIO_ERROR) {
106 ipsdisk_softc_t *dsc;
107 dsc = iobuf->bio_disk->d_drv1;
108 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
110 iobuf->bio_resid = 0;
117 ipsd_strategy(struct bio *iobuf)
119 ipsdisk_softc_t *dsc;
121 dsc = iobuf->bio_disk->d_drv1;
122 DEVICE_PRINTF(8, dsc->dev, "in strategy\n");
123 iobuf->bio_driver1 = (void *)(uintptr_t)dsc->sc->drives[dsc->disk_number].drivenum;
124 ips_start_io_request(dsc->sc, iobuf);
128 ipsd_probe(device_t dev)
130 DEVICE_PRINTF(2, dev, "in probe\n");
131 device_set_desc(dev, "Logical Drive");
136 ipsd_attach(device_t dev)
139 ipsdisk_softc_t *dsc;
140 struct disklabel *label;
142 u_int nheads, nsectors;
144 DEVICE_PRINTF(2, dev, "in attach\n");
145 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
146 bzero(dsc, sizeof(ipsdisk_softc_t));
147 adapter = device_get_parent(dev);
149 dsc->sc = device_get_softc(adapter);
150 dsc->unit = device_get_unit(dev);
151 dsc->disk_number = (uintptr_t) device_get_ivars(dev);
152 totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
153 if ((totalsectors > 0x400000) &&
154 ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
155 nheads = IPS_NORM_HEADS;
156 nsectors = IPS_NORM_SECTORS;
158 nheads = IPS_COMP_HEADS;
159 nsectors = IPS_COMP_SECTORS;
161 dsc->ipsd_dev_t = disk_create(dsc->unit, &dsc->ipsd_disk, 0,
163 dsc->ipsd_dev_t->si_drv1 = dsc;
164 dsc->ipsd_dev_t->si_iosize_max = IPS_MAX_IO_SIZE;
165 label = &dsc->ipsd_disk.d_label;
166 bzero(label, sizeof(*label));
167 label->d_ntracks = nheads;
168 label->d_nsectors = nsectors;
169 label->d_type = DTYPE_ESDI;
170 label->d_secsize = IPS_BLKSIZE;
171 label->d_ncylinders = totalsectors / nheads / nsectors;
172 label->d_secpercyl = nsectors / nheads;
173 label->d_secperunit = totalsectors;
174 device_printf(dev, "Logical Drive (%dMB)\n",
175 dsc->sc->drives[dsc->disk_number].sector_count >> 11);
180 ipsd_detach(device_t dev)
182 ipsdisk_softc_t *dsc;
184 DEVICE_PRINTF(2, dev, "in detach\n");
185 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
186 if (dsc->state & IPS_DEV_OPEN)
188 disk_destroy(&dsc->ipsd_disk);