2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
6 * Copyright 1994-2009 The FreeBSD Project.
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 FREEBSD PROJECT``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY,OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * The views and conclusions contained in the software and documentation
28 * are those of the authors and should not be interpreted as representing
29 * official policies,either expressed or implied, of the FreeBSD Project.
31 * $FreeBSD: src/sys/dev/mfi/mfi_pddisk.c,v 1.2.2.6 2007/08/24 17:29:18 jhb Exp $
32 * FreeBSD projects/head_mfi/ r232888
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/malloc.h>
53 #include <machine/md_var.h>
56 #include <dev/raid/mfi/mfireg.h>
57 #include <dev/raid/mfi/mfi_ioctl.h>
58 #include <dev/raid/mfi/mfivar.h>
60 static int mfi_syspd_probe(device_t dev);
61 static int mfi_syspd_attach(device_t dev);
62 static int mfi_syspd_detach(device_t dev);
64 static d_open_t mfi_syspd_open;
65 static d_close_t mfi_syspd_close;
66 static d_strategy_t mfi_syspd_strategy;
67 static d_dump_t mfi_syspd_dump;
69 static struct dev_ops mfi_syspd_ops = {
70 { "mfisyspd", 0, D_DISK | D_MPSAFE },
71 .d_open = mfi_syspd_open,
72 .d_close = mfi_syspd_close,
73 .d_strategy = mfi_syspd_strategy,
74 .d_dump = mfi_syspd_dump,
77 static devclass_t mfi_syspd_devclass;
79 static device_method_t mfi_syspd_methods[] = {
80 DEVMETHOD(device_probe, mfi_syspd_probe),
81 DEVMETHOD(device_attach, mfi_syspd_attach),
82 DEVMETHOD(device_detach, mfi_syspd_detach),
86 static driver_t mfi_syspd_driver = {
89 sizeof(struct mfi_system_pd)
92 DRIVER_MODULE(mfisyspd, mfi, mfi_syspd_driver, mfi_syspd_devclass, NULL, NULL);
95 mfi_syspd_probe(device_t dev)
102 mfi_syspd_attach(device_t dev)
104 struct mfi_system_pd *sc;
105 struct mfi_pd_info *pd_info;
106 struct disk_info info;
110 sc = device_get_softc(dev);
111 pd_info = device_get_ivars(dev);
114 sc->pd_id = pd_info->ref.v.device_id;
115 sc->pd_unit = device_get_unit(dev);
116 sc->pd_info = pd_info;
117 sc->pd_controller = device_get_softc(device_get_parent(dev));
118 sc->pd_flags = MFI_DISK_FLAGS_SYSPD;
120 sectors = pd_info->raw_size;
121 secsize = MFI_SECTOR_LEN;
122 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
123 TAILQ_INSERT_TAIL(&sc->pd_controller->mfi_syspd_tqh, sc, pd_link);
124 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
125 device_printf(dev, "%juMB (%ju sectors) SYSPD volume\n",
126 sectors / (1024 * 1024 / secsize), sectors);
128 devstat_add_entry(&sc->pd_devstat, "mfisyspd", device_get_unit(dev),
129 MFI_SECTOR_LEN, DEVSTAT_NO_ORDERED_TAGS,
130 DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER,
131 DEVSTAT_PRIORITY_ARRAY);
133 sc->pd_dev_t = disk_create(sc->pd_unit, &sc->pd_disk, &mfi_syspd_ops);
134 sc->pd_dev_t->si_drv1 = sc;
135 sc->pd_dev_t->si_iosize_max = sc->pd_controller->mfi_max_io *
138 bzero(&info, sizeof(info));
139 info.d_media_blksize = secsize; /* mandatory */
140 info.d_media_blocks = sectors;
142 if (info.d_media_blocks >= (1 * 1024 * 1024)) {
144 info.d_secpertrack = 63;
147 info.d_secpertrack = 32;
150 disk_setdiskinfo(&sc->pd_disk, &info);
156 mfi_syspd_detach(device_t dev)
158 struct mfi_system_pd *sc;
160 sc = device_get_softc(dev);
161 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
162 if ((sc->pd_flags & MFI_DISK_FLAGS_OPEN) &&
163 (sc->pd_controller->mfi_keep_deleted_volumes ||
164 sc->pd_controller->mfi_detaching)) {
165 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
168 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
170 disk_destroy(&sc->pd_disk);
171 devstat_remove_entry(&sc->pd_devstat);
172 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
173 TAILQ_REMOVE(&sc->pd_controller->mfi_syspd_tqh, sc, pd_link);
174 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
175 kfree(sc->pd_info, M_MFIBUF);
180 mfi_syspd_open(struct dev_open_args *ap)
182 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
185 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
186 if (sc->pd_flags & MFI_DISK_FLAGS_DISABLED)
189 sc->pd_flags |= MFI_DISK_FLAGS_OPEN;
192 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
197 mfi_syspd_close(struct dev_close_args *ap)
199 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
201 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
202 sc->pd_flags &= ~MFI_DISK_FLAGS_OPEN;
203 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
209 mfi_syspd_disable(struct mfi_system_pd *sc)
212 mfi_lockassert(&sc->pd_controller->mfi_io_lock);
213 if (sc->pd_flags & MFI_DISK_FLAGS_OPEN) {
214 if (sc->pd_controller->mfi_delete_busy_volumes)
216 device_printf(sc->pd_dev,
217 "Unable to delete busy syspd device\n");
220 sc->pd_flags |= MFI_DISK_FLAGS_DISABLED;
225 mfi_syspd_enable(struct mfi_system_pd *sc)
228 mfi_lockassert(&sc->pd_controller->mfi_io_lock);
229 sc->pd_flags &= ~MFI_DISK_FLAGS_DISABLED;
233 mfi_syspd_strategy(struct dev_strategy_args *ap)
235 struct bio *bio = ap->a_bio;
236 struct buf *bp = bio->bio_buf;
237 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
238 struct mfi_softc *controller;
241 bp->b_error = EINVAL;
242 bp->b_flags |= B_ERROR;
243 bp->b_resid = bp->b_bcount;
247 controller = sc->pd_controller;
249 if (controller->hw_crit_error) {
254 if (controller->issuepend_done == 0) {
262 * If it's a null transfer, do nothing. FreeBSD's original driver
263 * doesn't have this, but that caused hard error messages (even
264 * though everything else continued to work fine). Interestingly,
265 * only when HAMMER was used.
267 * Several others of our RAID drivers have this check, such as
268 * aac(4) and ida(4), so we insert it here, too.
270 * The cause of null transfers is yet unknown.
272 if (bp->b_bcount == 0) {
273 bp->b_resid = bp->b_bcount;
278 bio->bio_driver_info = sc;
279 lockmgr(&controller->mfi_io_lock, LK_EXCLUSIVE);
280 mfi_enqueue_bio(controller, bio);
281 devstat_start_transaction(&sc->pd_devstat);
282 mfi_startio(controller);
283 lockmgr(&controller->mfi_io_lock, LK_RELEASE);
288 mfi_syspd_dump(struct dev_dump_args *ap)
290 cdev_t dev = ap->a_head.a_dev;
291 off_t offset = ap->a_offset;
292 void *virt = ap->a_virtual;
293 size_t len = ap->a_length;
294 struct mfi_system_pd *sc;
295 struct mfi_softc *parent_sc;
299 parent_sc = sc->pd_controller;
302 if ((error = mfi_dump_syspd_blocks(parent_sc,
303 sc->pd_id, offset / MFI_SECTOR_LEN, virt, len)) != 0)
306 /* mfi_sync_cache(parent_sc, sc->ld_id); */