mfi(4): Remove some debug messages.
[dragonfly.git] / sys / dev / raid / mfi / mfi_syspd.c
CommitLineData
17566092
SW
1/*-
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
4 * are met:
5 *
6 * Copyright 1994-2009 The FreeBSD Project.
7 * All rights reserved.
8 *
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.
14 *
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.
26 *
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.
30 *
31 * $FreeBSD: src/sys/dev/mfi/mfi_pddisk.c,v 1.2.2.6 2007/08/24 17:29:18 jhb Exp $
32 */
33
34#include "opt_mfi.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/malloc.h>
41#include <sys/uio.h>
42
43#include <sys/bio.h>
44#include <sys/buf2.h>
45#include <sys/bus.h>
46#include <sys/conf.h>
47#include <sys/disk.h>
48
49#include <vm/vm.h>
50#include <vm/pmap.h>
51
52#include <machine/md_var.h>
53#include <sys/rman.h>
54
55#include <dev/raid/mfi/mfireg.h>
56#include <dev/raid/mfi/mfi_ioctl.h>
57#include <dev/raid/mfi/mfivar.h>
58
59static int mfi_syspd_probe(device_t dev);
60static int mfi_syspd_attach(device_t dev);
61static int mfi_syspd_detach(device_t dev);
62
63static d_open_t mfi_syspd_open;
64static d_close_t mfi_syspd_close;
65static d_strategy_t mfi_syspd_strategy;
66static d_dump_t mfi_syspd_dump;
67
68static struct dev_ops mfi_syspd_ops = {
69 { "mfisyspd", 0, D_DISK },
70 .d_open = mfi_syspd_open,
71 .d_close = mfi_syspd_close,
72 .d_strategy = mfi_syspd_strategy,
73 .d_dump = mfi_syspd_dump,
74};
75
76static devclass_t mfi_syspd_devclass;
77
78static device_method_t mfi_syspd_methods[] = {
79 DEVMETHOD(device_probe, mfi_syspd_probe),
80 DEVMETHOD(device_attach, mfi_syspd_attach),
81 DEVMETHOD(device_detach, mfi_syspd_detach),
82 { 0, 0 }
83};
84
85static driver_t mfi_syspd_driver = {
86 "mfisyspd",
87 mfi_syspd_methods,
88 sizeof(struct mfi_system_pd)
89};
90
91DRIVER_MODULE(mfisyspd, mfi, mfi_syspd_driver, mfi_syspd_devclass, 0, 0);
92
93static int
94mfi_syspd_probe(device_t dev)
95{
96
97 return (0);
98}
99
100static int
101mfi_syspd_attach(device_t dev)
102{
103 struct mfi_system_pd *sc;
104 struct mfi_pd_info *pd_info;
105 struct disk_info info;
106 uint64_t sectors;
107 uint32_t secsize;
108
109 sc = device_get_softc(dev);
110 pd_info = device_get_ivars(dev);
111
112 sc->pd_dev = dev;
113 sc->pd_id = pd_info->ref.v.device_id;
114 sc->pd_unit = device_get_unit(dev);
115 sc->pd_info = pd_info;
116 sc->pd_controller = device_get_softc(device_get_parent(dev));
117 sc->pd_flags = MFI_DISK_FLAGS_SYSPD;
118
119 sectors = pd_info->raw_size;
120 secsize = MFI_SECTOR_LEN;
121 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
122 TAILQ_INSERT_TAIL(&sc->pd_controller->mfi_syspd_tqh, sc, pd_link);
123 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
124 device_printf(dev, "%juMB (%ju sectors) SYSPD volume\n",
125 sectors / (1024 * 1024 / secsize), sectors);
126
127 devstat_add_entry(&sc->pd_devstat, "mfisyspd", device_get_unit(dev),
128 MFI_SECTOR_LEN, DEVSTAT_NO_ORDERED_TAGS,
129 DEVSTAT_TYPE_STORARRAY | DEVSTAT_TYPE_IF_OTHER,
130 DEVSTAT_PRIORITY_ARRAY);
131
9049decf
SW
132 sc->pd_dev_t = disk_create(sc->pd_unit, &sc->pd_disk, &mfi_syspd_ops);
133 sc->pd_dev_t->si_drv1 = sc;
134 sc->pd_dev_t->si_iosize_max = sc->pd_controller->mfi_max_io *
17566092
SW
135 secsize;
136
137 bzero(&info, sizeof(info));
138 info.d_media_blksize = secsize; /* mandatory */
139 info.d_media_blocks = sectors;
140
141 if (info.d_media_blocks >= (1 * 1024 * 1024)) {
142 info.d_nheads = 255;
143 info.d_secpertrack = 63;
144 } else {
145 info.d_nheads = 64;
146 info.d_secpertrack = 32;
147 }
148
149 disk_setdiskinfo(&sc->pd_disk, &info);
150
17566092
SW
151 return (0);
152}
153
154static int
155mfi_syspd_detach(device_t dev)
156{
157 struct mfi_system_pd *sc;
158
159 sc = device_get_softc(dev);
17566092
SW
160 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
161 if ((sc->pd_flags & MFI_DISK_FLAGS_OPEN) &&
162 (sc->pd_controller->mfi_keep_deleted_volumes ||
163 sc->pd_controller->mfi_detaching)) {
164 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
17566092
SW
165 return (EBUSY);
166 }
167 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
168
169 disk_destroy(&sc->pd_disk);
170 devstat_remove_entry(&sc->pd_devstat);
171 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
172 TAILQ_REMOVE(&sc->pd_controller->mfi_syspd_tqh, sc, pd_link);
173 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
174 kfree(sc->pd_info, M_MFIBUF);
175 return (0);
176}
177
178static int
179mfi_syspd_open(struct dev_open_args *ap)
180{
181 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
182 int error;
183
184 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
185 if (sc->pd_flags & MFI_DISK_FLAGS_DISABLED)
186 error = ENXIO;
187 else {
188 sc->pd_flags |= MFI_DISK_FLAGS_OPEN;
189 error = 0;
190 }
191 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
192 return (error);
193}
194
195static int
196mfi_syspd_close(struct dev_close_args *ap)
197{
198 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
199
200 lockmgr(&sc->pd_controller->mfi_io_lock, LK_EXCLUSIVE);
201 sc->pd_flags &= ~MFI_DISK_FLAGS_OPEN;
202 lockmgr(&sc->pd_controller->mfi_io_lock, LK_RELEASE);
203
204 return (0);
205}
206
207int
208mfi_syspd_disable(struct mfi_system_pd *sc)
209{
210
211 device_printf(sc->pd_dev,"syspd disable \n");
212 KKASSERT(lockstatus(&sc->pd_controller->mfi_io_lock, curthread) != 0);
213 if (sc->pd_flags & MFI_DISK_FLAGS_OPEN) {
214 if (sc->pd_controller->mfi_delete_busy_volumes)
215 return (0);
216 device_printf(sc->pd_dev, "Unable to delete busy syspd device\n");
217 return (EBUSY);
218 }
219 sc->pd_flags |= MFI_DISK_FLAGS_DISABLED;
220 return (0);
221}
222
223void
224mfi_syspd_enable(struct mfi_system_pd *sc)
225{
226
17566092
SW
227 KKASSERT(lockstatus(&sc->pd_controller->mfi_io_lock, curthread) != 0);
228 sc->pd_flags &= ~MFI_DISK_FLAGS_DISABLED;
229}
230
231static int
232mfi_syspd_strategy(struct dev_strategy_args *ap)
233{
234 struct bio *bio = ap->a_bio;
235 struct buf *bp = bio->bio_buf;
236 struct mfi_system_pd *sc = ap->a_head.a_dev->si_drv1;
237 struct mfi_softc *controller;
238
239 if (sc == NULL) {
240 bp->b_error = EINVAL;
241 bp->b_flags |= B_ERROR;
242 bp->b_resid = bp->b_bcount;
243 biodone(bio);
244 return (0);
245 }
246
247 /*
248 * XXX swildner
249 *
250 * If it's a null transfer, do nothing. FreeBSD's original driver
251 * doesn't have this, but that caused hard error messages (even
252 * though everything else continued to work fine). Interestingly,
253 * only when HAMMER was used.
254 *
255 * Several others of our RAID drivers have this check, such as
256 * aac(4) and ida(4), so we insert it here, too.
257 *
258 * The cause of null transfers is yet unknown.
259 */
260 if (bp->b_bcount == 0) {
261 bp->b_resid = bp->b_bcount;
262 biodone(bio);
263 return (0);
264 }
265
266 controller = sc->pd_controller;
267 bio->bio_driver_info = sc;
268 lockmgr(&controller->mfi_io_lock, LK_EXCLUSIVE);
269 mfi_enqueue_bio(controller, bio);
270 devstat_start_transaction(&sc->pd_devstat);
271 mfi_startio(controller);
272 lockmgr(&controller->mfi_io_lock, LK_RELEASE);
273 return (0);
274}
275
276#if 0
277void
278mfi_disk_complete(struct bio *bio)
279{
280 struct mfi_system_pd *sc = bio->bio_driver_info;
281 struct buf *bp = bio->bio_buf;
282
283 devstat_end_transaction_buf(&sc->pd_devstat, bp);
284 if (bio->b_flags & B_ERROR) {
285 if (bp->b_error == 0)
286 bp->b_error = EIO;
287 diskerr(bio, sc->pd_disk.d_cdev, "hard error", -1, 1);
288 kprintf("\n");
289 } else {
290 bp->b_resid = 0;
291 }
292 biodone(bio);
293}
294#endif
295
296static int
297mfi_syspd_dump(struct dev_dump_args *ap)
298{
299 cdev_t dev = ap->a_head.a_dev;
300 off_t offset = ap->a_offset;
301 void *virt = ap->a_virtual;
302 size_t len = ap->a_length;
303 struct mfi_system_pd *sc;
304 struct mfi_softc *parent_sc;
305 int error;
306
307 sc = dev->si_drv1;
308 parent_sc = sc->pd_controller;
309
310 if (len > 0) {
311 if ((error = mfi_dump_syspd_blocks(parent_sc, sc->pd_id, offset /
312 MFI_SECTOR_LEN, virt, len)) != 0)
313 return (error);
314 } else {
315 /* mfi_sync_cache(parent_sc, sc->ld_id); */
316 }
317 return (0);
318}