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 Exp $
28 * $DragonFly: src/sys/dev/raid/ips/ips_disk.c,v 1.4 2004/09/06 16:30:10 joerg Exp $
31 #include <dev/raid/ips/ips.h>
32 #include <dev/raid/ips/ips_disk.h>
35 static int ipsd_probe(device_t dev);
36 static int ipsd_attach(device_t dev);
37 static int ipsd_detach(device_t dev);
39 static disk_open_t ipsd_open;
40 static disk_close_t ipsd_close;
41 static disk_strategy_t ipsd_strategy;
43 static struct cdevsw ipsd_cdevsw = {
45 .d_maj = IPSD_CDEV_MAJOR,
49 .old_open = ipsd_open,
50 .old_close = ipsd_close,
51 .old_strategy = ipsd_strategy,
53 .old_write = physwrite,
56 static device_method_t ipsd_methods[] = {
57 DEVMETHOD(device_probe, ipsd_probe),
58 DEVMETHOD(device_attach, ipsd_attach),
59 DEVMETHOD(device_detach, ipsd_detach),
64 static driver_t ipsd_driver = {
67 sizeof(ipsdisk_softc_t)
70 static devclass_t ipsd_devclass;
71 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
74 * handle opening of disk device. It must set up all information about
75 * the geometry and size of the disk
78 ipsd_open(dev_t dev, int oflags, int devtype, d_thread_t *td)
80 ipsdisk_softc_t *dsc = dev->si_drv1;
84 dsc->state |= IPS_DEV_OPEN;
85 DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
90 ipsd_close(dev_t dev, int oflags, int devtype, d_thread_t *td)
92 ipsdisk_softc_t *dsc = dev->si_drv1;
94 dsc->state &= ~IPS_DEV_OPEN;
95 DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
99 /* ipsd_finish is called to clean up and return a completed IO request */
101 ipsd_finish(struct bio *iobuf)
103 if (iobuf->bio_flags & BIO_ERROR) {
104 ipsdisk_softc_t *dsc;
105 dsc = iobuf->bio_disk->d_drv1;
106 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
108 iobuf->bio_resid = 0;
115 ipsd_strategy(struct bio *iobuf)
117 ipsdisk_softc_t *dsc;
119 dsc = iobuf->bio_disk->d_drv1;
120 DEVICE_PRINTF(8, dsc->dev, "in strategy\n");
121 iobuf->bio_driver1 = (void *)(uintptr_t)dsc->sc->drives[dsc->disk_number].drivenum;
122 ips_start_io_request(dsc->sc, iobuf);
126 ipsd_probe(device_t dev)
128 DEVICE_PRINTF(2, dev, "in probe\n");
129 device_set_desc(dev, "Logical Drive");
134 ipsd_attach(device_t dev)
137 ipsdisk_softc_t *dsc;
138 struct disklabel *label;
140 u_int nheads, nsectors;
142 DEVICE_PRINTF(2, dev, "in attach\n");
143 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
144 bzero(dsc, sizeof(ipsdisk_softc_t));
145 adapter = device_get_parent(dev);
147 dsc->sc = device_get_softc(adapter);
148 dsc->unit = device_get_unit(dev);
149 dsc->disk_number = (uintptr_t) device_get_ivars(dev);
150 totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
151 if ((totalsectors > 0x400000) &&
152 ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
153 nheads = IPS_NORM_HEADS;
154 nsectors = IPS_NORM_SECTORS;
156 nheads = IPS_COMP_HEADS;
157 nsectors = IPS_COMP_SECTORS;
159 dsc->ipsd_dev_t = disk_create(dsc->unit, &dsc->ipsd_disk, 0,
161 dsc->ipsd_dev_t->si_drv1 = dsc;
162 dsc->ipsd_dev_t->si_iosize_max = IPS_MAX_IO_SIZE;
163 label = &dsc->ipsd_disk.d_label;
164 bzero(label, sizeof(*label));
165 label->d_ntracks = nheads;
166 label->d_nsectors = nsectors;
167 label->d_type = DTYPE_ESDI;
168 label->d_secsize = IPS_BLKSIZE;
169 label->d_ncylinders = totalsectors / nheads / nsectors;
170 label->d_secpercyl = nsectors / nheads;
171 label->d_secperunit = totalsectors;
172 device_printf(dev, "Logical Drive (%dMB)\n",
173 dsc->sc->drives[dsc->disk_number].sector_count >> 11);
178 ipsd_detach(device_t dev)
180 ipsdisk_softc_t *dsc;
182 DEVICE_PRINTF(2, dev, "in detach\n");
183 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
184 if (dsc->state & IPS_DEV_OPEN)
186 disk_destroy(&dsc->ipsd_disk);