2003-10-26 00:26:25 +04:00
|
|
|
/* $NetBSD: iop.c,v 1.40 2003/10/25 20:26:25 mycroft Exp $ */
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/*-
|
2002-11-15 16:51:29 +03:00
|
|
|
* Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc.
|
2000-11-08 22:45:30 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Support for I2O IOPs (intelligent I/O processors).
|
|
|
|
*/
|
|
|
|
|
2001-11-13 15:24:11 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-10-26 00:26:25 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: iop.c,v 1.40 2003/10/25 20:26:25 mycroft Exp $");
|
2001-11-13 15:24:11 +03:00
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
#include "opt_i2o.h"
|
2000-12-03 16:17:03 +03:00
|
|
|
#include "iop.h"
|
2000-11-08 22:45:30 +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/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/endian.h>
|
2000-12-03 16:17:03 +03:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kthread.h>
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-11-14 21:42:55 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <dev/i2o/i2o.h>
|
2001-03-20 16:01:48 +03:00
|
|
|
#include <dev/i2o/iopio.h>
|
2000-11-08 22:45:30 +03:00
|
|
|
#include <dev/i2o/iopreg.h>
|
|
|
|
#include <dev/i2o/iopvar.h>
|
|
|
|
|
|
|
|
#define POLL(ms, cond) \
|
|
|
|
do { \
|
|
|
|
int i; \
|
|
|
|
for (i = (ms) * 10; i; i--) { \
|
|
|
|
if (cond) \
|
|
|
|
break; \
|
|
|
|
DELAY(100); \
|
|
|
|
} \
|
|
|
|
} while (/* CONSTCOND */0);
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
#define DPRINTF(x) printf x
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef I2OVERBOSE
|
2000-12-03 16:17:03 +03:00
|
|
|
#define IFVERBOSE(x) x
|
2001-03-20 16:01:48 +03:00
|
|
|
#define COMMENT(x) NULL
|
2000-11-08 22:45:30 +03:00
|
|
|
#else
|
|
|
|
#define IFVERBOSE(x)
|
2001-03-20 16:01:48 +03:00
|
|
|
#define COMMENT(x)
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#define IOP_ICTXHASH_NBUCKETS 16
|
|
|
|
#define IOP_ICTXHASH(ictx) (&iop_ictxhashtbl[(ictx) & iop_ictxhash])
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
#define IOP_MAX_SEGS (((IOP_MAX_XFER + PAGE_SIZE - 1) / PAGE_SIZE) + 1)
|
|
|
|
|
|
|
|
#define IOP_TCTX_SHIFT 12
|
|
|
|
#define IOP_TCTX_MASK ((1 << IOP_TCTX_SHIFT) - 1)
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
static LIST_HEAD(, iop_initiator) *iop_ictxhashtbl;
|
|
|
|
static u_long iop_ictxhash;
|
2000-11-08 22:45:30 +03:00
|
|
|
static void *iop_sdh;
|
2000-12-03 16:17:03 +03:00
|
|
|
static struct i2o_systab *iop_systab;
|
|
|
|
static int iop_systab_size;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
extern struct cfdriver iop_cd;
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(iopopen);
|
|
|
|
dev_type_close(iopclose);
|
|
|
|
dev_type_ioctl(iopioctl);
|
|
|
|
|
|
|
|
const struct cdevsw iop_cdevsw = {
|
|
|
|
iopopen, iopclose, noread, nowrite, iopioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#define IC_CONFIGURE 0x01
|
2001-03-20 16:01:48 +03:00
|
|
|
#define IC_PRIORITY 0x02
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
struct iop_class {
|
2000-12-03 16:17:03 +03:00
|
|
|
u_short ic_class;
|
|
|
|
u_short ic_flags;
|
2001-03-20 16:01:48 +03:00
|
|
|
#ifdef I2OVERBOSE
|
2000-11-08 22:45:30 +03:00
|
|
|
const char *ic_caption;
|
2001-03-20 16:01:48 +03:00
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
} static const iop_class[] = {
|
|
|
|
{
|
|
|
|
I2O_CLASS_EXECUTIVE,
|
|
|
|
0,
|
2002-12-06 14:22:25 +03:00
|
|
|
IFVERBOSE("executive")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_DDM,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("device driver module")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_RANDOM_BLOCK_STORAGE,
|
2001-03-20 16:01:48 +03:00
|
|
|
IC_CONFIGURE | IC_PRIORITY,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("random block storage")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_SEQUENTIAL_STORAGE,
|
2001-03-20 16:01:48 +03:00
|
|
|
IC_CONFIGURE | IC_PRIORITY,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("sequential storage")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_LAN,
|
2001-03-20 16:01:48 +03:00
|
|
|
IC_CONFIGURE | IC_PRIORITY,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("LAN port")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_WAN,
|
2001-03-20 16:01:48 +03:00
|
|
|
IC_CONFIGURE | IC_PRIORITY,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("WAN port")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_FIBRE_CHANNEL_PORT,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
IFVERBOSE("fibrechannel port")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("fibrechannel peripheral")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_SCSI_PERIPHERAL,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("SCSI peripheral")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_ATE_PORT,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
IFVERBOSE("ATE port")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_ATE_PERIPHERAL,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("ATE peripheral")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_FLOPPY_CONTROLLER,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
IFVERBOSE("floppy controller")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_FLOPPY_DEVICE,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("floppy device")
|
2000-11-08 22:45:30 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_BUS_ADAPTER_PORT,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
IFVERBOSE("bus adapter port" )
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(I2ODEBUG) && defined(I2OVERBOSE)
|
2001-03-20 16:01:48 +03:00
|
|
|
static const char * const iop_status[] = {
|
2000-11-08 22:45:30 +03:00
|
|
|
"success",
|
|
|
|
"abort (dirty)",
|
|
|
|
"abort (no data transfer)",
|
|
|
|
"abort (partial transfer)",
|
|
|
|
"error (dirty)",
|
|
|
|
"error (no data transfer)",
|
|
|
|
"error (partial transfer)",
|
|
|
|
"undefined error code",
|
|
|
|
"process abort (dirty)",
|
|
|
|
"process abort (no data transfer)",
|
|
|
|
"process abort (partial transfer)",
|
|
|
|
"transaction error",
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
static inline u_int32_t iop_inl(struct iop_softc *, int);
|
|
|
|
static inline void iop_outl(struct iop_softc *, int, u_int32_t);
|
|
|
|
|
2002-11-08 08:47:35 +03:00
|
|
|
static inline u_int32_t iop_inl_msg(struct iop_softc *, int);
|
2002-11-15 16:51:29 +03:00
|
|
|
static inline void iop_outl_msg(struct iop_softc *, int, u_int32_t);
|
2002-11-08 08:47:35 +03:00
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_config_interrupts(struct device *);
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_configure_devices(struct iop_softc *, int, int);
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_devinfo(int, char *);
|
|
|
|
static int iop_print(void *, const char *);
|
|
|
|
static void iop_shutdown(void *);
|
|
|
|
static int iop_submatch(struct device *, struct cfdata *, void *);
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_adjqparam(struct iop_softc *, int);
|
2001-01-04 00:04:01 +03:00
|
|
|
static void iop_create_reconf_thread(void *);
|
2001-03-20 16:01:48 +03:00
|
|
|
static int iop_handle_reply(struct iop_softc *, u_int32_t);
|
2000-11-08 22:45:30 +03:00
|
|
|
static int iop_hrt_get(struct iop_softc *);
|
|
|
|
static int iop_hrt_get0(struct iop_softc *, struct i2o_hrt *, int);
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_intr_event(struct device *, struct iop_msg *, void *);
|
2000-12-03 16:17:03 +03:00
|
|
|
static int iop_lct_get0(struct iop_softc *, struct i2o_lct *, int,
|
|
|
|
u_int32_t);
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_msg_poll(struct iop_softc *, struct iop_msg *, int);
|
|
|
|
static void iop_msg_wait(struct iop_softc *, struct iop_msg *, int);
|
2000-11-08 22:45:30 +03:00
|
|
|
static int iop_ofifo_init(struct iop_softc *);
|
2001-08-04 20:54:18 +04:00
|
|
|
static int iop_passthrough(struct iop_softc *, struct ioppt *,
|
|
|
|
struct proc *);
|
2001-01-04 00:04:01 +03:00
|
|
|
static void iop_reconf_thread(void *);
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_release_mfa(struct iop_softc *, u_int32_t);
|
|
|
|
static int iop_reset(struct iop_softc *);
|
|
|
|
static int iop_systab_set(struct iop_softc *);
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_tfn_print(struct iop_softc *, struct i2o_fault_notify *);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
static void iop_reply_print(struct iop_softc *, struct i2o_reply *);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
static inline u_int32_t
|
|
|
|
iop_inl(struct iop_softc *sc, int off)
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_space_barrier(sc->sc_iot, sc->sc_ioh, off, 4,
|
|
|
|
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
|
|
|
|
return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, off));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
iop_outl(struct iop_softc *sc, int off, u_int32_t val)
|
|
|
|
{
|
|
|
|
|
|
|
|
bus_space_write_4(sc->sc_iot, sc->sc_ioh, off, val);
|
|
|
|
bus_space_barrier(sc->sc_iot, sc->sc_ioh, off, 4,
|
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
|
|
|
}
|
|
|
|
|
2002-11-08 08:47:35 +03:00
|
|
|
static inline u_int32_t
|
|
|
|
iop_inl_msg(struct iop_softc *sc, int off)
|
|
|
|
{
|
|
|
|
|
2002-12-11 16:02:31 +03:00
|
|
|
bus_space_barrier(sc->sc_msg_iot, sc->sc_msg_ioh, off, 4,
|
2002-11-08 08:47:35 +03:00
|
|
|
BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ);
|
2002-12-11 16:02:31 +03:00
|
|
|
return (bus_space_read_4(sc->sc_msg_iot, sc->sc_msg_ioh, off));
|
2002-11-08 08:47:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2002-11-15 16:51:29 +03:00
|
|
|
iop_outl_msg(struct iop_softc *sc, int off, u_int32_t val)
|
2002-11-08 08:47:35 +03:00
|
|
|
{
|
|
|
|
|
2002-11-15 16:51:29 +03:00
|
|
|
bus_space_write_4(sc->sc_msg_iot, sc->sc_msg_ioh, off, val);
|
|
|
|
bus_space_barrier(sc->sc_msg_iot, sc->sc_msg_ioh, off, 4,
|
2002-11-08 08:47:35 +03:00
|
|
|
BUS_SPACE_BARRIER_WRITE);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Initialise the IOP and our interface.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
void
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_init(struct iop_softc *sc, const char *intrstr)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
struct iop_msg *im;
|
2003-10-26 00:26:25 +04:00
|
|
|
int rv, i, j, state, nsegs;
|
2000-11-08 22:45:30 +03:00
|
|
|
u_int32_t mask;
|
|
|
|
char ident[64];
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
state = 0;
|
|
|
|
|
|
|
|
printf("I2O adapter");
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if (iop_ictxhashtbl == NULL)
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_ictxhashtbl = hashinit(IOP_ICTXHASH_NBUCKETS, HASH_LIST,
|
|
|
|
M_DEVBUF, M_NOWAIT, &iop_ictxhash);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
/* Disable interrupts at the IOP. */
|
|
|
|
mask = iop_inl(sc, IOP_REG_INTR_MASK);
|
|
|
|
iop_outl(sc, IOP_REG_INTR_MASK, mask | IOP_INTR_OFIFO);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
/* Allocate a scratch DMA map for small miscellaneous shared data. */
|
|
|
|
if (bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, 0,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &sc->sc_scr_dmamap) != 0) {
|
|
|
|
printf("%s: cannot create scratch dmamap\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
2000-12-03 16:17:03 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-08-04 20:54:18 +04:00
|
|
|
|
|
|
|
if (bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0,
|
|
|
|
sc->sc_scr_seg, 1, &nsegs, BUS_DMA_NOWAIT) != 0) {
|
|
|
|
printf("%s: cannot alloc scratch dmamem\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
state++;
|
|
|
|
|
|
|
|
if (bus_dmamem_map(sc->sc_dmat, sc->sc_scr_seg, nsegs, PAGE_SIZE,
|
|
|
|
&sc->sc_scr, 0)) {
|
|
|
|
printf("%s: cannot map scratch dmamem\n", sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
state++;
|
|
|
|
|
|
|
|
if (bus_dmamap_load(sc->sc_dmat, sc->sc_scr_dmamap, sc->sc_scr,
|
|
|
|
PAGE_SIZE, NULL, BUS_DMA_NOWAIT)) {
|
|
|
|
printf("%s: cannot load scratch dmamap\n", sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
2001-08-04 20:54:18 +04:00
|
|
|
state++;
|
|
|
|
|
2002-01-02 22:04:17 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
/* So that our debug checks don't choke. */
|
|
|
|
sc->sc_framesize = 128;
|
|
|
|
#endif
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
/* Reset the adapter and request status. */
|
|
|
|
if ((rv = iop_reset(sc)) != 0) {
|
|
|
|
printf("%s: not responding (reset)\n", sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = iop_status_get(sc, 1)) != 0) {
|
|
|
|
printf("%s: not responding (get status)\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
sc->sc_flags |= IOP_HAVESTATUS;
|
|
|
|
iop_strvis(sc, sc->sc_status.productid, sizeof(sc->sc_status.productid),
|
2000-11-08 22:45:30 +03:00
|
|
|
ident, sizeof(ident));
|
2000-12-03 16:17:03 +03:00
|
|
|
printf(" <%s>\n", ident);
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
printf("%s: orgid=0x%04x version=%d\n", sc->sc_dv.dv_xname,
|
|
|
|
le16toh(sc->sc_status.orgid),
|
|
|
|
(le32toh(sc->sc_status.segnumber) >> 12) & 15);
|
|
|
|
printf("%s: type want have cbase\n", sc->sc_dv.dv_xname);
|
|
|
|
printf("%s: mem %04x %04x %08x\n", sc->sc_dv.dv_xname,
|
|
|
|
le32toh(sc->sc_status.desiredprivmemsize),
|
|
|
|
le32toh(sc->sc_status.currentprivmemsize),
|
|
|
|
le32toh(sc->sc_status.currentprivmembase));
|
|
|
|
printf("%s: i/o %04x %04x %08x\n", sc->sc_dv.dv_xname,
|
|
|
|
le32toh(sc->sc_status.desiredpriviosize),
|
|
|
|
le32toh(sc->sc_status.currentpriviosize),
|
|
|
|
le32toh(sc->sc_status.currentpriviobase));
|
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_maxob = le32toh(sc->sc_status.maxoutboundmframes);
|
|
|
|
if (sc->sc_maxob > IOP_MAX_OUTBOUND)
|
|
|
|
sc->sc_maxob = IOP_MAX_OUTBOUND;
|
|
|
|
sc->sc_maxib = le32toh(sc->sc_status.maxinboundmframes);
|
|
|
|
if (sc->sc_maxib > IOP_MAX_INBOUND)
|
|
|
|
sc->sc_maxib = IOP_MAX_INBOUND;
|
2001-09-27 22:43:37 +04:00
|
|
|
sc->sc_framesize = le16toh(sc->sc_status.inboundmframesize) << 2;
|
|
|
|
if (sc->sc_framesize > IOP_MAX_MSG_SIZE)
|
|
|
|
sc->sc_framesize = IOP_MAX_MSG_SIZE;
|
|
|
|
|
|
|
|
#if defined(I2ODEBUG) || defined(DIAGNOSTIC)
|
|
|
|
if (sc->sc_framesize < IOP_MIN_MSG_SIZE) {
|
|
|
|
printf("%s: frame size too small (%d)\n",
|
|
|
|
sc->sc_dv.dv_xname, sc->sc_framesize);
|
2002-03-08 14:37:04 +03:00
|
|
|
goto bail_out;
|
2001-09-27 22:43:37 +04:00
|
|
|
}
|
|
|
|
#endif
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
/* Allocate message wrappers. */
|
2002-01-12 19:41:02 +03:00
|
|
|
im = malloc(sizeof(*im) * sc->sc_maxib, M_DEVBUF, M_NOWAIT|M_ZERO);
|
2002-03-08 14:37:04 +03:00
|
|
|
if (im == NULL) {
|
|
|
|
printf("%s: memory allocation failure\n", sc->sc_dv.dv_xname);
|
|
|
|
goto bail_out;
|
|
|
|
}
|
|
|
|
state++;
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_ims = im;
|
|
|
|
SLIST_INIT(&sc->sc_im_freelist);
|
|
|
|
|
2003-10-26 00:26:25 +04:00
|
|
|
for (i = 0; i < sc->sc_maxib; i++, im++) {
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
|
|
|
|
IOP_MAX_SEGS, IOP_MAX_XFER, 0,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
|
|
|
&im->im_xfer[0].ix_map);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: couldn't create dmamap (%d)",
|
|
|
|
sc->sc_dv.dv_xname, rv);
|
2003-10-26 00:26:25 +04:00
|
|
|
goto bail_out3;
|
2001-03-20 16:01:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
im->im_tctx = i;
|
|
|
|
SLIST_INSERT_HEAD(&sc->sc_im_freelist, im, im_chain);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-09-18 22:15:49 +04:00
|
|
|
/* Initialise the IOP's outbound FIFO. */
|
2000-12-03 16:17:03 +03:00
|
|
|
if (iop_ofifo_init(sc) != 0) {
|
2001-08-04 20:54:18 +04:00
|
|
|
printf("%s: unable to init oubound FIFO\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
2003-10-26 00:26:25 +04:00
|
|
|
goto bail_out3;
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/*
|
|
|
|
* Defer further configuration until (a) interrupts are working and
|
|
|
|
* (b) we have enough information to build the system table.
|
|
|
|
*/
|
2000-11-08 22:45:30 +03:00
|
|
|
config_interrupts((struct device *)sc, iop_config_interrupts);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/* Configure shutdown hook before we start any device activity. */
|
2000-11-08 22:45:30 +03:00
|
|
|
if (iop_sdh == NULL)
|
|
|
|
iop_sdh = shutdownhook_establish(iop_shutdown, NULL);
|
|
|
|
|
|
|
|
/* Ensure interrupts are enabled at the IOP. */
|
2000-12-03 16:17:03 +03:00
|
|
|
mask = iop_inl(sc, IOP_REG_INTR_MASK);
|
|
|
|
iop_outl(sc, IOP_REG_INTR_MASK, mask & ~IOP_INTR_OFIFO);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
if (intrstr != NULL)
|
|
|
|
printf("%s: interrupting at %s\n", sc->sc_dv.dv_xname,
|
|
|
|
intrstr);
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
printf("%s: queue depths: inbound %d/%d, outbound %d/%d\n",
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_dv.dv_xname, sc->sc_maxib,
|
|
|
|
le32toh(sc->sc_status.maxinboundmframes),
|
|
|
|
sc->sc_maxob, le32toh(sc->sc_status.maxoutboundmframes));
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
lockinit(&sc->sc_conflock, PRIBIO, "iopconf", hz * 30, 0);
|
2001-08-04 20:54:18 +04:00
|
|
|
return;
|
|
|
|
|
2003-10-26 00:26:25 +04:00
|
|
|
bail_out3:
|
2001-08-04 20:54:18 +04:00
|
|
|
if (state > 3) {
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat,
|
|
|
|
sc->sc_ims[j].im_xfer[0].ix_map);
|
|
|
|
free(sc->sc_ims, M_DEVBUF);
|
|
|
|
}
|
2003-10-26 00:26:25 +04:00
|
|
|
bail_out:
|
2001-08-04 20:54:18 +04:00
|
|
|
if (state > 2)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_scr_dmamap);
|
|
|
|
if (state > 1)
|
|
|
|
bus_dmamem_unmap(sc->sc_dmat, sc->sc_scr, PAGE_SIZE);
|
|
|
|
if (state > 0)
|
|
|
|
bus_dmamem_free(sc->sc_dmat, sc->sc_scr_seg, nsegs);
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_scr_dmamap);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Perform autoconfiguration tasks.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_config_interrupts(struct device *self)
|
|
|
|
{
|
2001-09-22 03:44:19 +04:00
|
|
|
struct iop_attach_args ia;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_softc *sc, *iop;
|
|
|
|
struct i2o_systab_entry *ste;
|
|
|
|
int rv, i, niop;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
sc = (struct iop_softc *)self;
|
2000-12-03 16:17:03 +03:00
|
|
|
LIST_INIT(&sc->sc_iilist);
|
|
|
|
|
|
|
|
printf("%s: configuring...\n", sc->sc_dv.dv_xname);
|
|
|
|
|
|
|
|
if (iop_hrt_get(sc) != 0) {
|
|
|
|
printf("%s: unable to retrieve HRT\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build the system table.
|
|
|
|
*/
|
|
|
|
if (iop_systab == NULL) {
|
|
|
|
for (i = 0, niop = 0; i < iop_cd.cd_ndevs; i++) {
|
|
|
|
if ((iop = device_lookup(&iop_cd, i)) == NULL)
|
|
|
|
continue;
|
|
|
|
if ((iop->sc_flags & IOP_HAVESTATUS) == 0)
|
|
|
|
continue;
|
2001-03-20 16:01:48 +03:00
|
|
|
if (iop_status_get(iop, 1) != 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: unable to retrieve status\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
iop->sc_flags &= ~IOP_HAVESTATUS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
niop++;
|
|
|
|
}
|
|
|
|
if (niop == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
i = sizeof(struct i2o_systab_entry) * (niop - 1) +
|
|
|
|
sizeof(struct i2o_systab);
|
|
|
|
iop_systab_size = i;
|
2002-01-12 19:41:02 +03:00
|
|
|
iop_systab = malloc(i, M_DEVBUF, M_NOWAIT|M_ZERO);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
iop_systab->numentries = niop;
|
|
|
|
iop_systab->version = I2O_VERSION_11;
|
|
|
|
|
|
|
|
for (i = 0, ste = iop_systab->entry; i < iop_cd.cd_ndevs; i++) {
|
|
|
|
if ((iop = device_lookup(&iop_cd, i)) == NULL)
|
|
|
|
continue;
|
|
|
|
if ((iop->sc_flags & IOP_HAVESTATUS) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ste->orgid = iop->sc_status.orgid;
|
|
|
|
ste->iopid = iop->sc_dv.dv_unit + 2;
|
|
|
|
ste->segnumber =
|
|
|
|
htole32(le32toh(iop->sc_status.segnumber) & ~4095);
|
|
|
|
ste->iopcaps = iop->sc_status.iopcaps;
|
|
|
|
ste->inboundmsgframesize =
|
|
|
|
iop->sc_status.inboundmframesize;
|
|
|
|
ste->inboundmsgportaddresslow =
|
|
|
|
htole32(iop->sc_memaddr + IOP_REG_IFIFO);
|
|
|
|
ste++;
|
|
|
|
}
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Post the system table to the IOP and bring it to the OPERATIONAL
|
|
|
|
* state.
|
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
if (iop_systab_set(sc) != 0) {
|
|
|
|
printf("%s: unable to set system table\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_SYS_ENABLE, IOP_ICTX, 1,
|
2001-03-20 16:01:48 +03:00
|
|
|
30000) != 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: unable to enable system\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/*
|
|
|
|
* Set up an event handler for this IOP.
|
|
|
|
*/
|
|
|
|
sc->sc_eventii.ii_dv = self;
|
|
|
|
sc->sc_eventii.ii_intr = iop_intr_event;
|
2001-08-04 20:54:18 +04:00
|
|
|
sc->sc_eventii.ii_flags = II_NOTCTX | II_UTILITY;
|
2000-12-03 16:17:03 +03:00
|
|
|
sc->sc_eventii.ii_tid = I2O_TID_IOP;
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_initiator_register(sc, &sc->sc_eventii);
|
|
|
|
|
|
|
|
rv = iop_util_eventreg(sc, &sc->sc_eventii,
|
|
|
|
I2O_EVENT_EXEC_RESOURCE_LIMITS |
|
|
|
|
I2O_EVENT_EXEC_CONNECTION_FAIL |
|
|
|
|
I2O_EVENT_EXEC_ADAPTER_FAULT |
|
|
|
|
I2O_EVENT_EXEC_POWER_FAIL |
|
|
|
|
I2O_EVENT_EXEC_RESET_PENDING |
|
|
|
|
I2O_EVENT_EXEC_RESET_IMMINENT |
|
|
|
|
I2O_EVENT_EXEC_HARDWARE_FAIL |
|
|
|
|
I2O_EVENT_EXEC_XCT_CHANGE |
|
|
|
|
I2O_EVENT_EXEC_DDM_AVAILIBILITY |
|
|
|
|
I2O_EVENT_GEN_DEVICE_RESET |
|
|
|
|
I2O_EVENT_GEN_STATE_CHANGE |
|
|
|
|
I2O_EVENT_GEN_GENERAL_WARNING);
|
|
|
|
if (rv != 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: unable to register for events", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-22 03:44:19 +04:00
|
|
|
/*
|
|
|
|
* Attempt to match and attach a product-specific extension.
|
|
|
|
*/
|
2000-11-08 22:45:30 +03:00
|
|
|
ia.ia_class = I2O_CLASS_ANY;
|
|
|
|
ia.ia_tid = I2O_TID_IOP;
|
2002-12-06 14:22:25 +03:00
|
|
|
config_found_sm(self, &ia, iop_print, iop_submatch);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-09-22 03:44:19 +04:00
|
|
|
/*
|
|
|
|
* Start device configuration.
|
|
|
|
*/
|
2001-03-20 16:01:48 +03:00
|
|
|
lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL);
|
|
|
|
if ((rv = iop_reconfigure(sc, 0)) == -1) {
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: configure failed (%d)\n", sc->sc_dv.dv_xname, rv);
|
|
|
|
return;
|
|
|
|
}
|
2001-03-20 16:01:48 +03:00
|
|
|
lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
kthread_create(iop_create_reconf_thread, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the reconfiguration thread. Called after the standard kernel
|
|
|
|
* threads have been created.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_create_reconf_thread(void *cookie)
|
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
|
|
|
int rv;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
sc = cookie;
|
|
|
|
sc->sc_flags |= IOP_ONLINE;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
rv = kthread_create1(iop_reconf_thread, sc, &sc->sc_reconf_proc,
|
2001-03-20 16:01:48 +03:00
|
|
|
"%s", sc->sc_dv.dv_xname);
|
|
|
|
if (rv != 0) {
|
2001-01-04 00:04:01 +03:00
|
|
|
printf("%s: unable to create reconfiguration thread (%d)",
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_dv.dv_xname, rv);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconfiguration thread; listens for LCT change notification, and
|
2001-06-12 19:17:10 +04:00
|
|
|
* initiates re-configuration if received.
|
2000-12-03 16:17:03 +03:00
|
|
|
*/
|
|
|
|
static void
|
2001-01-04 00:04:01 +03:00
|
|
|
iop_reconf_thread(void *cookie)
|
2000-12-03 16:17:03 +03:00
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
2003-01-19 00:21:28 +03:00
|
|
|
struct lwp *l;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_lct lct;
|
|
|
|
u_int32_t chgind;
|
2001-03-20 16:01:48 +03:00
|
|
|
int rv;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
sc = cookie;
|
2001-03-20 16:01:48 +03:00
|
|
|
chgind = sc->sc_chgind + 1;
|
2003-01-19 00:21:28 +03:00
|
|
|
l = curlwp;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2001-03-20 16:01:48 +03:00
|
|
|
DPRINTF(("%s: async reconfig: requested 0x%08x\n",
|
|
|
|
sc->sc_dv.dv_xname, chgind));
|
|
|
|
|
2003-01-19 00:21:28 +03:00
|
|
|
PHOLD(l);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_lct_get0(sc, &lct, sizeof(lct), chgind);
|
2003-01-19 00:21:28 +03:00
|
|
|
PRELE(l);
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: async reconfig: notified (0x%08x, %d)\n",
|
|
|
|
sc->sc_dv.dv_xname, le32toh(lct.changeindicator), rv));
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rv == 0 &&
|
|
|
|
lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL) == 0) {
|
|
|
|
iop_reconfigure(sc, le32toh(lct.changeindicator));
|
|
|
|
chgind = sc->sc_chgind + 1;
|
|
|
|
lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
tsleep(iop_reconf_thread, PWAIT, "iopzzz", hz * 5);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconfigure: find new and removed devices.
|
|
|
|
*/
|
2001-09-22 03:44:19 +04:00
|
|
|
int
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_reconfigure(struct iop_softc *sc, u_int chgind)
|
2000-12-03 16:17:03 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_hba_bus_scan mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_lct_entry *le;
|
|
|
|
struct iop_initiator *ii, *nextii;
|
|
|
|
int rv, tid, i;
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* If the reconfiguration request isn't the result of LCT change
|
|
|
|
* notification, then be more thorough: ask all bus ports to scan
|
|
|
|
* their busses. Wait up to 5 minutes for each bus port to complete
|
|
|
|
* the request.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
if (chgind == 0) {
|
|
|
|
if ((rv = iop_lct_get(sc)) != 0) {
|
|
|
|
DPRINTF(("iop_reconfigure: unable to read LCT\n"));
|
2001-03-20 16:01:48 +03:00
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
le = sc->sc_lct->entry;
|
|
|
|
for (i = 0; i < sc->sc_nlctent; i++, le++) {
|
|
|
|
if ((le16toh(le->classid) & 4095) !=
|
|
|
|
I2O_CLASS_BUS_ADAPTER_PORT)
|
|
|
|
continue;
|
2001-08-04 20:54:18 +04:00
|
|
|
tid = le16toh(le->localtid) & 4095;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(tid, I2O_HBA_BUS_SCAN);
|
|
|
|
mf.msgictx = IOP_ICTX;
|
|
|
|
mf.msgtctx = im->im_tctx;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
DPRINTF(("%s: scanning bus %d\n", sc->sc_dv.dv_xname,
|
|
|
|
tid));
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, &mf, 5*60*1000);
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (rv != 0)
|
|
|
|
printf("%s: bus scan failed\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
#endif
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
2001-03-20 16:01:48 +03:00
|
|
|
} else if (chgind <= sc->sc_chgind) {
|
2000-12-03 16:17:03 +03:00
|
|
|
DPRINTF(("%s: LCT unchanged (async)\n", sc->sc_dv.dv_xname));
|
2001-03-20 16:01:48 +03:00
|
|
|
return (0);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-read the LCT and determine if it has changed. */
|
|
|
|
if ((rv = iop_lct_get(sc)) != 0) {
|
|
|
|
DPRINTF(("iop_reconfigure: unable to re-read LCT\n"));
|
2001-03-20 16:01:48 +03:00
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
DPRINTF(("%s: %d LCT entries\n", sc->sc_dv.dv_xname, sc->sc_nlctent));
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
chgind = le32toh(sc->sc_lct->changeindicator);
|
|
|
|
if (chgind == sc->sc_chgind) {
|
2000-12-03 16:17:03 +03:00
|
|
|
DPRINTF(("%s: LCT unchanged\n", sc->sc_dv.dv_xname));
|
2001-03-20 16:01:48 +03:00
|
|
|
return (0);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
DPRINTF(("%s: LCT changed\n", sc->sc_dv.dv_xname));
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_chgind = chgind;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
if (sc->sc_tidmap != NULL)
|
|
|
|
free(sc->sc_tidmap, M_DEVBUF);
|
|
|
|
sc->sc_tidmap = malloc(sc->sc_nlctent * sizeof(struct iop_tidmap),
|
2002-01-12 19:41:02 +03:00
|
|
|
M_DEVBUF, M_NOWAIT|M_ZERO);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Allow 1 queued command per device while we're configuring. */
|
|
|
|
iop_adjqparam(sc, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Match and attach child devices. We configure high-level devices
|
|
|
|
* first so that any claims will propagate throughout the LCT,
|
|
|
|
* hopefully masking off aliased devices as a result.
|
|
|
|
*
|
|
|
|
* Re-reading the LCT at this point is a little dangerous, but we'll
|
|
|
|
* trust the IOP (and the operator) to behave itself...
|
|
|
|
*/
|
|
|
|
iop_configure_devices(sc, IC_CONFIGURE | IC_PRIORITY,
|
|
|
|
IC_CONFIGURE | IC_PRIORITY);
|
|
|
|
if ((rv = iop_lct_get(sc)) != 0)
|
|
|
|
DPRINTF(("iop_reconfigure: unable to re-read LCT\n"));
|
|
|
|
iop_configure_devices(sc, IC_CONFIGURE | IC_PRIORITY,
|
|
|
|
IC_CONFIGURE);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
for (ii = LIST_FIRST(&sc->sc_iilist); ii != NULL; ii = nextii) {
|
2001-03-20 16:01:48 +03:00
|
|
|
nextii = LIST_NEXT(ii, ii_list);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
/* Detach devices that were configured, but are now gone. */
|
|
|
|
for (i = 0; i < sc->sc_nlctent; i++)
|
|
|
|
if (ii->ii_tid == sc->sc_tidmap[i].it_tid)
|
|
|
|
break;
|
|
|
|
if (i == sc->sc_nlctent ||
|
|
|
|
(sc->sc_tidmap[i].it_flags & IT_CONFIGURED) == 0)
|
|
|
|
config_detach(ii->ii_dv, DETACH_FORCE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell initiators that existed before the re-configuration
|
|
|
|
* to re-configure.
|
|
|
|
*/
|
|
|
|
if (ii->ii_reconfig == NULL)
|
|
|
|
continue;
|
|
|
|
if ((rv = (*ii->ii_reconfig)(ii->ii_dv)) != 0)
|
|
|
|
printf("%s: %s failed reconfigure (%d)\n",
|
|
|
|
sc->sc_dv.dv_xname, ii->ii_dv->dv_xname, rv);
|
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Re-adjust queue parameters and return. */
|
|
|
|
if (sc->sc_nii != 0)
|
|
|
|
iop_adjqparam(sc, (sc->sc_maxib - sc->sc_nuii - IOP_MF_RESERVE)
|
|
|
|
/ sc->sc_nii);
|
|
|
|
|
|
|
|
return (0);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Configure I2O devices into the system.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static void
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_configure_devices(struct iop_softc *sc, int mask, int maskval)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_attach_args ia;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_initiator *ii;
|
2000-11-08 22:45:30 +03:00
|
|
|
const struct i2o_lct_entry *le;
|
2001-01-04 00:04:01 +03:00
|
|
|
struct device *dv;
|
2001-01-01 22:03:30 +03:00
|
|
|
int i, j, nent;
|
2001-03-20 16:01:48 +03:00
|
|
|
u_int usertid;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
nent = sc->sc_nlctent;
|
|
|
|
for (i = 0, le = sc->sc_lct->entry; i < nent; i++, le++) {
|
2001-08-04 20:54:18 +04:00
|
|
|
sc->sc_tidmap[i].it_tid = le16toh(le->localtid) & 4095;
|
2001-01-04 00:04:01 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Ignore the device if it's in use. */
|
|
|
|
usertid = le32toh(le->usertid) & 4095;
|
|
|
|
if (usertid != I2O_TID_NONE && usertid != I2O_TID_HOST)
|
2000-11-08 22:45:30 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ia.ia_class = le16toh(le->classid) & 4095;
|
2001-01-04 00:04:01 +03:00
|
|
|
ia.ia_tid = sc->sc_tidmap[i].it_tid;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-01-01 22:03:30 +03:00
|
|
|
/* Ignore uninteresting devices. */
|
|
|
|
for (j = 0; j < sizeof(iop_class) / sizeof(iop_class[0]); j++)
|
|
|
|
if (iop_class[j].ic_class == ia.ia_class)
|
|
|
|
break;
|
|
|
|
if (j < sizeof(iop_class) / sizeof(iop_class[0]) &&
|
2001-03-20 16:01:48 +03:00
|
|
|
(iop_class[j].ic_flags & mask) != maskval)
|
2001-01-01 22:03:30 +03:00
|
|
|
continue;
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Try to configure the device only if it's not already
|
|
|
|
* configured.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2000-12-03 18:51:36 +03:00
|
|
|
LIST_FOREACH(ii, &sc->sc_iilist, ii_list) {
|
2001-01-04 00:04:01 +03:00
|
|
|
if (ia.ia_tid == ii->ii_tid) {
|
|
|
|
sc->sc_tidmap[i].it_flags |= IT_CONFIGURED;
|
|
|
|
strcpy(sc->sc_tidmap[i].it_dvname,
|
|
|
|
ii->ii_dv->dv_xname);
|
2001-03-20 16:01:48 +03:00
|
|
|
break;
|
2001-01-04 00:04:01 +03:00
|
|
|
}
|
2000-12-03 18:51:36 +03:00
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
if (ii != NULL)
|
|
|
|
continue;
|
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
dv = config_found_sm(&sc->sc_dv, &ia, iop_print, iop_submatch);
|
|
|
|
if (dv != NULL) {
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_tidmap[i].it_flags |= IT_CONFIGURED;
|
2001-01-04 00:04:01 +03:00
|
|
|
strcpy(sc->sc_tidmap[i].it_dvname, dv->dv_xname);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Adjust queue parameters for all child devices.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_adjqparam(struct iop_softc *sc, int mpi)
|
|
|
|
{
|
|
|
|
struct iop_initiator *ii;
|
|
|
|
|
|
|
|
LIST_FOREACH(ii, &sc->sc_iilist, ii_list)
|
|
|
|
if (ii->ii_adjqparam != NULL)
|
|
|
|
(*ii->ii_adjqparam)(ii->ii_dv, mpi);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
static void
|
|
|
|
iop_devinfo(int class, char *devinfo)
|
|
|
|
{
|
|
|
|
#ifdef I2OVERBOSE
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(iop_class) / sizeof(iop_class[0]); i++)
|
|
|
|
if (class == iop_class[i].ic_class)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == sizeof(iop_class) / sizeof(iop_class[0]))
|
|
|
|
sprintf(devinfo, "device (class 0x%x)", class);
|
|
|
|
else
|
|
|
|
strcpy(devinfo, iop_class[i].ic_caption);
|
|
|
|
#else
|
|
|
|
|
|
|
|
sprintf(devinfo, "device (class 0x%x)", class);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
iop_print(void *aux, const char *pnp)
|
|
|
|
{
|
|
|
|
struct iop_attach_args *ia;
|
|
|
|
char devinfo[256];
|
|
|
|
|
|
|
|
ia = aux;
|
|
|
|
|
|
|
|
if (pnp != NULL) {
|
|
|
|
iop_devinfo(ia->ia_class, devinfo);
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("%s at %s", devinfo, pnp);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal(" tid %d", ia->ia_tid);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
iop_submatch(struct device *parent, struct cfdata *cf, void *aux)
|
|
|
|
{
|
|
|
|
struct iop_attach_args *ia;
|
|
|
|
|
|
|
|
ia = aux;
|
|
|
|
|
|
|
|
if (cf->iopcf_tid != IOPCF_TID_DEFAULT && cf->iopcf_tid != ia->ia_tid)
|
|
|
|
return (0);
|
|
|
|
|
2002-09-27 07:17:40 +04:00
|
|
|
return (config_match(parent, cf, aux));
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shut down all configured IOPs.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_shutdown(void *junk)
|
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
|
|
|
int i;
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
printf("shutting down iop devices...");
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
for (i = 0; i < iop_cd.cd_ndevs; i++) {
|
|
|
|
if ((sc = device_lookup(&iop_cd, i)) == NULL)
|
|
|
|
continue;
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((sc->sc_flags & IOP_ONLINE) == 0)
|
|
|
|
continue;
|
2002-10-22 17:42:33 +04:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_SYS_QUIESCE, IOP_ICTX,
|
2001-03-21 17:27:05 +03:00
|
|
|
0, 5000);
|
2002-10-22 17:42:33 +04:00
|
|
|
|
|
|
|
if (le16toh(sc->sc_status.orgid) != I2O_ORG_AMI) {
|
|
|
|
/*
|
|
|
|
* Some AMI firmware revisions will go to sleep and
|
|
|
|
* never come back after this.
|
|
|
|
*/
|
|
|
|
iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_IOP_CLEAR,
|
|
|
|
IOP_ICTX, 0, 1000);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait. Some boards could still be flushing, stupidly enough. */
|
|
|
|
delay(5000*1000);
|
2001-09-22 03:44:19 +04:00
|
|
|
printf(" done\n");
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Retrieve IOP status.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2001-09-22 03:44:19 +04:00
|
|
|
int
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_status_get(struct iop_softc *sc, int nosleep)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_status_get mf;
|
2001-08-04 20:54:18 +04:00
|
|
|
struct i2o_status *st;
|
|
|
|
paddr_t pa;
|
2001-03-20 16:01:48 +03:00
|
|
|
int rv, i;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
pa = sc->sc_scr_seg->ds_addr;
|
|
|
|
st = (struct i2o_status *)sc->sc_scr;
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_exec_status_get);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_STATUS_GET);
|
|
|
|
mf.reserved[0] = 0;
|
|
|
|
mf.reserved[1] = 0;
|
|
|
|
mf.reserved[2] = 0;
|
|
|
|
mf.reserved[3] = 0;
|
2001-08-04 20:54:18 +04:00
|
|
|
mf.addrlow = (u_int32_t)pa;
|
|
|
|
mf.addrhigh = (u_int32_t)((u_int64_t)pa >> 32);
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.length = sizeof(sc->sc_status);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
memset(st, 0, sizeof(*st));
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*st),
|
|
|
|
BUS_DMASYNC_PREREAD);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((rv = iop_post(sc, (u_int32_t *)&mf)) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
for (i = 25; i != 0; i--) {
|
2001-08-04 20:54:18 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0,
|
|
|
|
sizeof(*st), BUS_DMASYNC_POSTREAD);
|
|
|
|
if (st->syncbyte == 0xff)
|
2001-03-20 16:01:48 +03:00
|
|
|
break;
|
|
|
|
if (nosleep)
|
|
|
|
DELAY(100*1000);
|
|
|
|
else
|
|
|
|
tsleep(iop_status_get, PWAIT, "iopstat", hz / 10);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2002-01-02 22:04:17 +03:00
|
|
|
if (st->syncbyte != 0xff) {
|
|
|
|
printf("%s: STATUS_GET timed out\n", sc->sc_dv.dv_xname);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = EIO;
|
2002-01-02 22:04:17 +03:00
|
|
|
} else {
|
2001-08-04 20:54:18 +04:00
|
|
|
memcpy(&sc->sc_status, st, sizeof(sc->sc_status));
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = 0;
|
2001-08-04 20:54:18 +04:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-09-18 22:15:49 +04:00
|
|
|
* Initialize and populate the IOP's outbound FIFO.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_ofifo_init(struct iop_softc *sc)
|
|
|
|
{
|
|
|
|
bus_addr_t addr;
|
2000-12-03 16:17:03 +03:00
|
|
|
bus_dma_segment_t seg;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_outbound_init *mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
int i, rseg, rv;
|
2001-08-04 20:54:18 +04:00
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)], *sw;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
sw = (u_int32_t *)sc->sc_scr;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf = (struct i2o_exec_outbound_init *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_exec_outbound_init);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_OUTBOUND_INIT);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
2001-08-04 20:54:18 +04:00
|
|
|
mf->msgtctx = 0;
|
2001-03-20 16:01:48 +03:00
|
|
|
mf->pagesize = PAGE_SIZE;
|
2001-09-27 22:43:37 +04:00
|
|
|
mf->flags = IOP_INIT_CODE | ((sc->sc_framesize >> 2) << 16);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/*
|
|
|
|
* The I2O spec says that there are two SGLs: one for the status
|
|
|
|
* word, and one for a list of discarded MFAs. It continues to say
|
|
|
|
* that if you don't want to get the list of MFAs, an IGNORE SGL is
|
2001-03-20 16:01:48 +03:00
|
|
|
* necessary; this isn't the case (and is in fact a bad thing).
|
2000-12-03 16:17:03 +03:00
|
|
|
*/
|
2001-08-04 20:54:18 +04:00
|
|
|
mb[sizeof(*mf) / sizeof(u_int32_t) + 0] = sizeof(*sw) |
|
|
|
|
I2O_SGL_SIMPLE | I2O_SGL_END_BUFFER | I2O_SGL_END;
|
|
|
|
mb[sizeof(*mf) / sizeof(u_int32_t) + 1] =
|
|
|
|
(u_int32_t)sc->sc_scr_seg->ds_addr;
|
|
|
|
mb[0] += 2 << 16;
|
|
|
|
|
|
|
|
*sw = 0;
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
if ((rv = iop_post(sc, mb)) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
POLL(5000,
|
|
|
|
(bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
|
|
|
|
BUS_DMASYNC_POSTREAD),
|
|
|
|
*sw == htole32(I2O_EXEC_OUTBOUND_INIT_COMPLETE)));
|
|
|
|
|
|
|
|
if (*sw != htole32(I2O_EXEC_OUTBOUND_INIT_COMPLETE)) {
|
|
|
|
printf("%s: outbound FIFO init failed (%d)\n",
|
|
|
|
sc->sc_dv.dv_xname, le32toh(*sw));
|
2000-12-03 16:17:03 +03:00
|
|
|
return (EIO);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Allocate DMA safe memory for the reply frames. */
|
2000-11-08 22:45:30 +03:00
|
|
|
if (sc->sc_rep_phys == 0) {
|
2001-09-27 22:43:37 +04:00
|
|
|
sc->sc_rep_size = sc->sc_maxob * sc->sc_framesize;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_rep_size, PAGE_SIZE,
|
|
|
|
0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
|
|
|
|
if (rv != 0) {
|
2003-05-03 22:10:37 +04:00
|
|
|
printf("%s: DMA alloc = %d\n", sc->sc_dv.dv_xname,
|
2000-12-03 16:17:03 +03:00
|
|
|
rv);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = bus_dmamem_map(sc->sc_dmat, &seg, rseg, sc->sc_rep_size,
|
|
|
|
&sc->sc_rep, BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
|
|
|
|
if (rv != 0) {
|
2003-05-03 22:10:37 +04:00
|
|
|
printf("%s: DMA map = %d\n", sc->sc_dv.dv_xname, rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = bus_dmamap_create(sc->sc_dmat, sc->sc_rep_size, 1,
|
|
|
|
sc->sc_rep_size, 0, BUS_DMA_NOWAIT, &sc->sc_rep_dmamap);
|
|
|
|
if (rv != 0) {
|
2003-05-03 22:10:37 +04:00
|
|
|
printf("%s: DMA create = %d\n", sc->sc_dv.dv_xname,
|
2001-08-04 20:54:18 +04:00
|
|
|
rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
rv = bus_dmamap_load(sc->sc_dmat, sc->sc_rep_dmamap,
|
|
|
|
sc->sc_rep, sc->sc_rep_size, NULL, BUS_DMA_NOWAIT);
|
2000-12-03 16:17:03 +03:00
|
|
|
if (rv != 0) {
|
2003-05-03 22:10:37 +04:00
|
|
|
printf("%s: DMA load = %d\n", sc->sc_dv.dv_xname, rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_rep_phys = sc->sc_rep_dmamap->dm_segs[0].ds_addr;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Populate the outbound FIFO. */
|
2001-03-20 16:01:48 +03:00
|
|
|
for (i = sc->sc_maxob, addr = sc->sc_rep_phys; i != 0; i--) {
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_OFIFO, (u_int32_t)addr);
|
2001-09-27 22:43:37 +04:00
|
|
|
addr += sc->sc_framesize;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the specified number of bytes from the IOP's hardware resource table.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_hrt_get0(struct iop_softc *sc, struct i2o_hrt *hrt, int size)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
int rv;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_hrt_get *mf;
|
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2001-03-20 16:01:48 +03:00
|
|
|
mf = (struct i2o_exec_hrt_get *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_exec_hrt_get);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_HRT_GET);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_msg_map(sc, im, mb, hrt, size, 0, NULL);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, mb, 30000);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_free(sc, im);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Read the IOP's hardware resource table.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_hrt_get(struct iop_softc *sc)
|
|
|
|
{
|
|
|
|
struct i2o_hrt hrthdr, *hrt;
|
|
|
|
int size, rv;
|
|
|
|
|
2003-01-19 00:21:28 +03:00
|
|
|
PHOLD(curlwp);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_hrt_get0(sc, &hrthdr, sizeof(hrthdr));
|
2003-01-19 00:21:28 +03:00
|
|
|
PRELE(curlwp);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rv != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
DPRINTF(("%s: %d hrt entries\n", sc->sc_dv.dv_xname,
|
|
|
|
le16toh(hrthdr.numentries)));
|
|
|
|
|
|
|
|
size = sizeof(struct i2o_hrt) +
|
2001-08-04 20:54:18 +04:00
|
|
|
(le16toh(hrthdr.numentries) - 1) * sizeof(struct i2o_hrt_entry);
|
2000-11-08 22:45:30 +03:00
|
|
|
hrt = (struct i2o_hrt *)malloc(size, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if ((rv = iop_hrt_get0(sc, hrt, size)) != 0) {
|
|
|
|
free(hrt, M_DEVBUF);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_hrt != NULL)
|
|
|
|
free(sc->sc_hrt, M_DEVBUF);
|
|
|
|
sc->sc_hrt = hrt;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request the specified number of bytes from the IOP's logical
|
2000-12-03 16:17:03 +03:00
|
|
|
* configuration table. If a change indicator is specified, this
|
2001-03-20 16:01:48 +03:00
|
|
|
* is a verbatim notification request, so the caller is prepared
|
2000-12-03 16:17:03 +03:00
|
|
|
* to wait indefinitely.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_lct_get0(struct iop_softc *sc, struct i2o_lct *lct, int size,
|
|
|
|
u_int32_t chgind)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_lct_notify *mf;
|
2000-11-08 22:45:30 +03:00
|
|
|
int rv;
|
2001-03-20 16:01:48 +03:00
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2000-11-08 22:45:30 +03:00
|
|
|
memset(lct, 0, size);
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf = (struct i2o_exec_lct_notify *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_exec_lct_notify);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_LCT_NOTIFY);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->classid = I2O_CLASS_ANY;
|
|
|
|
mf->changeindicator = chgind;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-01-04 00:04:01 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
printf("iop_lct_get0: reading LCT");
|
|
|
|
if (chgind != 0)
|
|
|
|
printf(" (async)");
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_msg_map(sc, im, mb, lct, size, 0, NULL);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, mb, (chgind == 0 ? 120*1000 : 0));
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_free(sc, im);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:34:37 +03:00
|
|
|
* Read the IOP's logical configuration table.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_lct_get(struct iop_softc *sc)
|
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
int esize, size, rv;
|
|
|
|
struct i2o_lct *lct;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
esize = le32toh(sc->sc_status.expectedlctsize);
|
|
|
|
lct = (struct i2o_lct *)malloc(esize, M_DEVBUF, M_WAITOK);
|
|
|
|
if (lct == NULL)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (ENOMEM);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((rv = iop_lct_get0(sc, lct, esize, 0)) != 0) {
|
2000-11-08 22:45:30 +03:00
|
|
|
free(lct, M_DEVBUF);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
size = le16toh(lct->tablesize) << 2;
|
|
|
|
if (esize != size) {
|
2000-11-08 22:45:30 +03:00
|
|
|
free(lct, M_DEVBUF);
|
2000-12-03 16:17:03 +03:00
|
|
|
lct = (struct i2o_lct *)malloc(size, M_DEVBUF, M_WAITOK);
|
|
|
|
if (lct == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
if ((rv = iop_lct_get0(sc, lct, size, 0)) != 0) {
|
|
|
|
free(lct, M_DEVBUF);
|
|
|
|
return (rv);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
/* Swap in the new LCT. */
|
2000-11-08 22:45:30 +03:00
|
|
|
if (sc->sc_lct != NULL)
|
|
|
|
free(sc->sc_lct, M_DEVBUF);
|
|
|
|
sc->sc_lct = lct;
|
|
|
|
sc->sc_nlctent = ((le16toh(sc->sc_lct->tablesize) << 2) -
|
|
|
|
sizeof(struct i2o_lct) + sizeof(struct i2o_lct_entry)) /
|
|
|
|
sizeof(struct i2o_lct_entry);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Request the specified parameter group from the target. If an initiator
|
|
|
|
* is specified (a) don't wait for the operation to complete, but instead
|
|
|
|
* let the initiator's interrupt handler deal with the reply and (b) place a
|
|
|
|
* pointer to the parameter group op in the wrapper's `im_dvcontext' field.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2001-08-22 13:42:05 +04:00
|
|
|
iop_field_get_all(struct iop_softc *sc, int tid, int group, void *buf,
|
|
|
|
int size, struct iop_initiator *ii)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_util_params_op *mf;
|
|
|
|
struct i2o_reply *rf;
|
2001-08-22 13:42:05 +04:00
|
|
|
int rv;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct iop_pgop *pgop;
|
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, (ii == NULL ? IM_WAIT : 0) | IM_NOSTATUS);
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((pgop = malloc(sizeof(*pgop), M_DEVBUF, M_WAITOK)) == NULL) {
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
if ((rf = malloc(sizeof(*rf), M_DEVBUF, M_WAITOK)) == NULL) {
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
free(pgop, M_DEVBUF);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
im->im_dvcontext = pgop;
|
|
|
|
im->im_rb = rf;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf = (struct i2o_util_params_op *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
|
2001-08-22 13:42:05 +04:00
|
|
|
mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_GET);
|
2001-03-20 16:01:48 +03:00
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->flags = 0;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
pgop->olh.count = htole16(1);
|
|
|
|
pgop->olh.reserved = htole16(0);
|
2001-08-22 13:42:05 +04:00
|
|
|
pgop->oat.operation = htole16(I2O_PARAMS_OP_FIELD_GET);
|
2001-03-20 16:01:48 +03:00
|
|
|
pgop->oat.fieldcount = htole16(0xffff);
|
|
|
|
pgop->oat.group = htole16(group);
|
|
|
|
|
|
|
|
if (ii == NULL)
|
2003-01-19 00:21:28 +03:00
|
|
|
PHOLD(curlwp);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
memset(buf, 0, size);
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_msg_map(sc, im, mb, pgop, sizeof(*pgop), 1, NULL);
|
2001-08-22 13:42:05 +04:00
|
|
|
iop_msg_map(sc, im, mb, buf, size, 0, NULL);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, mb, (ii == NULL ? 30000 : 0));
|
|
|
|
|
|
|
|
if (ii == NULL)
|
2003-01-19 00:21:28 +03:00
|
|
|
PRELE(curlwp);
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
/* Detect errors; let partial transfers to count as success. */
|
|
|
|
if (ii == NULL && rv == 0) {
|
|
|
|
if (rf->reqstatus == I2O_STATUS_ERROR_PARTIAL_XFER &&
|
|
|
|
le16toh(rf->detail) == I2O_DSC_UNKNOWN_ERROR)
|
|
|
|
rv = 0;
|
|
|
|
else
|
|
|
|
rv = (rf->reqstatus != 0 ? EIO : 0);
|
2001-08-22 13:42:05 +04:00
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
printf("%s: FIELD_GET failed for tid %d group %d\n",
|
|
|
|
sc->sc_dv.dv_xname, tid, group);
|
2001-03-20 16:01:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ii == NULL || rv != 0) {
|
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
free(pgop, M_DEVBUF);
|
|
|
|
free(rf, M_DEVBUF);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
return (rv);
|
2001-03-20 16:01:48 +03:00
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-22 13:42:05 +04:00
|
|
|
/*
|
|
|
|
* Set a single field in a scalar parameter group.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_field_set(struct iop_softc *sc, int tid, int group, void *buf,
|
|
|
|
int size, int field)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_params_op *mf;
|
|
|
|
struct iop_pgop *pgop;
|
|
|
|
int rv, totsize;
|
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
|
|
|
|
|
|
|
totsize = sizeof(*pgop) + size;
|
|
|
|
|
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
|
|
|
if ((pgop = malloc(totsize, M_DEVBUF, M_WAITOK)) == NULL) {
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
mf = (struct i2o_util_params_op *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->flags = 0;
|
|
|
|
|
|
|
|
pgop->olh.count = htole16(1);
|
|
|
|
pgop->olh.reserved = htole16(0);
|
|
|
|
pgop->oat.operation = htole16(I2O_PARAMS_OP_FIELD_SET);
|
|
|
|
pgop->oat.fieldcount = htole16(1);
|
|
|
|
pgop->oat.group = htole16(group);
|
|
|
|
pgop->oat.fields[0] = htole16(field);
|
|
|
|
memcpy(pgop + 1, buf, size);
|
|
|
|
|
|
|
|
iop_msg_map(sc, im, mb, pgop, totsize, 1, NULL);
|
|
|
|
rv = iop_msg_post(sc, im, mb, 30000);
|
|
|
|
if (rv != 0)
|
|
|
|
printf("%s: FIELD_SET failed for tid %d group %d\n",
|
|
|
|
sc->sc_dv.dv_xname, tid, group);
|
|
|
|
|
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
free(pgop, M_DEVBUF);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete all rows in a tablular parameter group.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_table_clear(struct iop_softc *sc, int tid, int group)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_params_op *mf;
|
|
|
|
struct iop_pgop pgop;
|
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
|
|
|
|
|
|
|
mf = (struct i2o_util_params_op *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->flags = 0;
|
|
|
|
|
|
|
|
pgop.olh.count = htole16(1);
|
|
|
|
pgop.olh.reserved = htole16(0);
|
|
|
|
pgop.oat.operation = htole16(I2O_PARAMS_OP_TABLE_CLEAR);
|
|
|
|
pgop.oat.fieldcount = htole16(0);
|
|
|
|
pgop.oat.group = htole16(group);
|
|
|
|
pgop.oat.fields[0] = htole16(0);
|
|
|
|
|
2003-01-19 00:21:28 +03:00
|
|
|
PHOLD(curlwp);
|
2001-08-22 13:42:05 +04:00
|
|
|
iop_msg_map(sc, im, mb, &pgop, sizeof(pgop), 1, NULL);
|
|
|
|
rv = iop_msg_post(sc, im, mb, 30000);
|
|
|
|
if (rv != 0)
|
|
|
|
printf("%s: TABLE_CLEAR failed for tid %d group %d\n",
|
|
|
|
sc->sc_dv.dv_xname, tid, group);
|
|
|
|
|
|
|
|
iop_msg_unmap(sc, im);
|
2003-01-19 00:21:28 +03:00
|
|
|
PRELE(curlwp);
|
2001-08-22 13:42:05 +04:00
|
|
|
iop_msg_free(sc, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a single row to a tabular parameter group. The row can have only one
|
|
|
|
* field.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_table_add_row(struct iop_softc *sc, int tid, int group, void *buf,
|
|
|
|
int size, int row)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_params_op *mf;
|
|
|
|
struct iop_pgop *pgop;
|
|
|
|
int rv, totsize;
|
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
|
|
|
|
|
|
|
totsize = sizeof(*pgop) + sizeof(u_int16_t) * 2 + size;
|
|
|
|
|
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
|
|
|
if ((pgop = malloc(totsize, M_DEVBUF, M_WAITOK)) == NULL) {
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
mf = (struct i2o_util_params_op *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(tid, I2O_UTIL_PARAMS_SET);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->flags = 0;
|
|
|
|
|
|
|
|
pgop->olh.count = htole16(1);
|
|
|
|
pgop->olh.reserved = htole16(0);
|
|
|
|
pgop->oat.operation = htole16(I2O_PARAMS_OP_ROW_ADD);
|
|
|
|
pgop->oat.fieldcount = htole16(1);
|
|
|
|
pgop->oat.group = htole16(group);
|
|
|
|
pgop->oat.fields[0] = htole16(0); /* FieldIdx */
|
|
|
|
pgop->oat.fields[1] = htole16(1); /* RowCount */
|
|
|
|
pgop->oat.fields[2] = htole16(row); /* KeyValue */
|
|
|
|
memcpy(&pgop->oat.fields[3], buf, size);
|
|
|
|
|
|
|
|
iop_msg_map(sc, im, mb, pgop, totsize, 1, NULL);
|
|
|
|
rv = iop_msg_post(sc, im, mb, 30000);
|
|
|
|
if (rv != 0)
|
|
|
|
printf("%s: ADD_ROW failed for tid %d group %d row %d\n",
|
|
|
|
sc->sc_dv.dv_xname, tid, group, row);
|
|
|
|
|
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
free(pgop, M_DEVBUF);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Execute a simple command (no parameters).
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_simple_cmd(struct iop_softc *sc, int tid, int function, int ictx,
|
|
|
|
int async, int timo)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_msg mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
int rv, fl;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
fl = (async != 0 ? IM_WAIT : IM_POLL);
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, fl);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_msg);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(tid, function);
|
|
|
|
mf.msgictx = ictx;
|
|
|
|
mf.msgtctx = im->im_tctx;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, &mf, timo);
|
|
|
|
iop_msg_free(sc, im);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Post the system table to the IOP.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_systab_set(struct iop_softc *sc)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_sys_tab_set *mf;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct iop_msg *im;
|
2001-04-01 19:02:08 +04:00
|
|
|
bus_space_handle_t bsh;
|
|
|
|
bus_addr_t boo;
|
2000-11-08 22:45:30 +03:00
|
|
|
u_int32_t mema[2], ioa[2];
|
|
|
|
int rv;
|
2001-03-20 16:01:48 +03:00
|
|
|
u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf = (struct i2o_exec_sys_tab_set *)mb;
|
|
|
|
mf->msgflags = I2O_MSGFLAGS(i2o_exec_sys_tab_set);
|
|
|
|
mf->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_SYS_TAB_SET);
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
mf->iopid = (sc->sc_dv.dv_unit + 2) << 12;
|
|
|
|
mf->segnumber = 0;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-04-01 19:02:08 +04:00
|
|
|
mema[1] = sc->sc_status.desiredprivmemsize;
|
|
|
|
ioa[1] = sc->sc_status.desiredpriviosize;
|
|
|
|
|
|
|
|
if (mema[1] != 0) {
|
|
|
|
rv = bus_space_alloc(sc->sc_bus_memt, 0, 0xffffffff,
|
|
|
|
le32toh(mema[1]), PAGE_SIZE, 0, 0, &boo, &bsh);
|
|
|
|
mema[0] = htole32(boo);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: can't alloc priv mem space, err = %d\n",
|
|
|
|
sc->sc_dv.dv_xname, rv);
|
|
|
|
mema[0] = 0;
|
|
|
|
mema[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioa[1] != 0) {
|
|
|
|
rv = bus_space_alloc(sc->sc_bus_iot, 0, 0xffff,
|
|
|
|
le32toh(ioa[1]), 0, 0, 0, &boo, &bsh);
|
|
|
|
ioa[0] = htole32(boo);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: can't alloc priv i/o space, err = %d\n",
|
|
|
|
sc->sc_dv.dv_xname, rv);
|
|
|
|
ioa[0] = 0;
|
|
|
|
ioa[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2003-01-19 00:21:28 +03:00
|
|
|
PHOLD(curlwp);
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_msg_map(sc, im, mb, iop_systab, iop_systab_size, 1, NULL);
|
|
|
|
iop_msg_map(sc, im, mb, mema, sizeof(mema), 1, NULL);
|
|
|
|
iop_msg_map(sc, im, mb, ioa, sizeof(ioa), 1, NULL);
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, mb, 5000);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_free(sc, im);
|
2003-01-19 00:21:28 +03:00
|
|
|
PRELE(curlwp);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Reset the IOP. Must be called with interrupts disabled.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_reset(struct iop_softc *sc)
|
|
|
|
{
|
2001-08-04 20:54:18 +04:00
|
|
|
u_int32_t mfa, *sw;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_exec_iop_reset mf;
|
2000-11-08 22:45:30 +03:00
|
|
|
int rv;
|
2001-08-04 20:54:18 +04:00
|
|
|
paddr_t pa;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
sw = (u_int32_t *)sc->sc_scr;
|
|
|
|
pa = sc->sc_scr_seg->ds_addr;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_exec_iop_reset);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_IOP_RESET);
|
|
|
|
mf.reserved[0] = 0;
|
|
|
|
mf.reserved[1] = 0;
|
|
|
|
mf.reserved[2] = 0;
|
|
|
|
mf.reserved[3] = 0;
|
2001-08-04 20:54:18 +04:00
|
|
|
mf.statuslow = (u_int32_t)pa;
|
|
|
|
mf.statushigh = (u_int32_t)((u_int64_t)pa >> 32);
|
|
|
|
|
|
|
|
*sw = htole32(0);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
|
|
|
|
BUS_DMASYNC_PREREAD);
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
if ((rv = iop_post(sc, (u_int32_t *)&mf)))
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
POLL(2500,
|
|
|
|
(bus_dmamap_sync(sc->sc_dmat, sc->sc_scr_dmamap, 0, sizeof(*sw),
|
|
|
|
BUS_DMASYNC_POSTREAD), *sw != 0));
|
|
|
|
if (*sw != htole32(I2O_RESET_IN_PROGRESS)) {
|
|
|
|
printf("%s: reset rejected, status 0x%x\n",
|
|
|
|
sc->sc_dv.dv_xname, le32toh(*sw));
|
2000-11-08 22:45:30 +03:00
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* IOP is now in the INIT state. Wait no more than 10 seconds for
|
2000-11-08 22:45:30 +03:00
|
|
|
* the inbound queue to become responsive.
|
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
POLL(10000, (mfa = iop_inl(sc, IOP_REG_IFIFO)) != IOP_MFA_EMPTY);
|
2000-11-08 22:45:30 +03:00
|
|
|
if (mfa == IOP_MFA_EMPTY) {
|
|
|
|
printf("%s: reset failed\n", sc->sc_dv.dv_xname);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
iop_release_mfa(sc, mfa);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Register a new initiator. Must be called with the configuration lock
|
|
|
|
* held.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2001-03-20 16:01:48 +03:00
|
|
|
void
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_initiator_register(struct iop_softc *sc, struct iop_initiator *ii)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
static int ictxgen;
|
|
|
|
int s;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* 0 is reserved (by us) for system messages. */
|
|
|
|
ii->ii_ictx = ++ictxgen;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* `Utility initiators' don't make it onto the per-IOP initiator list
|
|
|
|
* (which is used only for configuration), but do get one slot on
|
|
|
|
* the inbound queue.
|
|
|
|
*/
|
|
|
|
if ((ii->ii_flags & II_UTILITY) == 0) {
|
|
|
|
LIST_INSERT_HEAD(&sc->sc_iilist, ii, ii_list);
|
|
|
|
sc->sc_nii++;
|
|
|
|
} else
|
|
|
|
sc->sc_nuii++;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
s = splbio();
|
|
|
|
LIST_INSERT_HEAD(IOP_ICTXHASH(ii->ii_ictx), ii, ii_hash);
|
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Unregister an initiator. Must be called with the configuration lock
|
|
|
|
* held.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
iop_initiator_unregister(struct iop_softc *sc, struct iop_initiator *ii)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
int s;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((ii->ii_flags & II_UTILITY) == 0) {
|
|
|
|
LIST_REMOVE(ii, ii_list);
|
|
|
|
sc->sc_nii--;
|
|
|
|
} else
|
|
|
|
sc->sc_nuii--;
|
|
|
|
|
|
|
|
s = splbio();
|
2000-12-03 16:17:03 +03:00
|
|
|
LIST_REMOVE(ii, ii_hash);
|
2001-03-20 16:01:48 +03:00
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Handle a reply frame from the IOP.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_handle_reply(struct iop_softc *sc, u_int32_t rmfa)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_reply *rb;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_fault_notify *fn;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct iop_initiator *ii;
|
2000-12-03 16:17:03 +03:00
|
|
|
u_int off, ictx, tctx, status, size;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
off = (int)(rmfa - sc->sc_rep_phys);
|
|
|
|
rb = (struct i2o_reply *)(sc->sc_rep + off);
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
/* Perform reply queue DMA synchronisation. */
|
2001-03-20 16:01:48 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, off,
|
2001-09-27 22:43:37 +04:00
|
|
|
sc->sc_framesize, BUS_DMASYNC_POSTREAD);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (--sc->sc_curib != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap,
|
|
|
|
0, sc->sc_rep_size, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((le32toh(rb->msgflags) & I2O_MSGFLAGS_64BIT) != 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
panic("iop_handle_reply: 64-bit reply");
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Find the initiator.
|
|
|
|
*/
|
|
|
|
ictx = le32toh(rb->msgictx);
|
|
|
|
if (ictx == IOP_ICTX)
|
|
|
|
ii = NULL;
|
|
|
|
else {
|
2000-12-03 16:17:03 +03:00
|
|
|
ii = LIST_FIRST(IOP_ICTXHASH(ictx));
|
|
|
|
for (; ii != NULL; ii = LIST_NEXT(ii, ii_hash))
|
|
|
|
if (ii->ii_ictx == ictx)
|
|
|
|
break;
|
|
|
|
if (ii == NULL) {
|
2000-11-08 22:45:30 +03:00
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_reply_print(sc, rb);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
2001-03-20 16:01:48 +03:00
|
|
|
printf("%s: WARNING: bad ictx returned (%x)\n",
|
2000-12-03 16:17:03 +03:00
|
|
|
sc->sc_dv.dv_xname, ictx);
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
2001-06-12 19:17:10 +04:00
|
|
|
* If we received a transport failure notice, we've got to dig the
|
2001-03-20 16:01:48 +03:00
|
|
|
* transaction context (if any) out of the original message frame,
|
|
|
|
* and then release the original MFA back to the inbound FIFO.
|
|
|
|
*/
|
|
|
|
if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0) {
|
|
|
|
status = I2O_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
fn = (struct i2o_fault_notify *)rb;
|
2002-11-08 08:47:35 +03:00
|
|
|
tctx = iop_inl_msg(sc, fn->lowmfa + 12);
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_release_mfa(sc, fn->lowmfa);
|
|
|
|
iop_tfn_print(sc, fn);
|
|
|
|
} else {
|
|
|
|
status = rb->reqstatus;
|
|
|
|
tctx = le32toh(rb->msgtctx);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
if (ii == NULL || (ii->ii_flags & II_NOTCTX) == 0) {
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
|
|
|
* This initiator tracks state using message wrappers.
|
|
|
|
*
|
|
|
|
* Find the originating message wrapper, and if requested
|
|
|
|
* notify the initiator.
|
|
|
|
*/
|
2001-03-20 16:01:48 +03:00
|
|
|
im = sc->sc_ims + (tctx & IOP_TCTX_MASK);
|
|
|
|
if ((tctx & IOP_TCTX_MASK) > sc->sc_maxib ||
|
|
|
|
(im->im_flags & IM_ALLOCED) == 0 ||
|
|
|
|
tctx != im->im_tctx) {
|
|
|
|
printf("%s: WARNING: bad tctx returned (0x%08x, %p)\n",
|
|
|
|
sc->sc_dv.dv_xname, tctx, im);
|
|
|
|
if (im != NULL)
|
|
|
|
printf("%s: flags=0x%08x tctx=0x%08x\n",
|
|
|
|
sc->sc_dv.dv_xname, im->im_flags,
|
|
|
|
im->im_tctx);
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((rb->msgflags & I2O_MSGFLAGS_FAIL) == 0)
|
|
|
|
iop_reply_print(sc, rb);
|
2000-12-03 16:17:03 +03:00
|
|
|
#endif
|
|
|
|
return (-1);
|
|
|
|
}
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
|
|
|
|
im->im_flags |= IM_FAIL;
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((im->im_flags & IM_REPLIED) != 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
panic("%s: dup reply", sc->sc_dv.dv_xname);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
im->im_flags |= IM_REPLIED;
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
if (status != I2O_STATUS_SUCCESS)
|
|
|
|
iop_reply_print(sc, rb);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
2001-03-20 16:01:48 +03:00
|
|
|
im->im_reqstatus = status;
|
|
|
|
|
|
|
|
/* Copy the reply frame, if requested. */
|
|
|
|
if (im->im_rb != NULL) {
|
2000-12-03 16:17:03 +03:00
|
|
|
size = (le32toh(rb->msgflags) >> 14) & ~3;
|
2001-03-20 16:01:48 +03:00
|
|
|
#ifdef I2ODEBUG
|
2001-09-27 22:43:37 +04:00
|
|
|
if (size > sc->sc_framesize)
|
2001-03-20 16:01:48 +03:00
|
|
|
panic("iop_handle_reply: reply too large");
|
|
|
|
#endif
|
|
|
|
memcpy(im->im_rb, rb, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify the initiator. */
|
|
|
|
if ((im->im_flags & IM_WAIT) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
wakeup(im);
|
2001-04-01 19:02:08 +04:00
|
|
|
else if ((im->im_flags & (IM_POLL | IM_POLL_INTR)) != IM_POLL)
|
2000-11-08 22:45:30 +03:00
|
|
|
(*ii->ii_intr)(ii->ii_dv, im, rb);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This initiator discards message wrappers.
|
|
|
|
*
|
|
|
|
* Simply pass the reply frame to the initiator.
|
|
|
|
*/
|
|
|
|
(*ii->ii_intr)(ii->ii_dv, NULL, rb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Handle an interrupt from the IOP.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
2000-12-03 16:17:03 +03:00
|
|
|
u_int32_t rmfa;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((iop_inl(sc, IOP_REG_INTR_STATUS) & IOP_INTR_OFIFO) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* Double read to account for IOP bug. */
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((rmfa = iop_inl(sc, IOP_REG_OFIFO)) == IOP_MFA_EMPTY) {
|
|
|
|
rmfa = iop_inl(sc, IOP_REG_OFIFO);
|
|
|
|
if (rmfa == IOP_MFA_EMPTY)
|
|
|
|
break;
|
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_handle_reply(sc, rmfa);
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_outl(sc, IOP_REG_OFIFO, rmfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an event signalled by the executive.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_intr_event(struct device *dv, struct iop_msg *im, void *reply)
|
|
|
|
{
|
|
|
|
struct i2o_util_event_register_reply *rb;
|
|
|
|
struct iop_softc *sc;
|
|
|
|
u_int event;
|
|
|
|
|
|
|
|
sc = (struct iop_softc *)dv;
|
|
|
|
rb = reply;
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
return;
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
event = le32toh(rb->event);
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: event 0x%08x received\n", dv->dv_xname, event);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a message wrapper.
|
|
|
|
*/
|
2001-03-20 16:01:48 +03:00
|
|
|
struct iop_msg *
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_msg_alloc(struct iop_softc *sc, int flags)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
static u_int tctxgen;
|
|
|
|
int s, i;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((flags & IM_SYSMASK) != 0)
|
|
|
|
panic("iop_msg_alloc: system flags specified");
|
|
|
|
#endif
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
s = splbio();
|
2001-03-20 16:01:48 +03:00
|
|
|
im = SLIST_FIRST(&sc->sc_im_freelist);
|
|
|
|
#if defined(DIAGNOSTIC) || defined(I2ODEBUG)
|
|
|
|
if (im == NULL)
|
|
|
|
panic("iop_msg_alloc: no free wrappers");
|
|
|
|
#endif
|
|
|
|
SLIST_REMOVE_HEAD(&sc->sc_im_freelist, im_chain);
|
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
im->im_tctx = (im->im_tctx & IOP_TCTX_MASK) | tctxgen;
|
|
|
|
tctxgen += (1 << IOP_TCTX_SHIFT);
|
2000-11-08 22:45:30 +03:00
|
|
|
im->im_flags = flags | IM_ALLOCED;
|
2001-03-20 16:01:48 +03:00
|
|
|
im->im_rb = NULL;
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
im->im_xfer[i++].ix_size = 0;
|
|
|
|
} while (i < IOP_MAX_MSG_XFERS);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
return (im);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a message wrapper.
|
|
|
|
*/
|
|
|
|
void
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_free(struct iop_softc *sc, struct iop_msg *im)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((im->im_flags & IM_ALLOCED) == 0)
|
|
|
|
panic("iop_msg_free: wrapper not allocated");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
im->im_flags = 0;
|
2001-03-20 16:01:48 +03:00
|
|
|
s = splbio();
|
|
|
|
SLIST_INSERT_HEAD(&sc->sc_im_freelist, im, im_chain);
|
2000-11-08 22:45:30 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Map a data transfer. Write a scatter-gather list into the message frame.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_map(struct iop_softc *sc, struct iop_msg *im, u_int32_t *mb,
|
2001-08-04 20:54:18 +04:00
|
|
|
void *xferaddr, int xfersize, int out, struct proc *up)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
bus_dmamap_t dm;
|
|
|
|
bus_dma_segment_t *ds;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct iop_xfer *ix;
|
2001-03-20 16:01:48 +03:00
|
|
|
u_int rv, i, nsegs, flg, off, xn;
|
|
|
|
u_int32_t *p;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
for (xn = 0, ix = im->im_xfer; xn < IOP_MAX_MSG_XFERS; xn++, ix++)
|
2000-11-08 22:45:30 +03:00
|
|
|
if (ix->ix_size == 0)
|
|
|
|
break;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
if (xfersize == 0)
|
|
|
|
panic("iop_msg_map: null transfer");
|
|
|
|
if (xfersize > IOP_MAX_XFER)
|
|
|
|
panic("iop_msg_map: transfer too large");
|
|
|
|
if (xn == IOP_MAX_MSG_XFERS)
|
2000-11-08 22:45:30 +03:00
|
|
|
panic("iop_msg_map: too many xfers");
|
|
|
|
#endif
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Only the first DMA map is static.
|
|
|
|
*/
|
|
|
|
if (xn != 0) {
|
2000-11-08 22:45:30 +03:00
|
|
|
rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
|
2001-03-20 16:01:48 +03:00
|
|
|
IOP_MAX_SEGS, IOP_MAX_XFER, 0,
|
2000-11-08 22:45:30 +03:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ix->ix_map);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
dm = ix->ix_map;
|
2001-08-04 20:54:18 +04:00
|
|
|
rv = bus_dmamap_load(sc->sc_dmat, dm, xferaddr, xfersize, up,
|
|
|
|
(up == NULL ? BUS_DMA_NOWAIT : 0));
|
2000-11-08 22:45:30 +03:00
|
|
|
if (rv != 0)
|
2001-03-20 16:01:48 +03:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* How many SIMPLE SG elements can we fit in this message?
|
|
|
|
*/
|
|
|
|
off = mb[0] >> 16;
|
|
|
|
p = mb + off;
|
2001-09-27 22:43:37 +04:00
|
|
|
nsegs = ((sc->sc_framesize >> 2) - off) >> 1;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
if (dm->dm_nsegs > nsegs) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ix->ix_map);
|
|
|
|
rv = EFBIG;
|
|
|
|
DPRINTF(("iop_msg_map: too many segs\n"));
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsegs = dm->dm_nsegs;
|
|
|
|
xfersize = 0;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Write out the SG list.
|
|
|
|
*/
|
2000-11-08 22:45:30 +03:00
|
|
|
if (out)
|
2001-03-20 16:01:48 +03:00
|
|
|
flg = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;
|
2000-11-08 22:45:30 +03:00
|
|
|
else
|
2001-03-20 16:01:48 +03:00
|
|
|
flg = I2O_SGL_SIMPLE;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
for (i = nsegs, ds = dm->dm_segs; i > 1; i--, p += 2, ds++) {
|
|
|
|
p[0] = (u_int32_t)ds->ds_len | flg;
|
|
|
|
p[1] = (u_int32_t)ds->ds_addr;
|
|
|
|
xfersize += ds->ds_len;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
p[0] = (u_int32_t)ds->ds_len | flg | I2O_SGL_END_BUFFER;
|
|
|
|
p[1] = (u_int32_t)ds->ds_addr;
|
|
|
|
xfersize += ds->ds_len;
|
|
|
|
|
|
|
|
/* Fix up the transfer record, and sync the map. */
|
|
|
|
ix->ix_flags = (out ? IX_OUT : IX_IN);
|
|
|
|
ix->ix_size = xfersize;
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, xfersize,
|
|
|
|
out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
|
|
|
* If this is the first xfer we've mapped for this message, adjust
|
|
|
|
* the SGL offset field in the message header.
|
|
|
|
*/
|
2000-11-09 15:51:36 +03:00
|
|
|
if ((im->im_flags & IM_SGLOFFADJ) == 0) {
|
2001-03-20 16:01:48 +03:00
|
|
|
mb[0] += (mb[0] >> 12) & 0xf0;
|
2000-11-09 15:51:36 +03:00
|
|
|
im->im_flags |= IM_SGLOFFADJ;
|
|
|
|
}
|
2001-03-20 16:01:48 +03:00
|
|
|
mb[0] += (nsegs << 17);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (0);
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
bad:
|
|
|
|
if (xn != 0)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, ix->ix_map);
|
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Map a block I/O data transfer (different in that there's only one per
|
|
|
|
* message maximum, and PAGE addressing may be used). Write a scatter
|
|
|
|
* gather list into the message frame.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_msg_map_bio(struct iop_softc *sc, struct iop_msg *im, u_int32_t *mb,
|
|
|
|
void *xferaddr, int xfersize, int out)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
bus_dma_segment_t *ds;
|
|
|
|
bus_dmamap_t dm;
|
|
|
|
struct iop_xfer *ix;
|
|
|
|
u_int rv, i, nsegs, off, slen, tlen, flg;
|
|
|
|
paddr_t saddr, eaddr;
|
|
|
|
u_int32_t *p;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
2001-03-20 16:01:48 +03:00
|
|
|
if (xfersize == 0)
|
|
|
|
panic("iop_msg_map_bio: null transfer");
|
|
|
|
if (xfersize > IOP_MAX_XFER)
|
|
|
|
panic("iop_msg_map_bio: transfer too large");
|
|
|
|
if ((im->im_flags & IM_SGLOFFADJ) != 0)
|
|
|
|
panic("iop_msg_map_bio: SGLOFFADJ");
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
ix = im->im_xfer;
|
|
|
|
dm = ix->ix_map;
|
2001-08-04 20:54:18 +04:00
|
|
|
rv = bus_dmamap_load(sc->sc_dmat, dm, xferaddr, xfersize, NULL,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_STREAMING);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
off = mb[0] >> 16;
|
2001-09-27 22:43:37 +04:00
|
|
|
nsegs = ((sc->sc_framesize >> 2) - off) >> 1;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the transfer is highly fragmented and won't fit using SIMPLE
|
|
|
|
* elements, use PAGE_LIST elements instead. SIMPLE elements are
|
|
|
|
* potentially more efficient, both for us and the IOP.
|
|
|
|
*/
|
|
|
|
if (dm->dm_nsegs > nsegs) {
|
|
|
|
nsegs = 1;
|
|
|
|
p = mb + off + 1;
|
|
|
|
|
|
|
|
/* XXX This should be done with a bus_space flag. */
|
|
|
|
for (i = dm->dm_nsegs, ds = dm->dm_segs; i > 0; i--, ds++) {
|
|
|
|
slen = ds->ds_len;
|
|
|
|
saddr = ds->ds_addr;
|
|
|
|
|
|
|
|
while (slen > 0) {
|
|
|
|
eaddr = (saddr + PAGE_SIZE) & ~(PAGE_SIZE - 1);
|
|
|
|
tlen = min(eaddr - saddr, slen);
|
|
|
|
slen -= tlen;
|
|
|
|
*p++ = le32toh(saddr);
|
|
|
|
saddr = eaddr;
|
|
|
|
nsegs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mb[off] = xfersize | I2O_SGL_PAGE_LIST | I2O_SGL_END_BUFFER |
|
|
|
|
I2O_SGL_END;
|
|
|
|
if (out)
|
|
|
|
mb[off] |= I2O_SGL_DATA_OUT;
|
|
|
|
} else {
|
|
|
|
p = mb + off;
|
2001-04-01 19:02:08 +04:00
|
|
|
nsegs = dm->dm_nsegs;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
if (out)
|
|
|
|
flg = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;
|
|
|
|
else
|
|
|
|
flg = I2O_SGL_SIMPLE;
|
|
|
|
|
|
|
|
for (i = nsegs, ds = dm->dm_segs; i > 1; i--, p += 2, ds++) {
|
|
|
|
p[0] = (u_int32_t)ds->ds_len | flg;
|
|
|
|
p[1] = (u_int32_t)ds->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
p[0] = (u_int32_t)ds->ds_len | flg | I2O_SGL_END_BUFFER |
|
|
|
|
I2O_SGL_END;
|
|
|
|
p[1] = (u_int32_t)ds->ds_addr;
|
|
|
|
nsegs <<= 1;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Fix up the transfer record, and sync the map. */
|
|
|
|
ix->ix_flags = (out ? IX_OUT : IX_IN);
|
|
|
|
ix->ix_size = xfersize;
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, xfersize,
|
|
|
|
out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the SGL offset and total message size fields. We don't
|
|
|
|
* set IM_SGLOFFADJ, since it's used only for SIMPLE elements.
|
|
|
|
*/
|
|
|
|
mb[0] += ((off << 4) + (nsegs << 16));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmap all data transfers associated with a message wrapper.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iop_msg_unmap(struct iop_softc *sc, struct iop_msg *im)
|
|
|
|
{
|
|
|
|
struct iop_xfer *ix;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (im->im_xfer[0].ix_size == 0)
|
|
|
|
panic("iop_msg_unmap: no transfers mapped");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (ix = im->im_xfer, i = 0;;) {
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, ix->ix_size,
|
|
|
|
ix->ix_flags & IX_OUT ? BUS_DMASYNC_POSTWRITE :
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ix->ix_map);
|
|
|
|
|
|
|
|
/* Only the first DMA map is static. */
|
|
|
|
if (i != 0)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, ix->ix_map);
|
|
|
|
if ((++ix)->ix_size == 0)
|
|
|
|
break;
|
|
|
|
if (++i >= IOP_MAX_MSG_XFERS)
|
|
|
|
break;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
2001-03-20 16:01:48 +03:00
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Post a message frame to the IOP's inbound queue.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_post(struct iop_softc *sc, u_int32_t *mb)
|
|
|
|
{
|
|
|
|
u_int32_t mfa;
|
|
|
|
int s;
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
#ifdef I2ODEBUG
|
2001-09-27 22:43:37 +04:00
|
|
|
if ((mb[0] >> 16) > (sc->sc_framesize >> 2))
|
2001-04-01 19:02:08 +04:00
|
|
|
panic("iop_post: frame too large");
|
2001-08-04 20:54:18 +04:00
|
|
|
#endif
|
2001-04-01 19:02:08 +04:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
s = splbio();
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
/* Allocate a slot with the IOP. */
|
|
|
|
if ((mfa = iop_inl(sc, IOP_REG_IFIFO)) == IOP_MFA_EMPTY)
|
|
|
|
if ((mfa = iop_inl(sc, IOP_REG_IFIFO)) == IOP_MFA_EMPTY) {
|
|
|
|
splx(s);
|
|
|
|
printf("%s: mfa not forthcoming\n",
|
|
|
|
sc->sc_dv.dv_xname);
|
|
|
|
return (EAGAIN);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
/* Perform reply buffer DMA synchronisation. */
|
2001-03-20 16:01:48 +03:00
|
|
|
if (sc->sc_curib++ == 0)
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, 0,
|
|
|
|
sc->sc_rep_size, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
/* Copy out the message frame. */
|
2002-11-15 16:51:29 +03:00
|
|
|
bus_space_write_region_4(sc->sc_msg_iot, sc->sc_msg_ioh, mfa, mb,
|
2002-11-08 08:47:35 +03:00
|
|
|
mb[0] >> 16);
|
2002-11-15 16:51:29 +03:00
|
|
|
bus_space_barrier(sc->sc_msg_iot, sc->sc_msg_ioh, mfa,
|
2002-11-08 08:47:35 +03:00
|
|
|
(mb[0] >> 14) & ~3, BUS_SPACE_BARRIER_WRITE);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* Post the MFA back to the IOP. */
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_IFIFO, mfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Post a message to the IOP and deal with completion.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_msg_post(struct iop_softc *sc, struct iop_msg *im, void *xmb, int timo)
|
|
|
|
{
|
|
|
|
u_int32_t *mb;
|
|
|
|
int rv, s;
|
|
|
|
|
|
|
|
mb = xmb;
|
|
|
|
|
|
|
|
/* Terminate the scatter/gather list chain. */
|
|
|
|
if ((im->im_flags & IM_SGLOFFADJ) != 0)
|
|
|
|
mb[(mb[0] >> 16) - 2] |= I2O_SGL_END;
|
|
|
|
|
|
|
|
if ((rv = iop_post(sc, mb)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
if ((im->im_flags & (IM_POLL | IM_WAIT)) != 0) {
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((im->im_flags & IM_POLL) != 0)
|
|
|
|
iop_msg_poll(sc, im, timo);
|
|
|
|
else
|
|
|
|
iop_msg_wait(sc, im, timo);
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
if ((im->im_flags & IM_REPLIED) != 0) {
|
|
|
|
if ((im->im_flags & IM_NOSTATUS) != 0)
|
|
|
|
rv = 0;
|
|
|
|
else if ((im->im_flags & IM_FAIL) != 0)
|
|
|
|
rv = ENXIO;
|
|
|
|
else if (im->im_reqstatus != I2O_STATUS_SUCCESS)
|
|
|
|
rv = EIO;
|
|
|
|
else
|
|
|
|
rv = 0;
|
|
|
|
} else
|
|
|
|
rv = EBUSY;
|
2000-11-09 15:51:36 +03:00
|
|
|
splx(s);
|
2001-03-20 16:01:48 +03:00
|
|
|
} else
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Spin until the specified message is replied to.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_msg_poll(struct iop_softc *sc, struct iop_msg *im, int timo)
|
|
|
|
{
|
|
|
|
u_int32_t rmfa;
|
2003-01-20 07:25:46 +03:00
|
|
|
int s;
|
2001-03-20 16:01:48 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
s = splbio();
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* Wait for completion. */
|
|
|
|
for (timo *= 10; timo != 0; timo--) {
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((iop_inl(sc, IOP_REG_INTR_STATUS) & IOP_INTR_OFIFO) != 0) {
|
|
|
|
/* Double read to account for IOP bug. */
|
|
|
|
rmfa = iop_inl(sc, IOP_REG_OFIFO);
|
|
|
|
if (rmfa == IOP_MFA_EMPTY)
|
|
|
|
rmfa = iop_inl(sc, IOP_REG_OFIFO);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rmfa != IOP_MFA_EMPTY) {
|
2003-01-20 07:25:46 +03:00
|
|
|
iop_handle_reply(sc, rmfa);
|
2001-03-20 16:01:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the reply frame to the IOP's
|
|
|
|
* outbound FIFO.
|
|
|
|
*/
|
|
|
|
iop_outl(sc, IOP_REG_OFIFO, rmfa);
|
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
if ((im->im_flags & IM_REPLIED) != 0)
|
|
|
|
break;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timo == 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
printf("%s: poll - no reply\n", sc->sc_dv.dv_xname);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (iop_status_get(sc, 1) != 0)
|
|
|
|
printf("iop_msg_poll: unable to retrieve status\n");
|
2000-12-03 16:17:03 +03:00
|
|
|
else
|
2001-03-20 16:01:48 +03:00
|
|
|
printf("iop_msg_poll: IOP state = %d\n",
|
2000-12-03 16:17:03 +03:00
|
|
|
(le32toh(sc->sc_status.segnumber) >> 16) & 0xff);
|
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Sleep until the specified message is replied to.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2001-03-20 16:01:48 +03:00
|
|
|
static void
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_wait(struct iop_softc *sc, struct iop_msg *im, int timo)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
int s, rv;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
s = splbio();
|
|
|
|
if ((im->im_flags & IM_REPLIED) != 0) {
|
|
|
|
splx(s);
|
2001-03-20 16:01:48 +03:00
|
|
|
return;
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
2002-04-05 22:27:45 +04:00
|
|
|
rv = tsleep(im, PRIBIO, "iopmsg", mstohz(timo));
|
2000-12-03 16:17:03 +03:00
|
|
|
splx(s);
|
2001-03-20 16:01:48 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("iop_msg_wait: tsleep() == %d\n", rv);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (iop_status_get(sc, 0) != 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("iop_msg_wait: unable to retrieve status\n");
|
|
|
|
else
|
|
|
|
printf("iop_msg_wait: IOP state = %d\n",
|
|
|
|
(le32toh(sc->sc_status.segnumber) >> 16) & 0xff);
|
|
|
|
}
|
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release an unused message frame back to the IOP's inbound fifo.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_release_mfa(struct iop_softc *sc, u_int32_t mfa)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Use the frame to issue a no-op. */
|
2002-11-15 16:51:29 +03:00
|
|
|
iop_outl_msg(sc, mfa, I2O_VERSION_11 | (4 << 16));
|
|
|
|
iop_outl_msg(sc, mfa + 4, I2O_MSGFUNC(I2O_TID_IOP, I2O_UTIL_NOP));
|
|
|
|
iop_outl_msg(sc, mfa + 8, 0);
|
|
|
|
iop_outl_msg(sc, mfa + 12, 0);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_IFIFO, mfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Dump a reply frame header.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
static void
|
2001-03-20 16:01:48 +03:00
|
|
|
iop_reply_print(struct iop_softc *sc, struct i2o_reply *rb)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
u_int function, detail;
|
2000-11-08 22:45:30 +03:00
|
|
|
#ifdef I2OVERBOSE
|
|
|
|
const char *statusstr;
|
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
function = (le32toh(rb->msgfunc) >> 24) & 0xff;
|
2000-11-08 22:45:30 +03:00
|
|
|
detail = le16toh(rb->detail);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: reply:\n", sc->sc_dv.dv_xname);
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
#ifdef I2OVERBOSE
|
|
|
|
if (rb->reqstatus < sizeof(iop_status) / sizeof(iop_status[0]))
|
|
|
|
statusstr = iop_status[rb->reqstatus];
|
|
|
|
else
|
|
|
|
statusstr = "undefined error code";
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: function=0x%02x status=0x%02x (%s)\n",
|
|
|
|
sc->sc_dv.dv_xname, function, rb->reqstatus, statusstr);
|
2000-11-08 22:45:30 +03:00
|
|
|
#else
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: function=0x%02x status=0x%02x\n",
|
|
|
|
sc->sc_dv.dv_xname, function, rb->reqstatus);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: detail=0x%04x ictx=0x%08x tctx=0x%08x\n",
|
|
|
|
sc->sc_dv.dv_xname, detail, le32toh(rb->msgictx),
|
|
|
|
le32toh(rb->msgtctx));
|
|
|
|
printf("%s: tidi=%d tidt=%d flags=0x%02x\n", sc->sc_dv.dv_xname,
|
|
|
|
(le32toh(rb->msgfunc) >> 12) & 4095, le32toh(rb->msgfunc) & 4095,
|
|
|
|
(le32toh(rb->msgflags) >> 8) & 0xff);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Dump a transport failure reply.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_tfn_print(struct iop_softc *sc, struct i2o_fault_notify *fn)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("%s: WARNING: transport failure:\n", sc->sc_dv.dv_xname);
|
|
|
|
|
2001-09-27 22:43:37 +04:00
|
|
|
printf("%s: ictx=0x%08x tctx=0x%08x\n", sc->sc_dv.dv_xname,
|
2001-03-20 16:01:48 +03:00
|
|
|
le32toh(fn->msgictx), le32toh(fn->msgtctx));
|
|
|
|
printf("%s: failurecode=0x%02x severity=0x%02x\n",
|
|
|
|
sc->sc_dv.dv_xname, fn->failurecode, fn->severity);
|
|
|
|
printf("%s: highestver=0x%02x lowestver=0x%02x\n",
|
|
|
|
sc->sc_dv.dv_xname, fn->highestver, fn->lowestver);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Translate an I2O ASCII field into a C string.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
void
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_strvis(struct iop_softc *sc, const char *src, int slen, char *dst, int dlen)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
int hc, lc, i, nit;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
dlen--;
|
|
|
|
lc = 0;
|
|
|
|
hc = 0;
|
|
|
|
i = 0;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DPT use NUL as a space, whereas AMI use it as a terminator. The
|
|
|
|
* spec has nothing to say about it. Since AMI fields are usually
|
|
|
|
* filled with junk after the terminator, ...
|
|
|
|
*/
|
|
|
|
nit = (le16toh(sc->sc_status.orgid) != I2O_ORG_DPT);
|
|
|
|
|
|
|
|
while (slen-- != 0 && dlen-- != 0) {
|
|
|
|
if (nit && *src == '\0')
|
|
|
|
break;
|
|
|
|
else if (*src <= 0x20 || *src >= 0x7f) {
|
2000-11-08 22:45:30 +03:00
|
|
|
if (hc)
|
|
|
|
dst[i++] = ' ';
|
|
|
|
} else {
|
|
|
|
hc = 1;
|
|
|
|
dst[i++] = *src;
|
|
|
|
lc = i;
|
|
|
|
}
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[lc] = '\0';
|
|
|
|
}
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/*
|
|
|
|
* Retrieve the DEVICE_IDENTITY parameter group from the target and dump it.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_print_ident(struct iop_softc *sc, int tid)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct i2o_param_op_results pr;
|
|
|
|
struct i2o_param_read_results prr;
|
|
|
|
struct i2o_param_device_identity di;
|
|
|
|
} __attribute__ ((__packed__)) p;
|
|
|
|
char buf[32];
|
|
|
|
int rv;
|
|
|
|
|
2001-08-22 13:42:05 +04:00
|
|
|
rv = iop_field_get_all(sc, tid, I2O_PARAM_DEVICE_IDENTITY, &p,
|
|
|
|
sizeof(p), NULL);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
iop_strvis(sc, p.di.vendorinfo, sizeof(p.di.vendorinfo), buf,
|
|
|
|
sizeof(buf));
|
|
|
|
printf(" <%s, ", buf);
|
|
|
|
iop_strvis(sc, p.di.productinfo, sizeof(p.di.productinfo), buf,
|
|
|
|
sizeof(buf));
|
|
|
|
printf("%s, ", buf);
|
|
|
|
iop_strvis(sc, p.di.revlevel, sizeof(p.di.revlevel), buf, sizeof(buf));
|
|
|
|
printf("%s>", buf);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Claim or unclaim the specified TID.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_util_claim(struct iop_softc *sc, struct iop_initiator *ii, int release,
|
2001-08-04 20:54:18 +04:00
|
|
|
int flags)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_util_claim mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
int rv, func;
|
|
|
|
|
|
|
|
func = release ? I2O_UTIL_CLAIM_RELEASE : I2O_UTIL_CLAIM;
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* We can use the same structure, as they're identical. */
|
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_util_claim);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, func);
|
|
|
|
mf.msgictx = ii->ii_ictx;
|
|
|
|
mf.msgtctx = im->im_tctx;
|
|
|
|
mf.flags = flags;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, &mf, 5000);
|
|
|
|
iop_msg_free(sc, im);
|
2000-12-03 16:17:03 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/*
|
|
|
|
* Perform an abort.
|
|
|
|
*/
|
|
|
|
int iop_util_abort(struct iop_softc *sc, struct iop_initiator *ii, int func,
|
2001-08-04 20:54:18 +04:00
|
|
|
int tctxabort, int flags)
|
2000-12-03 16:17:03 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_util_abort mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
int rv;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_util_abort);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_ABORT);
|
|
|
|
mf.msgictx = ii->ii_ictx;
|
|
|
|
mf.msgtctx = im->im_tctx;
|
|
|
|
mf.flags = (func << 24) | flags;
|
|
|
|
mf.tctxabort = tctxabort;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_msg_post(sc, im, &mf, 5000);
|
|
|
|
iop_msg_free(sc, im);
|
2000-12-03 16:17:03 +03:00
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-20 16:01:48 +03:00
|
|
|
* Enable or disable reception of events for the specified device.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
int iop_util_eventreg(struct iop_softc *sc, struct iop_initiator *ii, int mask)
|
|
|
|
{
|
2001-03-20 16:01:48 +03:00
|
|
|
struct i2o_util_event_register mf;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.msgflags = I2O_MSGFLAGS(i2o_util_event_register);
|
|
|
|
mf.msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_EVENT_REGISTER);
|
|
|
|
mf.msgictx = ii->ii_ictx;
|
2001-08-04 20:54:18 +04:00
|
|
|
mf.msgtctx = 0;
|
2001-03-20 16:01:48 +03:00
|
|
|
mf.eventmask = mask;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
/* This message is replied to only when events are signalled. */
|
2001-08-04 20:54:18 +04:00
|
|
|
return (iop_post(sc, (u_int32_t *)&mf));
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
iopopen(dev_t dev, int flag, int mode, struct proc *p)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_softc *sc;
|
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((sc = device_lookup(&iop_cd, minor(dev))) == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
if ((sc->sc_flags & IOP_ONLINE) == 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (ENXIO);
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((sc->sc_flags & IOP_OPEN) != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
sc->sc_flags |= IOP_OPEN;
|
|
|
|
|
|
|
|
return (0);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
iopclose(dev_t dev, int flag, int mode, struct proc *p)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_softc *sc;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
sc = device_lookup(&iop_cd, minor(dev));
|
2001-03-20 16:01:48 +03:00
|
|
|
sc->sc_flags &= ~IOP_OPEN;
|
2001-08-04 20:54:18 +04:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
return (0);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
iopioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_softc *sc;
|
|
|
|
struct iovec *iov;
|
|
|
|
int rv, i;
|
|
|
|
|
|
|
|
if (securelevel >= 2)
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
sc = device_lookup(&iop_cd, minor(dev));
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IOPIOCPT:
|
2003-06-30 02:28:00 +04:00
|
|
|
return (iop_passthrough(sc, (struct ioppt *)data, p));
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
case IOPIOCGSTATUS:
|
|
|
|
iov = (struct iovec *)data;
|
|
|
|
i = sizeof(struct i2o_status);
|
|
|
|
if (i > iov->iov_len)
|
|
|
|
i = iov->iov_len;
|
|
|
|
else
|
|
|
|
iov->iov_len = i;
|
|
|
|
if ((rv = iop_status_get(sc, 0)) == 0)
|
|
|
|
rv = copyout(&sc->sc_status, iov->iov_base, i);
|
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
case IOPIOCGLCT:
|
|
|
|
case IOPIOCGTIDMAP:
|
|
|
|
case IOPIOCRECONFIG:
|
|
|
|
break;
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
default:
|
|
|
|
#if defined(DIAGNOSTIC) || defined(I2ODEBUG)
|
|
|
|
printf("%s: unknown ioctl %lx\n", sc->sc_dv.dv_xname, cmd);
|
|
|
|
#endif
|
|
|
|
return (ENOTTY);
|
|
|
|
}
|
2001-01-04 00:04:01 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
if ((rv = lockmgr(&sc->sc_conflock, LK_SHARED, NULL)) != 0)
|
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
switch (cmd) {
|
2000-12-03 16:17:03 +03:00
|
|
|
case IOPIOCGLCT:
|
|
|
|
iov = (struct iovec *)data;
|
2001-03-20 16:01:48 +03:00
|
|
|
i = le16toh(sc->sc_lct->tablesize) << 2;
|
2000-12-03 16:17:03 +03:00
|
|
|
if (i > iov->iov_len)
|
|
|
|
i = iov->iov_len;
|
|
|
|
else
|
|
|
|
iov->iov_len = i;
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = copyout(sc->sc_lct, iov->iov_base, i);
|
2000-12-03 16:17:03 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOPIOCRECONFIG:
|
2001-03-20 16:01:48 +03:00
|
|
|
rv = iop_reconfigure(sc, 0);
|
2001-01-04 00:04:01 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOPIOCGTIDMAP:
|
|
|
|
iov = (struct iovec *)data;
|
2001-03-20 16:01:48 +03:00
|
|
|
i = sizeof(struct iop_tidmap) * sc->sc_nlctent;
|
|
|
|
if (i > iov->iov_len)
|
|
|
|
i = iov->iov_len;
|
|
|
|
else
|
|
|
|
iov->iov_len = i;
|
|
|
|
rv = copyout(sc->sc_tidmap, iov->iov_base, i);
|
2000-12-03 16:17:03 +03:00
|
|
|
break;
|
2001-03-20 16:01:48 +03:00
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-08-04 20:54:18 +04:00
|
|
|
iop_passthrough(struct iop_softc *sc, struct ioppt *pt, struct proc *p)
|
2001-03-20 16:01:48 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_msg *mf;
|
|
|
|
struct ioppt_buf *ptb;
|
|
|
|
int rv, i, mapped;
|
|
|
|
|
|
|
|
mf = NULL;
|
|
|
|
im = NULL;
|
|
|
|
mapped = 1;
|
|
|
|
|
2001-09-27 22:43:37 +04:00
|
|
|
if (pt->pt_msglen > sc->sc_framesize ||
|
2001-03-20 16:01:48 +03:00
|
|
|
pt->pt_msglen < sizeof(struct i2o_msg) ||
|
|
|
|
pt->pt_nbufs > IOP_MAX_MSG_XFERS ||
|
|
|
|
pt->pt_nbufs < 0 || pt->pt_replylen < 0 ||
|
|
|
|
pt->pt_timo < 1000 || pt->pt_timo > 5*60*1000)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
for (i = 0; i < pt->pt_nbufs; i++)
|
|
|
|
if (pt->pt_bufs[i].ptb_datalen > IOP_MAX_XFER) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2001-09-27 22:43:37 +04:00
|
|
|
mf = malloc(sc->sc_framesize, M_DEVBUF, M_WAITOK);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (mf == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
if ((rv = copyin(pt->pt_msg, mf, pt->pt_msglen)) != 0)
|
|
|
|
goto bad;
|
|
|
|
|
2001-08-04 20:54:18 +04:00
|
|
|
im = iop_msg_alloc(sc, IM_WAIT | IM_NOSTATUS);
|
2001-03-20 16:01:48 +03:00
|
|
|
im->im_rb = (struct i2o_reply *)mf;
|
|
|
|
mf->msgictx = IOP_ICTX;
|
|
|
|
mf->msgtctx = im->im_tctx;
|
|
|
|
|
|
|
|
for (i = 0; i < pt->pt_nbufs; i++) {
|
|
|
|
ptb = &pt->pt_bufs[i];
|
2001-08-04 20:54:18 +04:00
|
|
|
rv = iop_msg_map(sc, im, (u_int32_t *)mf, ptb->ptb_data,
|
|
|
|
ptb->ptb_datalen, ptb->ptb_out != 0, p);
|
2001-03-20 16:01:48 +03:00
|
|
|
if (rv != 0)
|
|
|
|
goto bad;
|
|
|
|
mapped = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = iop_msg_post(sc, im, mf, pt->pt_timo)) != 0)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
i = (le32toh(im->im_rb->msgflags) >> 14) & ~3;
|
2001-09-27 22:43:37 +04:00
|
|
|
if (i > sc->sc_framesize)
|
|
|
|
i = sc->sc_framesize;
|
2001-03-20 16:01:48 +03:00
|
|
|
if (i > pt->pt_replylen)
|
|
|
|
i = pt->pt_replylen;
|
2001-08-04 20:54:18 +04:00
|
|
|
rv = copyout(im->im_rb, pt->pt_reply, i);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2001-03-20 16:01:48 +03:00
|
|
|
bad:
|
|
|
|
if (mapped != 0)
|
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
if (im != NULL)
|
|
|
|
iop_msg_free(sc, im);
|
|
|
|
if (mf != NULL)
|
|
|
|
free(mf, M_DEVBUF);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|