2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999,2000 Jonathan Lemon
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 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Disk driver for Compaq SMART RAID adapters.
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
45 #include <machine/bus.h>
50 #include <machine/md_var.h>
52 #include <geom/geom_disk.h>
54 #include <dev/ida/idareg.h>
55 #include <dev/ida/idavar.h>
58 static int idad_probe(device_t dev);
59 static int idad_attach(device_t dev);
60 static int idad_detach(device_t dev);
62 static d_strategy_t idad_strategy;
63 static dumper_t idad_dump;
65 static devclass_t idad_devclass;
67 static device_method_t idad_methods[] = {
68 DEVMETHOD(device_probe, idad_probe),
69 DEVMETHOD(device_attach, idad_attach),
70 DEVMETHOD(device_detach, idad_detach),
74 static driver_t idad_driver = {
77 sizeof(struct idad_softc)
80 DRIVER_MODULE(idad, ida, idad_driver, idad_devclass, 0, 0);
83 * Read/write routine for a buffer. Finds the proper unit, range checks
84 * arguments, and schedules the transfer. Does not wait for the transfer
85 * to complete. Multi-page transfers are supported. All I/O requests must
86 * be a multiple of a sector in length.
89 idad_strategy(struct bio *bp)
91 struct idad_softc *drv;
93 drv = bp->bio_disk->d_drv1;
95 bp->bio_error = EINVAL;
100 * software write protect check
102 if (drv->flags & DRV_WRITEPROT && (bp->bio_cmd == BIO_WRITE)) {
103 bp->bio_error = EROFS;
107 bp->bio_driver1 = drv;
108 ida_submit_buf(drv->controller, bp);
112 bp->bio_flags |= BIO_ERROR;
115 * Correctly set the buf to indicate a completed transfer
117 bp->bio_resid = bp->bio_bcount;
123 idad_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
126 struct idad_softc *drv;
135 drv->controller->flags &= ~IDA_INTERRUPTS;
138 error = ida_command(drv->controller, CMD_WRITE, virtual,
139 length, drv->drive, offset / DEV_BSIZE, DMA_DATA_OUT);
141 drv->controller->flags |= IDA_INTERRUPTS;
146 idad_intr(struct bio *bp)
148 struct idad_softc *drv;
150 drv = bp->bio_disk->d_drv1;
152 if (bp->bio_flags & BIO_ERROR)
161 idad_probe(device_t dev)
164 device_set_desc(dev, "Compaq Logical Drive");
169 idad_attach(device_t dev)
171 struct ida_drive_info dinfo;
172 struct idad_softc *drv;
176 drv = (struct idad_softc *)device_get_softc(dev);
177 parent = device_get_parent(dev);
179 drv->controller = (struct ida_softc *)device_get_softc(parent);
180 drv->unit = device_get_unit(dev);
181 drv->drive = (intptr_t)device_get_ivars(dev);
183 mtx_lock(&drv->controller->lock);
184 error = ida_command(drv->controller, CMD_GET_LOG_DRV_INFO,
185 &dinfo, sizeof(dinfo), drv->drive, 0, DMA_DATA_IN);
186 mtx_unlock(&drv->controller->lock);
188 device_printf(dev, "CMD_GET_LOG_DRV_INFO failed\n");
192 drv->cylinders = dinfo.dp.ncylinders;
193 drv->heads = dinfo.dp.nheads;
194 drv->sectors = dinfo.dp.nsectors;
195 drv->secsize = dinfo.secsize == 0 ? 512 : dinfo.secsize;
196 drv->secperunit = dinfo.secperunit;
199 * other initialization
201 device_printf(dev, "%uMB (%u sectors), blocksize=%d\n",
202 drv->secperunit / ((1024 * 1024) / drv->secsize),
203 drv->secperunit, drv->secsize);
205 drv->disk = disk_alloc();
206 drv->disk->d_strategy = idad_strategy;
207 drv->disk->d_name = "idad";
208 drv->disk->d_dump = idad_dump;
209 drv->disk->d_sectorsize = drv->secsize;
210 drv->disk->d_mediasize = (off_t)drv->secperunit * drv->secsize;
211 drv->disk->d_fwsectors = drv->sectors;
212 drv->disk->d_fwheads = drv->heads;
213 drv->disk->d_drv1 = drv;
214 drv->disk->d_maxsize = DFLTPHYS; /* XXX guess? */
215 drv->disk->d_unit = drv->unit;
216 disk_create(drv->disk, DISK_VERSION);
222 idad_detach(device_t dev)
224 struct idad_softc *drv;
226 drv = (struct idad_softc *)device_get_softc(dev);
227 disk_destroy(drv->disk);