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.5 2004/10/06 02:12:31 y0netan1 Exp $
31 #include <sys/devicestat.h>
32 #include <dev/raid/ips/ips.h>
33 #include <dev/raid/ips/ips_disk.h>
36 static int ipsd_probe(device_t dev);
37 static int ipsd_attach(device_t dev);
38 static int ipsd_detach(device_t dev);
40 static disk_open_t ipsd_open;
41 static disk_close_t ipsd_close;
42 static disk_strategy_t ipsd_strategy;
44 static struct cdevsw ipsd_cdevsw = {
46 .d_maj = IPSD_CDEV_MAJOR,
50 .old_open = ipsd_open,
51 .old_close = ipsd_close,
52 .old_strategy = ipsd_strategy,
54 .old_write = physwrite,
57 static device_method_t ipsd_methods[] = {
58 DEVMETHOD(device_probe, ipsd_probe),
59 DEVMETHOD(device_attach, ipsd_attach),
60 DEVMETHOD(device_detach, ipsd_detach),
65 static driver_t ipsd_driver = {
68 sizeof(ipsdisk_softc_t)
71 static devclass_t ipsd_devclass;
72 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
75 * handle opening of disk device. It must set up all information about
76 * the geometry and size of the disk
79 ipsd_open(dev_t dev, int oflags, int devtype, d_thread_t *td)
81 ipsdisk_softc_t *dsc = dev->si_drv1;
85 dsc->state |= IPS_DEV_OPEN;
86 DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
91 ipsd_close(dev_t dev, int oflags, int devtype, d_thread_t *td)
93 ipsdisk_softc_t *dsc = dev->si_drv1;
95 dsc->state &= ~IPS_DEV_OPEN;
96 DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
100 /* ipsd_finish is called to clean up and return a completed IO request */
102 ipsd_finish(struct bio *iobuf)
104 ipsdisk_softc_t *dsc;
106 dsc = iobuf->bio_disk->d_drv1;
107 if (iobuf->bio_flags & BIO_ERROR) {
108 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
110 iobuf->bio_resid = 0;
111 devstat_end_transaction_buf(&dsc->stats, iobuf);
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 devstat_start_transaction(&dsc->stats);
125 ips_start_io_request(dsc->sc, iobuf);
129 ipsd_probe(device_t dev)
131 DEVICE_PRINTF(2, dev, "in probe\n");
132 device_set_desc(dev, "Logical Drive");
137 ipsd_attach(device_t dev)
140 ipsdisk_softc_t *dsc;
141 struct disklabel *label;
143 u_int nheads, nsectors;
145 DEVICE_PRINTF(2, dev, "in attach\n");
146 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
147 bzero(dsc, sizeof(ipsdisk_softc_t));
148 adapter = device_get_parent(dev);
150 dsc->sc = device_get_softc(adapter);
151 dsc->unit = device_get_unit(dev);
152 dsc->disk_number = (uintptr_t) device_get_ivars(dev);
153 totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
154 if ((totalsectors > 0x400000) &&
155 ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
156 nheads = IPS_NORM_HEADS;
157 nsectors = IPS_NORM_SECTORS;
159 nheads = IPS_COMP_HEADS;
160 nsectors = IPS_COMP_SECTORS;
162 devstat_add_entry(&dsc->stats, "ipsd", dsc->unit, DEV_BSIZE,
163 DEVSTAT_NO_ORDERED_TAGS,
164 DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_SCSI,
165 DEVSTAT_PRIORITY_DISK);
166 dsc->ipsd_dev_t = disk_create(dsc->unit, &dsc->ipsd_disk, 0,
168 dsc->ipsd_dev_t->si_drv1 = dsc;
169 dsc->ipsd_dev_t->si_iosize_max = IPS_MAX_IO_SIZE;
170 label = &dsc->ipsd_disk.d_label;
171 bzero(label, sizeof(*label));
172 label->d_ntracks = nheads;
173 label->d_nsectors = nsectors;
174 label->d_type = DTYPE_ESDI;
175 label->d_secsize = IPS_BLKSIZE;
176 label->d_ncylinders = totalsectors / nheads / nsectors;
177 label->d_secpercyl = nsectors / nheads;
178 label->d_secperunit = totalsectors;
179 device_printf(dev, "Logical Drive (%dMB)\n",
180 dsc->sc->drives[dsc->disk_number].sector_count >> 11);
185 ipsd_detach(device_t dev)
187 ipsdisk_softc_t *dsc;
189 DEVICE_PRINTF(2, dev, "in detach\n");
190 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
191 if (dsc->state & IPS_DEV_OPEN)
193 devstat_remove_entry(&dsc->stats);
194 disk_destroy(&dsc->ipsd_disk);