2 * Copyright (c) 1999 Jonathan Lemon
3 * Copyright (c) 1999, 2000 Michael Smith
4 * Copyright (c) 2000 BSDi
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
29 * Copyright (c) 2002 Eric Moore
30 * Copyright (c) 2002 LSI Logic Corporation
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. The party using or redistributing the source code and binary forms
42 * agrees to the disclaimer below and the terms and conditions set forth
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 #include <sys/cdefs.h>
59 __FBSDID("$FreeBSD$");
62 * Disk driver for AMI MegaRaid controllers
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/module.h>
74 #include <machine/bus.h>
77 #include <dev/amr/amrio.h>
78 #include <dev/amr/amrreg.h>
79 #include <dev/amr/amrvar.h>
80 #include <dev/amr/amr_tables.h>
83 static int amrd_probe(device_t dev);
84 static int amrd_attach(device_t dev);
85 static int amrd_detach(device_t dev);
87 static disk_open_t amrd_open;
88 static disk_strategy_t amrd_strategy;
90 static devclass_t amrd_devclass;
92 int amr_disks_registered = 0;
95 static device_method_t amrd_methods[] = {
96 DEVMETHOD(device_probe, amrd_probe),
97 DEVMETHOD(device_attach, amrd_attach),
98 DEVMETHOD(device_detach, amrd_detach),
102 static driver_t amrd_driver = {
105 sizeof(struct amrd_softc)
108 DRIVER_MODULE(amrd, amr, amrd_driver, amrd_devclass, 0, 0);
111 amrd_open(struct disk *dp)
113 struct amrd_softc *sc = (struct amrd_softc *)dp->d_drv1;
120 /* controller not active? */
121 if (sc->amrd_controller->amr_state & AMR_STATE_SHUTDOWN)
126 /********************************************************************************
127 * System crashdump support
131 amrd_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
134 struct amrd_softc *amrd_sc;
135 struct amr_softc *amr_sc;
140 amrd_sc = (struct amrd_softc *)dp->d_drv1;
143 amr_sc = (struct amr_softc *)amrd_sc->amrd_controller;
146 int driveno = amrd_sc->amrd_drive - amr_sc->amr_drive;
147 if ((error = amr_dump_blocks(amr_sc,driveno,offset / AMR_BLKSIZE ,(void *)virtual,(int) length / AMR_BLKSIZE )) != 0)
155 * Read/write routine for a buffer. Finds the proper unit, range checks
156 * arguments, and schedules the transfer. Does not wait for the transfer
157 * to complete. Multi-page transfers are supported. All I/O requests must
158 * be a multiple of a sector in length.
161 amrd_strategy(struct bio *bio)
163 struct amrd_softc *sc = (struct amrd_softc *)bio->bio_disk->d_drv1;
167 bio->bio_error = EINVAL;
171 amr_submit_bio(sc->amrd_controller, bio);
175 bio->bio_flags |= BIO_ERROR;
178 * Correctly set the buf to indicate a completed transfer
180 bio->bio_resid = bio->bio_bcount;
186 amrd_intr(void *data)
188 struct bio *bio = (struct bio *)data;
192 if (bio->bio_flags & BIO_ERROR) {
193 bio->bio_error = EIO;
194 debug(1, "i/o error\n");
203 amrd_probe(device_t dev)
208 device_set_desc(dev, "LSILogic MegaRAID logical drive");
213 amrd_attach(device_t dev)
215 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev);
220 parent = device_get_parent(dev);
221 sc->amrd_controller = (struct amr_softc *)device_get_softc(parent);
222 sc->amrd_unit = device_get_unit(dev);
223 sc->amrd_drive = device_get_ivars(dev);
226 device_printf(dev, "%uMB (%u sectors) RAID %d (%s)\n",
227 sc->amrd_drive->al_size / ((1024 * 1024) / AMR_BLKSIZE),
228 sc->amrd_drive->al_size, sc->amrd_drive->al_properties & AMR_DRV_RAID_MASK,
229 amr_describe_code(amr_table_drvstate, AMR_DRV_CURSTATE(sc->amrd_drive->al_state)));
231 sc->amrd_disk = disk_alloc();
232 sc->amrd_disk->d_drv1 = sc;
233 sc->amrd_disk->d_maxsize = (AMR_NSEG - 1) * PAGE_SIZE;
234 sc->amrd_disk->d_open = amrd_open;
235 sc->amrd_disk->d_strategy = amrd_strategy;
236 sc->amrd_disk->d_name = "amrd";
237 sc->amrd_disk->d_dump = (dumper_t *)amrd_dump;
238 sc->amrd_disk->d_unit = sc->amrd_unit;
239 sc->amrd_disk->d_flags = DISKFLAG_CANFLUSHCACHE;
240 sc->amrd_disk->d_sectorsize = AMR_BLKSIZE;
241 sc->amrd_disk->d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE;
242 sc->amrd_disk->d_fwsectors = sc->amrd_drive->al_sectors;
243 sc->amrd_disk->d_fwheads = sc->amrd_drive->al_heads;
244 disk_create(sc->amrd_disk, DISK_VERSION);
250 amrd_detach(device_t dev)
252 struct amrd_softc *sc = (struct amrd_softc *)device_get_softc(dev);
256 if (sc->amrd_disk->d_flags & DISKFLAG_OPEN)
260 if (--amr_disks_registered == 0)
261 cdevsw_remove(&amrddisk_cdevsw);
263 disk_destroy(sc->amrd_disk);