2009-03-18 19:00:08 +03:00
|
|
|
/* $NetBSD: cac.c,v 1.48 2009/03/18 16:00:18 cegger Exp $ */
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
/*-
|
2007-02-10 00:55:00 +03:00
|
|
|
* Copyright (c) 2000, 2006, 2007 The NetBSD Foundation, Inc.
|
2000-03-16 17:52:22 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2000-06-13 17:36:42 +04:00
|
|
|
* by Andrew Doran.
|
2000-03-16 17:52:22 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver for Compaq array controllers.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-18 19:00:08 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: cac.c,v 1.48 2009/03/18 16:00:18 cegger Exp $");
|
2008-03-14 06:30:19 +03:00
|
|
|
|
|
|
|
#include "bio.h"
|
2001-11-13 16:14:31 +03:00
|
|
|
|
2000-03-16 17:52:22 +03: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>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/pool.h>
|
|
|
|
|
2000-11-14 21:21:00 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2006-01-30 00:42:40 +03:00
|
|
|
#include <sys/bswap.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
#include <dev/ic/cacreg.h>
|
|
|
|
#include <dev/ic/cacvar.h>
|
|
|
|
|
2008-03-14 06:30:19 +03:00
|
|
|
#if NBIO > 0
|
|
|
|
#include <dev/biovar.h>
|
|
|
|
#endif /* NBIO > 0 */
|
|
|
|
|
2004-09-13 16:55:47 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static struct cac_ccb *cac_ccb_alloc(struct cac_softc *, int);
|
|
|
|
static void cac_ccb_done(struct cac_softc *, struct cac_ccb *);
|
|
|
|
static void cac_ccb_free(struct cac_softc *, struct cac_ccb *);
|
|
|
|
static int cac_ccb_poll(struct cac_softc *, struct cac_ccb *, int);
|
|
|
|
static int cac_ccb_start(struct cac_softc *, struct cac_ccb *);
|
|
|
|
static int cac_print(void *, const char *);
|
|
|
|
static void cac_shutdown(void *);
|
|
|
|
|
|
|
|
static struct cac_ccb *cac_l0_completed(struct cac_softc *);
|
|
|
|
static int cac_l0_fifo_full(struct cac_softc *);
|
|
|
|
static void cac_l0_intr_enable(struct cac_softc *, int);
|
|
|
|
static int cac_l0_intr_pending(struct cac_softc *);
|
|
|
|
static void cac_l0_submit(struct cac_softc *, struct cac_ccb *);
|
2000-09-01 16:11:37 +04:00
|
|
|
|
|
|
|
static void *cac_sdh; /* shutdown hook */
|
|
|
|
|
2008-03-14 06:30:19 +03:00
|
|
|
#if NBIO > 0
|
|
|
|
int cac_ioctl(struct device *, u_long, void *);
|
|
|
|
int cac_ioctl_vol(struct cac_softc *, struct bioc_vol *);
|
|
|
|
int cac_create_sensors(struct cac_softc *);
|
|
|
|
void cac_sensor_refresh(struct sysmon_envsys *, envsys_data_t *);
|
|
|
|
#endif /* NBIO > 0 */
|
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
const struct cac_linkage cac_l0 = {
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_completed,
|
|
|
|
cac_l0_fifo_full,
|
|
|
|
cac_l0_intr_enable,
|
|
|
|
cac_l0_intr_pending,
|
|
|
|
cac_l0_submit
|
|
|
|
};
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise our interface to the controller.
|
|
|
|
*/
|
|
|
|
int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_init(struct cac_softc *sc, const char *intrstr, int startfw)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
|
|
|
struct cac_controller_info cinfo;
|
|
|
|
struct cac_attach_args caca;
|
|
|
|
int error, rseg, size, i;
|
|
|
|
bus_dma_segment_t seg;
|
|
|
|
struct cac_ccb *ccb;
|
2005-08-25 22:35:38 +04:00
|
|
|
int locs[CACCF_NLOCS];
|
2006-12-29 17:07:08 +03:00
|
|
|
char firm[8];
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
if (intrstr != NULL)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_normal_dev(&sc->sc_dv, "interrupting at %s\n",
|
2000-09-01 16:11:37 +04:00
|
|
|
intrstr);
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
SIMPLEQ_INIT(&sc->sc_ccb_free);
|
|
|
|
SIMPLEQ_INIT(&sc->sc_ccb_queue);
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_VM);
|
2007-02-10 00:55:00 +03:00
|
|
|
cv_init(&sc->sc_ccb_cv, "cacccb");
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
size = sizeof(struct cac_ccb) * CAC_MAX_CCBS;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat, size, PAGE_SIZE, 0, &seg, 1,
|
2000-03-16 17:52:22 +03:00
|
|
|
&rseg, BUS_DMA_NOWAIT)) != 0) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to allocate CCBs, error = %d\n",
|
|
|
|
error);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, size,
|
2007-03-04 08:59:00 +03:00
|
|
|
(void **)&sc->sc_ccbs,
|
2000-09-01 16:11:37 +04:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) != 0) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to map CCBs, error = %d\n",
|
|
|
|
error);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, size, 1, size, 0,
|
2000-03-16 17:52:22 +03:00
|
|
|
BUS_DMA_NOWAIT, &sc->sc_dmamap)) != 0) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to create CCB DMA map, error = %d\n",
|
|
|
|
error);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap, sc->sc_ccbs,
|
2000-03-16 17:52:22 +03:00
|
|
|
size, NULL, BUS_DMA_NOWAIT)) != 0) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to load CCB DMA map, error = %d\n",
|
|
|
|
error);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_ccbs_paddr = sc->sc_dmamap->dm_segs[0].ds_addr;
|
|
|
|
memset(sc->sc_ccbs, 0, size);
|
|
|
|
ccb = (struct cac_ccb *)sc->sc_ccbs;
|
|
|
|
|
|
|
|
for (i = 0; i < CAC_MAX_CCBS; i++, ccb++) {
|
|
|
|
/* Create the DMA map for this CCB's data */
|
2000-09-08 16:16:17 +04:00
|
|
|
error = bus_dmamap_create(sc->sc_dmat, CAC_MAX_XFER,
|
|
|
|
CAC_SG_SIZE, CAC_MAX_XFER, 0,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
|
|
|
&ccb->ccb_dmamap_xfer);
|
2000-09-01 16:11:37 +04:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
if (error) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "can't create ccb dmamap (%d)\n",
|
|
|
|
error);
|
2000-03-16 17:52:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccb->ccb_flags = 0;
|
|
|
|
ccb->ccb_paddr = sc->sc_ccbs_paddr + i * sizeof(struct cac_ccb);
|
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_free, ccb, ccb_chain);
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
/* Start firmware background tasks, if needed. */
|
|
|
|
if (startfw) {
|
|
|
|
if (cac_cmd(sc, CAC_CMD_START_FIRMWARE, &cinfo, sizeof(cinfo),
|
|
|
|
0, 0, CAC_CCB_DATA_IN, NULL)) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "CAC_CMD_START_FIRMWARE failed\n");
|
2000-09-01 16:11:37 +04:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
if (cac_cmd(sc, CAC_CMD_GET_CTRL_INFO, &cinfo, sizeof(cinfo), 0, 0,
|
2000-03-16 17:52:22 +03:00
|
|
|
CAC_CCB_DATA_IN, NULL)) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "CAC_CMD_GET_CTRL_INFO failed\n");
|
2000-03-16 17:52:22 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2006-12-29 17:07:08 +03:00
|
|
|
strlcpy(firm, cinfo.firm_rev, 4+1);
|
2008-04-08 16:07:25 +04:00
|
|
|
printf("%s: %d channels, firmware <%s>\n", device_xname(&sc->sc_dv),
|
2006-12-29 17:07:08 +03:00
|
|
|
cinfo.scsi_chips, firm);
|
|
|
|
|
2000-11-08 22:20:33 +03:00
|
|
|
sc->sc_nunits = cinfo.num_drvs;
|
2000-03-16 17:52:22 +03:00
|
|
|
for (i = 0; i < cinfo.num_drvs; i++) {
|
|
|
|
caca.caca_unit = i;
|
2004-09-13 16:55:47 +04:00
|
|
|
|
2005-08-25 22:35:38 +04:00
|
|
|
locs[CACCF_UNIT] = i;
|
2004-09-13 16:55:47 +04:00
|
|
|
|
2005-08-25 22:35:38 +04:00
|
|
|
config_found_sm_loc(&sc->sc_dv, "cac", locs, &caca,
|
2006-12-29 17:07:08 +03:00
|
|
|
cac_print, config_stdsubmatch);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
/* Set our `shutdownhook' before we start any device activity. */
|
2000-04-26 19:54:02 +04:00
|
|
|
if (cac_sdh == NULL)
|
2000-03-16 17:52:22 +03:00
|
|
|
cac_sdh = shutdownhook_establish(cac_shutdown, NULL);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2002-01-25 19:10:35 +03:00
|
|
|
(*sc->sc_cl.cl_intr_enable)(sc, CAC_INTR_ENABLE);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
|
|
|
|
2008-03-14 06:30:19 +03:00
|
|
|
#if NBIO > 0
|
|
|
|
if (bio_register(&sc->sc_dv, cac_ioctl) != 0)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "controller registration failed");
|
2008-03-14 06:30:19 +03:00
|
|
|
else
|
|
|
|
sc->sc_ioctl = cac_ioctl;
|
|
|
|
if (cac_create_sensors(sc) != 0)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to create sensors\n");
|
2008-03-14 06:30:19 +03:00
|
|
|
#endif
|
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-09-01 16:11:37 +04:00
|
|
|
* Shut down all `cac' controllers.
|
2000-03-16 17:52:22 +03:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
cac_shutdown(void *cookie)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
2000-04-26 19:54:02 +04:00
|
|
|
extern struct cfdriver cac_cd;
|
2000-03-16 17:52:22 +03:00
|
|
|
struct cac_softc *sc;
|
2005-05-30 08:43:46 +04:00
|
|
|
u_int8_t tbuf[512];
|
2000-04-26 19:54:02 +04:00
|
|
|
int i;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2000-04-26 19:54:02 +04:00
|
|
|
for (i = 0; i < cac_cd.cd_ndevs; i++) {
|
2008-06-08 16:43:51 +04:00
|
|
|
if ((sc = device_lookup_private(&cac_cd, i)) == NULL)
|
2005-02-27 03:26:58 +03:00
|
|
|
continue;
|
2005-05-30 08:43:46 +04:00
|
|
|
memset(tbuf, 0, sizeof(tbuf));
|
|
|
|
tbuf[0] = 1;
|
|
|
|
cac_cmd(sc, CAC_CMD_FLUSH_CACHE, tbuf, sizeof(tbuf), 0, 0,
|
2000-03-16 17:52:22 +03:00
|
|
|
CAC_CCB_DATA_OUT, NULL);
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
/*
|
2000-09-01 16:11:37 +04:00
|
|
|
* Print autoconfiguration message for a sub-device.
|
2000-03-16 17:52:22 +03:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_print(void *aux, const char *pnp)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
|
|
|
struct cac_attach_args *caca;
|
|
|
|
|
|
|
|
caca = (struct cac_attach_args *)aux;
|
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
if (pnp != NULL)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("block device at %s", pnp);
|
|
|
|
aprint_normal(" unit %d", caca->caca_unit);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an interrupt from the controller: process finished CCBs and
|
|
|
|
* dequeue any waiting CCBs.
|
|
|
|
*/
|
|
|
|
int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_intr(void *cookie)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
|
|
|
struct cac_softc *sc;
|
|
|
|
struct cac_ccb *ccb;
|
2007-02-10 00:55:00 +03:00
|
|
|
int rv;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
sc = (struct cac_softc *)cookie;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
if ((*sc->sc_cl.cl_intr_pending)(sc)) {
|
|
|
|
while ((ccb = (*sc->sc_cl.cl_completed)(sc)) != NULL) {
|
|
|
|
cac_ccb_done(sc, ccb);
|
|
|
|
cac_ccb_start(sc, NULL);
|
|
|
|
}
|
|
|
|
rv = 1;
|
|
|
|
} else
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
return (rv);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute a [polled] command.
|
|
|
|
*/
|
|
|
|
int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_cmd(struct cac_softc *sc, int command, void *data, int datasize,
|
|
|
|
int drive, int blkno, int flags, struct cac_context *context)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
|
|
|
struct cac_ccb *ccb;
|
|
|
|
struct cac_sgb *sgb;
|
2007-02-10 00:55:00 +03:00
|
|
|
int i, rv, size, nsegs;
|
2000-03-20 21:48:34 +03:00
|
|
|
|
|
|
|
size = 0;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2003-12-05 13:23:00 +03:00
|
|
|
if ((ccb = cac_ccb_alloc(sc, 1)) == NULL) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to alloc CCB");
|
2003-12-05 13:23:00 +03:00
|
|
|
return (EAGAIN);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & (CAC_CCB_DATA_IN | CAC_CCB_DATA_OUT)) != 0) {
|
2000-09-01 16:11:37 +04:00
|
|
|
bus_dmamap_load(sc->sc_dmat, ccb->ccb_dmamap_xfer,
|
2001-03-08 02:07:12 +03:00
|
|
|
(void *)data, datasize, NULL, BUS_DMA_NOWAIT |
|
2001-07-19 20:25:23 +04:00
|
|
|
BUS_DMA_STREAMING | ((flags & CAC_CCB_DATA_IN) ?
|
|
|
|
BUS_DMA_READ : BUS_DMA_WRITE));
|
2000-09-01 16:11:37 +04:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, ccb->ccb_dmamap_xfer, 0, datasize,
|
|
|
|
(flags & CAC_CCB_DATA_IN) != 0 ? BUS_DMASYNC_PREREAD :
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
sgb = ccb->ccb_seg;
|
2000-03-20 21:48:34 +03:00
|
|
|
nsegs = min(ccb->ccb_dmamap_xfer->dm_nsegs, CAC_SG_SIZE);
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2000-03-20 21:48:34 +03:00
|
|
|
for (i = 0; i < nsegs; i++, sgb++) {
|
|
|
|
size += ccb->ccb_dmamap_xfer->dm_segs[i].ds_len;
|
2005-02-27 03:26:58 +03:00
|
|
|
sgb->length =
|
2000-03-16 17:52:22 +03:00
|
|
|
htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_len);
|
2005-02-27 03:26:58 +03:00
|
|
|
sgb->addr =
|
2000-03-16 17:52:22 +03:00
|
|
|
htole32(ccb->ccb_dmamap_xfer->dm_segs[i].ds_addr);
|
|
|
|
}
|
2000-03-20 21:48:34 +03:00
|
|
|
} else {
|
|
|
|
size = datasize;
|
|
|
|
nsegs = 0;
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ccb->ccb_hdr.drive = drive;
|
2006-11-28 23:29:14 +03:00
|
|
|
ccb->ccb_hdr.priority = 0;
|
2005-02-27 03:26:58 +03:00
|
|
|
ccb->ccb_hdr.size = htole16((sizeof(struct cac_req) +
|
2000-03-16 17:52:22 +03:00
|
|
|
sizeof(struct cac_sgb) * CAC_SG_SIZE) >> 2);
|
|
|
|
|
2006-11-28 23:29:14 +03:00
|
|
|
ccb->ccb_req.next = 0;
|
|
|
|
ccb->ccb_req.error = 0;
|
|
|
|
ccb->ccb_req.reserved = 0;
|
2000-03-20 21:48:34 +03:00
|
|
|
ccb->ccb_req.bcount = htole16(howmany(size, DEV_BSIZE));
|
2000-03-16 17:52:22 +03:00
|
|
|
ccb->ccb_req.command = command;
|
2000-05-03 22:58:15 +04:00
|
|
|
ccb->ccb_req.sgcount = nsegs;
|
2000-03-16 17:52:22 +03:00
|
|
|
ccb->ccb_req.blkno = htole32(blkno);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
ccb->ccb_flags = flags;
|
2000-03-20 21:48:34 +03:00
|
|
|
ccb->ccb_datasize = size;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
if (context == NULL) {
|
|
|
|
memset(&ccb->ccb_context, 0, sizeof(struct cac_context));
|
2000-09-01 16:11:37 +04:00
|
|
|
|
|
|
|
/* Synchronous commands musn't wait. */
|
2002-01-25 19:10:35 +03:00
|
|
|
if ((*sc->sc_cl.cl_fifo_full)(sc)) {
|
2000-03-16 17:52:22 +03:00
|
|
|
cac_ccb_free(sc, ccb);
|
2003-12-05 13:23:00 +03:00
|
|
|
rv = EAGAIN;
|
2000-03-16 17:52:22 +03:00
|
|
|
} else {
|
2000-09-08 16:16:17 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
ccb->ccb_flags |= CAC_CCB_ACTIVE;
|
|
|
|
#endif
|
2002-01-25 19:10:35 +03:00
|
|
|
(*sc->sc_cl.cl_submit)(sc, ccb);
|
2000-10-19 18:28:46 +04:00
|
|
|
rv = cac_ccb_poll(sc, ccb, 2000);
|
2000-03-16 17:52:22 +03:00
|
|
|
cac_ccb_free(sc, ccb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(&ccb->ccb_context, context, sizeof(struct cac_context));
|
2003-12-05 13:23:00 +03:00
|
|
|
(void)cac_ccb_start(sc, ccb);
|
|
|
|
rv = 0;
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-10 00:55:00 +03:00
|
|
|
* Wait for the specified CCB to complete.
|
2000-03-16 17:52:22 +03:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_poll(struct cac_softc *sc, struct cac_ccb *wantccb, int timo)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
2000-09-01 16:11:37 +04:00
|
|
|
struct cac_ccb *ccb;
|
2000-10-19 18:28:46 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2006-12-29 17:07:08 +03:00
|
|
|
timo *= 1000;
|
2000-03-16 17:52:22 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
do {
|
|
|
|
for (; timo != 0; timo--) {
|
2002-01-25 19:10:35 +03:00
|
|
|
ccb = (*sc->sc_cl.cl_completed)(sc);
|
|
|
|
if (ccb != NULL)
|
2000-03-16 17:52:22 +03:00
|
|
|
break;
|
2006-12-29 17:07:08 +03:00
|
|
|
DELAY(1);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
2000-10-19 18:28:46 +04:00
|
|
|
if (timo == 0) {
|
2008-04-08 16:07:25 +04:00
|
|
|
printf("%s: timeout\n", device_xname(&sc->sc_dv));
|
2000-10-19 18:28:46 +04:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_done(sc, ccb);
|
|
|
|
} while (ccb != wantccb);
|
2000-10-19 18:28:46 +04:00
|
|
|
|
|
|
|
return (0);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-02-27 03:26:58 +03:00
|
|
|
* Enqueue the specified command (if any) and attempt to start all enqueued
|
2007-02-10 00:55:00 +03:00
|
|
|
* commands.
|
2000-03-16 17:52:22 +03:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_start(struct cac_softc *sc, struct cac_ccb *ccb)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
2000-09-01 16:11:37 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
if (ccb != NULL)
|
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_queue, ccb, ccb_chain);
|
|
|
|
|
|
|
|
while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_queue)) != NULL) {
|
2002-01-25 19:10:35 +03:00
|
|
|
if ((*sc->sc_cl.cl_fifo_full)(sc))
|
2003-12-05 13:23:00 +03:00
|
|
|
return (EAGAIN);
|
2002-06-02 03:50:52 +04:00
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_queue, ccb_chain);
|
2000-09-01 16:11:37 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
ccb->ccb_flags |= CAC_CCB_ACTIVE;
|
|
|
|
#endif
|
2002-01-25 19:10:35 +03:00
|
|
|
(*sc->sc_cl.cl_submit)(sc, ccb);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a finished CCB.
|
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_done(struct cac_softc *sc, struct cac_ccb *ccb)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
2000-11-08 22:20:33 +03:00
|
|
|
struct device *dv;
|
|
|
|
void *context;
|
2000-03-16 17:52:22 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((ccb->ccb_flags & CAC_CCB_ACTIVE) == 0)
|
|
|
|
panic("cac_ccb_done: CCB not active");
|
|
|
|
ccb->ccb_flags &= ~CAC_CCB_ACTIVE;
|
|
|
|
#endif
|
|
|
|
|
2000-03-16 17:52:22 +03:00
|
|
|
if ((ccb->ccb_flags & (CAC_CCB_DATA_IN | CAC_CCB_DATA_OUT)) != 0) {
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ccb->ccb_dmamap_xfer, 0,
|
|
|
|
ccb->ccb_datasize, ccb->ccb_flags & CAC_CCB_DATA_IN ?
|
|
|
|
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ccb->ccb_dmamap_xfer);
|
|
|
|
}
|
|
|
|
|
2000-12-11 16:19:50 +03:00
|
|
|
error = ccb->ccb_req.error;
|
2000-09-01 16:11:37 +04:00
|
|
|
if (ccb->ccb_context.cc_handler != NULL) {
|
2000-11-08 22:20:33 +03:00
|
|
|
dv = ccb->ccb_context.cc_dv;
|
|
|
|
context = ccb->ccb_context.cc_context;
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_free(sc, ccb);
|
2000-11-08 22:20:33 +03:00
|
|
|
(*ccb->ccb_context.cc_handler)(dv, context, error);
|
2000-12-11 16:19:50 +03:00
|
|
|
} else {
|
|
|
|
if ((error & CAC_RET_SOFT_ERROR) != 0)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "soft error; array may be degraded\n");
|
2000-12-11 16:19:50 +03:00
|
|
|
if ((error & CAC_RET_HARD_ERROR) != 0)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "hard error\n");
|
2000-12-11 16:19:50 +03:00
|
|
|
if ((error & CAC_RET_CMD_REJECTED) != 0) {
|
|
|
|
error = 1;
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "invalid request\n");
|
2000-12-11 16:19:50 +03:00
|
|
|
}
|
2000-09-01 16:11:37 +04:00
|
|
|
}
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-09-01 16:11:37 +04:00
|
|
|
* Allocate a CCB.
|
2000-03-16 17:52:22 +03:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static struct cac_ccb *
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_alloc(struct cac_softc *sc, int nosleep)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
|
|
|
struct cac_ccb *ccb;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_free)) != NULL) {
|
2002-06-02 03:50:52 +04:00
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_free, ccb_chain);
|
2000-03-16 17:52:22 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nosleep) {
|
|
|
|
ccb = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
cv_wait(&sc->sc_ccb_cv, &sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-03-16 17:52:22 +03:00
|
|
|
return (ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a CCB onto the freelist.
|
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_ccb_free(struct cac_softc *sc, struct cac_ccb *ccb)
|
2000-03-16 17:52:22 +03:00
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2000-03-16 17:52:22 +03:00
|
|
|
|
|
|
|
ccb->ccb_flags = 0;
|
2007-02-10 00:55:00 +03:00
|
|
|
if (SIMPLEQ_EMPTY(&sc->sc_ccb_free))
|
|
|
|
cv_signal(&sc->sc_ccb_cv);
|
2000-03-16 17:52:22 +03:00
|
|
|
SIMPLEQ_INSERT_HEAD(&sc->sc_ccb_free, ccb, ccb_chain);
|
|
|
|
}
|
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
/*
|
|
|
|
* Board specific linkage shared between multiple bus types.
|
|
|
|
*/
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_fifo_full(struct cac_softc *sc)
|
|
|
|
{
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
return (cac_inl(sc, CAC_REG_CMD_FIFO) == 0);
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb)
|
|
|
|
{
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
|
|
|
|
(char *)ccb - (char *)sc->sc_ccbs,
|
2000-09-01 16:11:37 +04:00
|
|
|
sizeof(struct cac_ccb), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
|
|
|
|
cac_outl(sc, CAC_REG_CMD_FIFO, ccb->ccb_paddr);
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static struct cac_ccb *
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_completed(struct cac_softc *sc)
|
|
|
|
{
|
|
|
|
struct cac_ccb *ccb;
|
|
|
|
paddr_t off;
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
if ((off = cac_inl(sc, CAC_REG_DONE_FIFO)) == 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
if ((off & 3) != 0)
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "failed command list returned: %lx\n",
|
|
|
|
(long)off);
|
2002-01-25 19:10:35 +03:00
|
|
|
|
|
|
|
off = (off & ~3) - sc->sc_ccbs_paddr;
|
2007-03-04 08:59:00 +03:00
|
|
|
ccb = (struct cac_ccb *)((char *)sc->sc_ccbs + off);
|
2000-09-01 16:11:37 +04:00
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, off, sizeof(struct cac_ccb),
|
|
|
|
BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
|
|
|
|
|
2006-11-28 23:29:14 +03:00
|
|
|
if ((off & 3) != 0 && ccb->ccb_req.error == 0)
|
|
|
|
ccb->ccb_req.error = CAC_RET_CMD_REJECTED;
|
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
return (ccb);
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static int
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_intr_pending(struct cac_softc *sc)
|
|
|
|
{
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2002-01-25 19:10:35 +03:00
|
|
|
return (cac_inl(sc, CAC_REG_INTR_PENDING) & CAC_INTR_ENABLE);
|
2000-09-01 16:11:37 +04:00
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_l0_intr_enable(struct cac_softc *sc, int state)
|
|
|
|
{
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
KASSERT(mutex_owned(&sc->sc_mutex));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2000-09-01 16:11:37 +04:00
|
|
|
cac_outl(sc, CAC_REG_INTR_MASK,
|
|
|
|
state ? CAC_INTR_ENABLE : CAC_INTR_DISABLE);
|
|
|
|
}
|
2008-03-14 06:30:19 +03:00
|
|
|
|
|
|
|
#if NBIO > 0
|
|
|
|
const int cac_level[] = { 0, 4, 1, 5, 51, 7 };
|
|
|
|
const int cac_stat[] = { BIOC_SVONLINE, BIOC_SVOFFLINE, BIOC_SVOFFLINE,
|
|
|
|
BIOC_SVDEGRADED, BIOC_SVREBUILD, BIOC_SVREBUILD, BIOC_SVDEGRADED,
|
|
|
|
BIOC_SVDEGRADED, BIOC_SVINVALID, BIOC_SVINVALID, BIOC_SVBUILDING,
|
|
|
|
BIOC_SVOFFLINE, BIOC_SVBUILDING };
|
|
|
|
|
|
|
|
int
|
|
|
|
cac_ioctl(struct device *dev, u_long cmd, void *addr)
|
|
|
|
{
|
|
|
|
struct cac_softc *sc = (struct cac_softc *)dev;
|
|
|
|
struct bioc_inq *bi;
|
|
|
|
struct bioc_disk *bd;
|
|
|
|
cac_lock_t lock;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
lock = CAC_LOCK(sc);
|
|
|
|
switch (cmd) {
|
|
|
|
case BIOCINQ:
|
|
|
|
bi = (struct bioc_inq *)addr;
|
2008-04-08 16:07:25 +04:00
|
|
|
strlcpy(bi->bi_dev, device_xname(&sc->sc_dv), sizeof(bi->bi_dev));
|
2008-03-14 06:30:19 +03:00
|
|
|
bi->bi_novol = sc->sc_nunits;
|
|
|
|
bi->bi_nodisk = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOCVOL:
|
|
|
|
error = cac_ioctl_vol(sc, (struct bioc_vol *)addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOCDISK:
|
|
|
|
case BIOCDISK_NOVOL:
|
|
|
|
bd = (struct bioc_disk *)addr;
|
|
|
|
if (bd->bd_volid > sc->sc_nunits) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* No disk information yet */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOCBLINK:
|
|
|
|
case BIOCALARM:
|
|
|
|
case BIOCSETSTATE:
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
CAC_UNLOCK(sc, lock);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cac_ioctl_vol(struct cac_softc *sc, struct bioc_vol *bv)
|
|
|
|
{
|
|
|
|
struct cac_drive_info dinfo;
|
|
|
|
struct cac_drive_status dstatus;
|
|
|
|
u_int32_t blks;
|
|
|
|
|
|
|
|
if (bv->bv_volid > sc->sc_nunits) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
if (cac_cmd(sc, CAC_CMD_GET_LOG_DRV_INFO, &dinfo, sizeof(dinfo),
|
|
|
|
bv->bv_volid, 0, CAC_CCB_DATA_IN, NULL)) {
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
if (cac_cmd(sc, CAC_CMD_SENSE_DRV_STATUS, &dstatus, sizeof(dstatus),
|
|
|
|
bv->bv_volid, 0, CAC_CCB_DATA_IN, NULL)) {
|
|
|
|
return EIO;
|
|
|
|
}
|
|
|
|
blks = CAC_GET2(dinfo.ncylinders) * CAC_GET1(dinfo.nheads) *
|
|
|
|
CAC_GET1(dinfo.nsectors);
|
|
|
|
bv->bv_size = (off_t)blks * CAC_GET2(dinfo.secsize);
|
|
|
|
bv->bv_level = cac_level[CAC_GET1(dinfo.mirror)]; /*XXX limit check */
|
|
|
|
bv->bv_nodisk = 0; /* XXX */
|
|
|
|
bv->bv_status = 0; /* XXX */
|
|
|
|
bv->bv_percent = -1;
|
|
|
|
bv->bv_seconds = 0;
|
|
|
|
if (dstatus.stat < sizeof(cac_stat)/sizeof(cac_stat[0]))
|
|
|
|
bv->bv_status = cac_stat[dstatus.stat];
|
|
|
|
if (bv->bv_status == BIOC_SVREBUILD ||
|
|
|
|
bv->bv_status == BIOC_SVBUILDING)
|
|
|
|
bv->bv_percent = ((blks - CAC_GET4(dstatus.prog)) * 1000ULL) /
|
|
|
|
blks;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cac_create_sensors(struct cac_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int nsensors = sc->sc_nunits;
|
|
|
|
|
|
|
|
sc->sc_sme = sysmon_envsys_create();
|
|
|
|
sc->sc_sensor = malloc(sizeof(envsys_data_t) * nsensors,
|
|
|
|
M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (sc->sc_sensor == NULL) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "can't allocate envsys_data_t\n");
|
2008-03-14 06:30:19 +03:00
|
|
|
return(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nsensors; i++) {
|
|
|
|
sc->sc_sensor[i].units = ENVSYS_DRIVE;
|
|
|
|
sc->sc_sensor[i].monitor = true;
|
|
|
|
/* Enable monitoring for drive state changes */
|
|
|
|
sc->sc_sensor[i].flags |= ENVSYS_FMONSTCHANGED;
|
|
|
|
/* logical drives */
|
|
|
|
snprintf(sc->sc_sensor[i].desc,
|
|
|
|
sizeof(sc->sc_sensor[i].desc), "%s:%d",
|
2008-04-08 16:07:25 +04:00
|
|
|
device_xname(&sc->sc_dv), i);
|
2008-03-14 06:30:19 +03:00
|
|
|
if (sysmon_envsys_sensor_attach(sc->sc_sme,
|
|
|
|
&sc->sc_sensor[i]))
|
|
|
|
goto out;
|
|
|
|
}
|
2008-04-08 16:07:25 +04:00
|
|
|
sc->sc_sme->sme_name = device_xname(&sc->sc_dv);
|
2008-03-14 06:30:19 +03:00
|
|
|
sc->sc_sme->sme_cookie = sc;
|
|
|
|
sc->sc_sme->sme_refresh = cac_sensor_refresh;
|
|
|
|
if (sysmon_envsys_register(sc->sc_sme)) {
|
2008-04-08 16:07:25 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to register with sysmon\n");
|
2008-03-14 06:30:19 +03:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(sc->sc_sensor, M_DEVBUF);
|
|
|
|
sysmon_envsys_destroy(sc->sc_sme);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cac_sensor_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
|
|
|
|
{
|
|
|
|
struct cac_softc *sc = sme->sme_cookie;
|
|
|
|
struct bioc_vol bv;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (edata->sensor >= sc->sc_nunits)
|
|
|
|
return;
|
|
|
|
|
2009-03-18 19:00:08 +03:00
|
|
|
memset(&bv, 0, sizeof(bv));
|
2008-03-14 06:30:19 +03:00
|
|
|
bv.bv_volid = edata->sensor;
|
|
|
|
s = splbio();
|
|
|
|
if (cac_ioctl_vol(sc, &bv)) {
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
switch(bv.bv_status) {
|
|
|
|
case BIOC_SVOFFLINE:
|
|
|
|
edata->value_cur = ENVSYS_DRIVE_FAIL;
|
|
|
|
edata->state = ENVSYS_SCRITICAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOC_SVDEGRADED:
|
|
|
|
edata->value_cur = ENVSYS_DRIVE_PFAIL;
|
|
|
|
edata->state = ENVSYS_SCRITICAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOC_SVSCRUB:
|
|
|
|
case BIOC_SVONLINE:
|
|
|
|
edata->value_cur = ENVSYS_DRIVE_ONLINE;
|
|
|
|
edata->state = ENVSYS_SVALID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOC_SVREBUILD:
|
|
|
|
case BIOC_SVBUILDING:
|
|
|
|
edata->value_cur = ENVSYS_DRIVE_REBUILD;
|
|
|
|
edata->state = ENVSYS_SVALID;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIOC_SVINVALID:
|
|
|
|
/* FALLTRHOUGH */
|
|
|
|
default:
|
|
|
|
edata->value_cur = 0; /* unknown */
|
|
|
|
edata->state = ENVSYS_SINVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* NBIO > 0 */
|