2015-08-17 22:47:21 +03:00
|
|
|
/* $NetBSD: ld.c,v 1.90 2015/08/17 19:47:21 jakllsch Exp $ */
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran and Charles M. Hannum.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-11-08 22:20:33 +03:00
|
|
|
* Disk driver for use by RAID controllers.
|
2000-10-19 18:06:02 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 08:32:49 +03:00
|
|
|
#include <sys/cdefs.h>
|
2015-08-17 22:47:21 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.90 2015/08/17 19:47:21 jakllsch Exp $");
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/dkio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2000-12-03 16:03:30 +03:00
|
|
|
#include <sys/vnode.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#include <sys/syslog.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/mutex.h>
|
2015-04-13 19:33:23 +03:00
|
|
|
#include <sys/rndsource.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
#include <dev/ldvar.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-02-08 06:19:42 +03:00
|
|
|
#include <prop/proplib.h>
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
static void ldminphys(struct buf *bp);
|
2010-08-19 21:59:10 +04:00
|
|
|
static bool ld_suspend(device_t, const pmf_qual_t *);
|
2008-03-09 22:15:01 +03:00
|
|
|
static bool ld_shutdown(device_t, int);
|
2015-08-16 21:00:03 +03:00
|
|
|
static int ld_diskstart(device_t, struct buf *bp);
|
2015-05-02 11:00:08 +03:00
|
|
|
static void ld_iosize(device_t, int *);
|
|
|
|
static int ld_dumpblocks(device_t, void *, daddr_t, int);
|
|
|
|
static void ld_fake_geometry(struct ld_softc *);
|
2013-05-29 04:47:48 +04:00
|
|
|
static void ld_set_geometry(struct ld_softc *);
|
2009-05-07 13:11:42 +04:00
|
|
|
static void ld_config_interrupts (device_t);
|
2015-05-02 11:00:08 +03:00
|
|
|
static int ld_lastclose(device_t);
|
2015-08-17 22:47:21 +03:00
|
|
|
static int ld_discard(device_t, off_t, off_t);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
extern struct cfdriver ld_cd;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static dev_type_open(ldopen);
|
|
|
|
static dev_type_close(ldclose);
|
|
|
|
static dev_type_read(ldread);
|
|
|
|
static dev_type_write(ldwrite);
|
|
|
|
static dev_type_ioctl(ldioctl);
|
|
|
|
static dev_type_strategy(ldstrategy);
|
|
|
|
static dev_type_dump(lddump);
|
|
|
|
static dev_type_size(ldsize);
|
2015-08-17 22:47:21 +03:00
|
|
|
static dev_type_discard(lddiscard);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct bdevsw ld_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = ldopen,
|
|
|
|
.d_close = ldclose,
|
|
|
|
.d_strategy = ldstrategy,
|
|
|
|
.d_ioctl = ldioctl,
|
|
|
|
.d_dump = lddump,
|
|
|
|
.d_psize = ldsize,
|
2015-08-17 22:47:21 +03:00
|
|
|
.d_discard = lddiscard,
|
2015-08-16 21:00:03 +03:00
|
|
|
.d_flag = D_DISK | D_MPSAFE
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw ld_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = ldopen,
|
|
|
|
.d_close = ldclose,
|
|
|
|
.d_read = ldread,
|
|
|
|
.d_write = ldwrite,
|
|
|
|
.d_ioctl = ldioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2015-08-17 22:47:21 +03:00
|
|
|
.d_discard = lddiscard,
|
2015-08-16 21:00:03 +03:00
|
|
|
.d_flag = D_DISK | D_MPSAFE
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
static struct dkdriver lddkdriver = {
|
|
|
|
.d_open = ldopen,
|
|
|
|
.d_close = ldclose,
|
|
|
|
.d_strategy = ldstrategy,
|
|
|
|
.d_iosize = ld_iosize,
|
|
|
|
.d_minphys = ldminphys,
|
2015-08-16 21:00:03 +03:00
|
|
|
.d_diskstart = ld_diskstart,
|
2015-05-02 11:00:08 +03:00
|
|
|
.d_dumpblocks = ld_dumpblocks,
|
2015-08-17 22:47:21 +03:00
|
|
|
.d_lastclose = ld_lastclose,
|
|
|
|
.d_discard = ld_discard
|
2015-05-02 11:00:08 +03:00
|
|
|
};
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldattach(struct ld_softc *sc)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
device_t self = sc->sc_dv;
|
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_VM);
|
2015-08-16 17:02:52 +03:00
|
|
|
cv_init(&sc->sc_drain, "lddrain");
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2001-02-04 20:15:37 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
/* Initialise dk and disk structure. */
|
|
|
|
dk_init(dksc, self, DKTYPE_LD);
|
|
|
|
disk_init(&dksc->sc_dkdev, dksc->sc_xname, &lddkdriver);
|
|
|
|
|
|
|
|
/* Attach the device into the rnd source list. */
|
|
|
|
rnd_attach_source(&sc->sc_rnd_source, dksc->sc_xname,
|
|
|
|
RND_TYPE_DISK, RND_FLAG_DEFAULT);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
if (sc->sc_maxxfer > MAXPHYS)
|
|
|
|
sc->sc_maxxfer = MAXPHYS;
|
|
|
|
|
2003-01-27 05:43:30 +03:00
|
|
|
/* Build synthetic geometry if necessary. */
|
|
|
|
if (sc->sc_nheads == 0 || sc->sc_nsectors == 0 ||
|
2015-05-02 11:00:08 +03:00
|
|
|
sc->sc_ncylinders == 0)
|
|
|
|
ld_fake_geometry(sc);
|
2001-06-10 14:48:42 +04:00
|
|
|
|
2010-09-20 10:54:06 +04:00
|
|
|
sc->sc_disksize512 = sc->sc_secperunit * sc->sc_secsize / DEV_BSIZE;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
/* Attach dk and disk subsystems */
|
|
|
|
dk_attach(dksc);
|
|
|
|
disk_attach(&dksc->sc_dkdev);
|
2013-05-29 04:47:48 +04:00
|
|
|
ld_set_geometry(sc);
|
2007-02-08 06:19:42 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
bufq_alloc(&dksc->sc_bufq, BUFQ_DISK_DEFAULT_STRAT, BUFQ_SORT_RAWBLOCK);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2008-03-09 22:15:01 +03:00
|
|
|
/* Register with PMF */
|
2015-05-02 11:00:08 +03:00
|
|
|
if (!pmf_device_register1(dksc->sc_dev, ld_suspend, NULL, ld_shutdown))
|
|
|
|
aprint_error_dev(dksc->sc_dev,
|
2008-03-09 22:15:01 +03:00
|
|
|
"couldn't establish power handler\n");
|
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
/* Discover wedges on this disk. */
|
2008-09-09 16:45:39 +04:00
|
|
|
config_interrupts(sc->sc_dv, ld_config_interrupts);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-01-04 00:01:28 +03:00
|
|
|
int
|
2005-05-30 08:44:52 +04:00
|
|
|
ldadjqparam(struct ld_softc *sc, int xmax)
|
2001-01-04 00:01:28 +03:00
|
|
|
{
|
2001-02-04 20:15:37 +03:00
|
|
|
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2005-05-30 08:44:52 +04:00
|
|
|
sc->sc_maxqueuecnt = xmax;
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2001-02-04 20:15:37 +03:00
|
|
|
|
2003-06-13 06:32:27 +04:00
|
|
|
return (0);
|
2001-02-04 20:15:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbegindetach(struct ld_softc *sc, int flags)
|
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
2015-08-16 17:02:52 +03:00
|
|
|
int rv = 0;
|
2001-02-04 20:15:37 +03:00
|
|
|
|
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
|
|
|
return (0);
|
2001-01-04 00:01:28 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
rv = disk_begindetach(&dksc->sc_dkdev, ld_lastclose, dksc->sc_dev, flags);
|
2009-07-24 01:38:33 +04:00
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
2001-01-04 00:01:28 +03:00
|
|
|
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2003-06-13 06:32:27 +04:00
|
|
|
sc->sc_maxqueuecnt = 0;
|
2015-05-02 11:00:08 +03:00
|
|
|
|
|
|
|
dk_detach(dksc);
|
|
|
|
|
2003-06-13 06:32:27 +04:00
|
|
|
while (sc->sc_queuecnt > 0) {
|
|
|
|
sc->sc_flags |= LDF_DRAIN;
|
2015-08-16 17:02:52 +03:00
|
|
|
cv_wait(&sc->sc_drain, &sc->sc_mutex);
|
2003-06-13 06:32:27 +04:00
|
|
|
}
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2001-02-04 20:15:37 +03:00
|
|
|
|
|
|
|
return (rv);
|
2001-01-04 00:01:28 +03:00
|
|
|
}
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
void
|
2001-02-04 20:15:37 +03:00
|
|
|
ldenddetach(struct ld_softc *sc)
|
2000-12-03 16:03:30 +03:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
2015-08-16 17:02:52 +03:00
|
|
|
int bmaj, cmaj, i, mn;
|
2000-12-03 16:03:30 +03:00
|
|
|
|
2001-02-04 20:15:37 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
|
|
|
return;
|
|
|
|
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Wait for commands queued with the hardware to complete. */
|
2015-08-16 17:07:19 +03:00
|
|
|
if (sc->sc_queuecnt != 0) {
|
|
|
|
if (cv_timedwait(&sc->sc_drain, &sc->sc_mutex, 30 * hz))
|
2015-05-02 11:00:08 +03:00
|
|
|
printf("%s: not drained\n", dksc->sc_xname);
|
2015-08-16 17:07:19 +03:00
|
|
|
}
|
2000-12-03 16:03:30 +03:00
|
|
|
|
|
|
|
/* Kill off any queued buffers. */
|
2015-05-02 11:00:08 +03:00
|
|
|
bufq_drain(dksc->sc_bufq);
|
2015-08-16 17:02:52 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-12-03 16:03:30 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
bufq_free(dksc->sc_bufq);
|
2005-03-31 15:28:53 +04:00
|
|
|
|
2015-08-16 17:02:52 +03:00
|
|
|
/* Locate the major numbers. */
|
|
|
|
bmaj = bdevsw_lookup_major(&ld_bdevsw);
|
|
|
|
cmaj = cdevsw_lookup_major(&ld_cdevsw);
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Nuke the vnodes for any open instances. */
|
2002-05-08 19:49:07 +04:00
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
2015-05-02 11:00:08 +03:00
|
|
|
mn = DISKMINOR(device_unit(dksc->sc_dev), i);
|
2002-05-08 19:49:07 +04:00
|
|
|
vdevgone(bmaj, mn, mn, VBLK);
|
|
|
|
vdevgone(cmaj, mn, mn, VCHR);
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
/* Delete all of our wedges. */
|
2015-05-02 11:00:08 +03:00
|
|
|
dkwedge_delall(&dksc->sc_dkdev);
|
2004-09-25 08:28:08 +04:00
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Detach from the disk list. */
|
2015-05-02 11:00:08 +03:00
|
|
|
disk_detach(&dksc->sc_dkdev);
|
|
|
|
disk_destroy(&dksc->sc_dkdev);
|
2000-12-03 16:03:30 +03:00
|
|
|
|
|
|
|
/* Unhook the entropy source. */
|
|
|
|
rnd_detach_source(&sc->sc_rnd_source);
|
|
|
|
|
2008-03-09 22:18:25 +03:00
|
|
|
/* Deregister with PMF */
|
2015-05-02 11:00:08 +03:00
|
|
|
pmf_device_deregister(dksc->sc_dev);
|
2008-03-09 22:18:25 +03:00
|
|
|
|
2003-06-13 06:32:27 +04:00
|
|
|
/*
|
|
|
|
* XXX We can't really flush the cache here, beceause the
|
|
|
|
* XXX device may already be non-existent from the controller's
|
|
|
|
* XXX perspective.
|
|
|
|
*/
|
|
|
|
#if 0
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Flush the device's cache. */
|
|
|
|
if (sc->sc_flush != NULL)
|
2008-08-11 10:43:37 +04:00
|
|
|
if ((*sc->sc_flush)(sc, 0) != 0)
|
2015-08-16 20:22:00 +03:00
|
|
|
device_printf(dksc->sc_dev, "unable to flush cache\n");
|
2003-06-13 06:32:27 +04:00
|
|
|
#endif
|
2015-08-16 17:02:52 +03:00
|
|
|
cv_destroy(&sc->sc_drain);
|
2008-08-01 20:09:45 +04:00
|
|
|
mutex_destroy(&sc->sc_mutex);
|
2000-12-03 16:03:30 +03:00
|
|
|
}
|
|
|
|
|
2010-08-19 21:59:10 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
static bool
|
|
|
|
ld_suspend(device_t dev, const pmf_qual_t *qual)
|
|
|
|
{
|
|
|
|
return ld_shutdown(dev, 0);
|
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2008-03-09 22:15:01 +03:00
|
|
|
static bool
|
|
|
|
ld_shutdown(device_t dev, int flags)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2008-03-09 22:15:01 +03:00
|
|
|
struct ld_softc *sc = device_private(dev);
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2008-08-11 10:43:37 +04:00
|
|
|
if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, LDFL_POLL) != 0) {
|
2015-08-16 20:22:00 +03:00
|
|
|
device_printf(dksc->sc_dev, "unable to flush cache\n");
|
2008-03-09 22:15:01 +03:00
|
|
|
return false;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
2008-03-09 22:15:01 +03:00
|
|
|
|
|
|
|
return true;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldopen(dev_t dev, int flags, int fmt, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENXIO);
|
2015-05-02 11:00:08 +03:00
|
|
|
dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return dk_open(dksc, dev, flags, fmt, l);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
static int
|
2015-05-02 11:00:08 +03:00
|
|
|
ld_lastclose(device_t self)
|
2009-07-24 01:38:33 +04:00
|
|
|
{
|
|
|
|
struct ld_softc *sc = device_private(self);
|
2015-07-22 13:32:16 +03:00
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, 0) != 0)
|
2015-08-16 20:22:00 +03:00
|
|
|
device_printf(self, "unable to flush cache\n");
|
2015-07-22 13:32:16 +03:00
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
return 0;
|
2015-07-22 13:32:16 +03:00
|
|
|
}
|
2009-07-24 01:38:33 +04:00
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldclose(dev_t dev, int flags, int fmt, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
2015-05-02 11:00:08 +03:00
|
|
|
dksc = &sc->sc_dksc;
|
2004-09-25 08:28:08 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return dk_close(dksc, dev, flags, fmt, l);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldread(dev_t dev, struct uio *uio, int ioflag)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (physio(ldstrategy, NULL, dev, B_READ, ldminphys, uio));
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldwrite(dev_t dev, struct uio *uio, int ioflag)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (physio(ldstrategy, NULL, dev, B_WRITE, ldminphys, uio));
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
ldioctl(dev_t dev, u_long cmd, void *addr, int32_t flag, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
2014-12-31 22:52:04 +03:00
|
|
|
int unit, error;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
2015-05-02 11:00:08 +03:00
|
|
|
dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
error = disk_ioctl(&dksc->sc_dkdev, dev, cmd, addr, flag, l);
|
2007-02-08 06:19:42 +03:00
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return (error);
|
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
error = dk_ioctl(dksc, dev, cmd, addr, flag, l);
|
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return (error);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
error = 0;
|
2001-01-07 21:09:01 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
switch (cmd) {
|
2004-10-27 02:46:13 +04:00
|
|
|
case DIOCCACHESYNC:
|
|
|
|
/*
|
|
|
|
* XXX Do we really need to care about having a writable
|
|
|
|
* file descriptor here?
|
|
|
|
*/
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
else if (sc->sc_flush)
|
2008-08-11 10:43:37 +04:00
|
|
|
error = (*sc->sc_flush)(sc, 0);
|
2004-10-27 02:46:13 +04:00
|
|
|
else
|
|
|
|
error = 0; /* XXX Error out instead? */
|
|
|
|
break;
|
2000-10-19 18:06:02 +04:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldstrategy(struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
2000-12-03 16:03:30 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
unit = DISKUNIT(bp->b_dev);
|
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
|
|
|
dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return dk_strategy(dksc, bp);
|
2003-06-08 03:37:24 +04:00
|
|
|
}
|
2000-11-26 19:16:04 +03:00
|
|
|
|
2015-08-16 21:00:03 +03:00
|
|
|
static int
|
|
|
|
ld_diskstart(device_t dev, struct buf *bp)
|
2003-06-08 03:37:24 +04:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
struct ld_softc *sc = device_private(dev);
|
2003-06-08 03:37:24 +04:00
|
|
|
int error;
|
|
|
|
|
2015-08-16 21:00:03 +03:00
|
|
|
if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
|
|
|
|
return EAGAIN;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
|
|
|
|
2015-08-16 21:00:03 +03:00
|
|
|
if (sc->sc_queuecnt >= sc->sc_maxqueuecnt)
|
|
|
|
error = EAGAIN;
|
|
|
|
else {
|
|
|
|
error = (*sc->sc_start)(sc, bp);
|
|
|
|
if (error == 0)
|
|
|
|
sc->sc_queuecnt++;
|
2003-06-08 03:37:24 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mutex);
|
2015-08-16 21:00:03 +03:00
|
|
|
|
|
|
|
return error;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
lddone(struct ld_softc *sc, struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
dk_done(dksc, bp);
|
2000-11-08 22:20:33 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2001-02-04 20:15:37 +03:00
|
|
|
if (--sc->sc_queuecnt <= sc->sc_maxqueuecnt) {
|
2003-06-13 06:32:27 +04:00
|
|
|
if ((sc->sc_flags & LDF_DRAIN) != 0) {
|
|
|
|
sc->sc_flags &= ~LDF_DRAIN;
|
2015-08-16 20:32:31 +03:00
|
|
|
cv_broadcast(&sc->sc_drain);
|
2003-06-13 06:32:27 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2015-08-16 21:00:03 +03:00
|
|
|
dk_start(dksc, NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
} else
|
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ldsize(dev_t dev)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
2015-05-02 11:00:08 +03:00
|
|
|
dksc = &sc->sc_dksc;
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return dk_size(dksc, dev);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a dump.
|
|
|
|
*/
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2015-05-02 11:00:08 +03:00
|
|
|
lddump(dev_t dev, daddr_t blkno, void *va, size_t size)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENXIO);
|
2015-05-02 11:00:08 +03:00
|
|
|
dksc = &sc->sc_dksc;
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return dk_dump(dksc, dev, blkno, va, size);
|
|
|
|
}
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
static int
|
|
|
|
ld_dumpblocks(device_t dev, void *va, daddr_t blkno, int nblk)
|
|
|
|
{
|
|
|
|
struct ld_softc *sc = device_private(dev);
|
2015-07-22 13:32:16 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
if (sc->sc_dump == NULL)
|
|
|
|
return (ENXIO);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
return (*sc->sc_dump)(sc, va, blkno, nblk);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the size of a transfer.
|
|
|
|
*/
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldminphys(struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
int unit;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
unit = DISKUNIT(bp->b_dev);
|
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
ld_iosize(sc->sc_dv, &bp->b_bcount);
|
2000-10-19 18:06:02 +04:00
|
|
|
minphys(bp);
|
|
|
|
}
|
2007-02-08 06:19:42 +03:00
|
|
|
|
|
|
|
static void
|
2015-05-02 11:00:08 +03:00
|
|
|
ld_iosize(device_t d, int *countp)
|
2007-02-08 06:19:42 +03:00
|
|
|
{
|
2015-05-02 11:00:08 +03:00
|
|
|
struct ld_softc *sc = device_private(d);
|
2007-02-08 06:19:42 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
if (*countp > sc->sc_maxxfer)
|
|
|
|
*countp = sc->sc_maxxfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_fake_geometry(struct ld_softc *sc)
|
|
|
|
{
|
|
|
|
uint64_t ncyl;
|
|
|
|
|
|
|
|
if (sc->sc_secperunit <= 528 * 2048) /* 528MB */
|
|
|
|
sc->sc_nheads = 16;
|
|
|
|
else if (sc->sc_secperunit <= 1024 * 2048) /* 1GB */
|
|
|
|
sc->sc_nheads = 32;
|
|
|
|
else if (sc->sc_secperunit <= 21504 * 2048) /* 21GB */
|
|
|
|
sc->sc_nheads = 64;
|
|
|
|
else if (sc->sc_secperunit <= 43008 * 2048) /* 42GB */
|
|
|
|
sc->sc_nheads = 128;
|
|
|
|
else
|
|
|
|
sc->sc_nheads = 255;
|
|
|
|
|
|
|
|
sc->sc_nsectors = 63;
|
|
|
|
sc->sc_ncylinders = INT_MAX;
|
|
|
|
ncyl = sc->sc_secperunit /
|
|
|
|
(sc->sc_nheads * sc->sc_nsectors);
|
|
|
|
if (ncyl < INT_MAX)
|
|
|
|
sc->sc_ncylinders = (int)ncyl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ld_set_geometry(struct ld_softc *sc)
|
|
|
|
{
|
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
|
|
|
struct disk_geom *dg = &dksc->sc_dkdev.dk_geom;
|
|
|
|
char tbuf[9];
|
|
|
|
|
|
|
|
format_bytes(tbuf, sizeof(tbuf), sc->sc_secperunit *
|
|
|
|
sc->sc_secsize);
|
|
|
|
aprint_normal_dev(dksc->sc_dev, "%s, %d cyl, %d head, %d sec, "
|
|
|
|
"%d bytes/sect x %"PRIu64" sectors\n",
|
|
|
|
tbuf, sc->sc_ncylinders, sc->sc_nheads,
|
|
|
|
sc->sc_nsectors, sc->sc_secsize, sc->sc_secperunit);
|
2007-02-08 06:19:42 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
memset(dg, 0, sizeof(*dg));
|
|
|
|
dg->dg_secperunit = sc->sc_secperunit;
|
|
|
|
dg->dg_secsize = sc->sc_secsize;
|
|
|
|
dg->dg_nsectors = sc->sc_nsectors;
|
|
|
|
dg->dg_ntracks = sc->sc_nheads;
|
|
|
|
dg->dg_ncylinders = sc->sc_ncylinders;
|
2007-02-08 06:19:42 +03:00
|
|
|
|
2015-05-02 11:00:08 +03:00
|
|
|
disk_set_info(dksc->sc_dev, &dksc->sc_dkdev, NULL);
|
2007-02-08 06:19:42 +03:00
|
|
|
}
|
2007-02-23 01:28:32 +03:00
|
|
|
|
|
|
|
static void
|
2009-05-07 13:11:42 +04:00
|
|
|
ld_config_interrupts(device_t d)
|
2007-02-23 01:28:32 +03:00
|
|
|
{
|
2008-07-06 18:07:44 +04:00
|
|
|
struct ld_softc *sc = device_private(d);
|
2015-05-02 11:00:08 +03:00
|
|
|
struct dk_softc *dksc = &sc->sc_dksc;
|
|
|
|
|
|
|
|
dkwedge_discover(&dksc->sc_dkdev);
|
2007-02-23 01:28:32 +03:00
|
|
|
}
|
2015-08-17 22:47:21 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
ld_discard(device_t dev, off_t pos, off_t len)
|
|
|
|
{
|
|
|
|
struct ld_softc *sc = device_private(dev);
|
|
|
|
|
|
|
|
if (sc->sc_discard == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
return (*sc->sc_discard)(sc, pos, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lddiscard(dev_t dev, off_t pos, off_t len)
|
|
|
|
{
|
|
|
|
struct ld_softc *sc;
|
|
|
|
struct dk_softc *dksc;
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
|
|
|
dksc = &sc->sc_dksc;
|
|
|
|
|
|
|
|
return dk_discard(dksc, dev, pos, len);
|
|
|
|
}
|