2001-01-01 22:03:30 +03:00
|
|
|
/* $NetBSD: iop.c,v 1.8 2001/01/01 19:03:30 ad Exp $ */
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
|
|
|
#include <sys/pool.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>
|
|
|
|
#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
|
2000-11-08 22:45:30 +03:00
|
|
|
#else
|
|
|
|
#define IFVERBOSE(x)
|
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#define COMMENT(x) ""
|
|
|
|
|
|
|
|
#define IOP_ICTXHASH_NBUCKETS 16
|
|
|
|
#define IOP_ICTXHASH(ictx) (&iop_ictxhashtbl[(ictx) & iop_ictxhash])
|
|
|
|
#define IOP_TCTXHASH_NBUCKETS 64
|
|
|
|
#define IOP_TCTXHASH(tctx) (&iop_tctxhashtbl[(tctx) & iop_tctxhash])
|
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;
|
|
|
|
static TAILQ_HEAD(, iop_msg) *iop_tctxhashtbl;
|
|
|
|
static u_long iop_tctxhash;
|
2000-11-08 22:45:30 +03:00
|
|
|
static void *iop_sdh;
|
|
|
|
static struct pool *iop_msgpool;
|
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;
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#define IC_CONFIGURE 0x01
|
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;
|
2000-11-08 22:45:30 +03:00
|
|
|
const char *ic_caption;
|
|
|
|
} static const iop_class[] = {
|
|
|
|
{
|
|
|
|
I2O_CLASS_EXECUTIVE,
|
|
|
|
0,
|
2000-12-03 16:17:03 +03:00
|
|
|
COMMENT("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,
|
2000-12-03 16:17:03 +03:00
|
|
|
IC_CONFIGURE,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("random block storage")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_SEQUENTIAL_STORAGE,
|
2000-12-03 16:17:03 +03:00
|
|
|
IC_CONFIGURE,
|
2000-11-08 22:45:30 +03:00
|
|
|
IFVERBOSE("sequential storage")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_LAN,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
IFVERBOSE("LAN port")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
I2O_CLASS_WAN,
|
|
|
|
IC_CONFIGURE,
|
|
|
|
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)
|
|
|
|
static const char *iop_status[] = {
|
|
|
|
"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);
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_config_interrupts(struct device *);
|
2000-12-03 16:17:03 +03:00
|
|
|
static void iop_configure_devices(struct iop_softc *);
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_devinfo(int, char *);
|
|
|
|
static int iop_print(void *, const char *);
|
2000-12-03 16:17:03 +03:00
|
|
|
static int iop_reconfigure(struct iop_softc *, u_int32_t);
|
2000-11-08 22:45:30 +03:00
|
|
|
static void iop_shutdown(void *);
|
|
|
|
static int iop_submatch(struct device *, struct cfdata *, void *);
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef notyet
|
2000-11-08 22:45:30 +03:00
|
|
|
static int iop_vendor_print(void *, const char *);
|
2000-12-03 16:17:03 +03:00
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
static void iop_intr_event(struct device *, struct iop_msg *, void *);
|
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);
|
2000-12-03 16:17:03 +03:00
|
|
|
static int iop_lct_get0(struct iop_softc *, struct i2o_lct *, int,
|
|
|
|
u_int32_t);
|
|
|
|
static int 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 *);
|
2000-12-03 16:17:03 +03:00
|
|
|
static int iop_handle_reply(struct iop_softc *, u_int32_t);
|
|
|
|
static void iop_reconfigure_proc(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_status_get(struct iop_softc *);
|
|
|
|
static int iop_systab_set(struct iop_softc *);
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
static void iop_reply_print(struct iop_softc *, struct iop_msg *,
|
|
|
|
struct i2o_reply *);
|
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
cdev_decl(iop);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/*
|
|
|
|
* Initialise the adapter.
|
|
|
|
*/
|
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)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
u_int32_t mask;
|
|
|
|
static int again;
|
|
|
|
char ident[64];
|
|
|
|
|
|
|
|
if (again == 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
/* Create the shared message wrapper pool and hashes. */
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msgpool = pool_create(sizeof(struct iop_msg), 0, 0, 0,
|
|
|
|
"ioppl", 0, NULL, NULL, M_DEVBUF);
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_ictxhashtbl = hashinit(IOP_ICTXHASH_NBUCKETS, HASH_LIST,
|
|
|
|
M_DEVBUF, M_NOWAIT, &iop_ictxhash);
|
|
|
|
iop_tctxhashtbl = hashinit(IOP_TCTXHASH_NBUCKETS, HASH_TAILQ,
|
|
|
|
M_DEVBUF, M_NOWAIT, &iop_tctxhash);
|
2000-11-08 22:45:30 +03:00
|
|
|
again = 1;
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/* Reset the IOP and request status. */
|
2000-11-08 22:45:30 +03:00
|
|
|
printf("I2O adapter");
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
if ((rv = iop_reset(sc)) != 0) {
|
|
|
|
printf("%s: not responding (reset)\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
if ((rv = iop_status_get(sc)) != 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: not responding (get status)\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
DPRINTF((" (state=%d)",
|
|
|
|
(le32toh(sc->sc_status.segnumber) >> 16) & 0xff));
|
|
|
|
sc->sc_flags |= IOP_HAVESTATUS;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
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
|
|
|
|
|
|
|
sc->sc_maxreplycnt = le32toh(sc->sc_status.maxoutboundmframes);
|
|
|
|
if (sc->sc_maxreplycnt > IOP_MAX_HW_REPLYCNT)
|
|
|
|
sc->sc_maxreplycnt = IOP_MAX_HW_REPLYCNT;
|
2000-12-03 16:17:03 +03:00
|
|
|
sc->sc_maxqueuecnt = le32toh(sc->sc_status.maxinboundmframes);
|
|
|
|
if (sc->sc_maxqueuecnt > IOP_MAX_HW_QUEUECNT)
|
|
|
|
sc->sc_maxqueuecnt = IOP_MAX_HW_QUEUECNT;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if (iop_ofifo_init(sc) != 0) {
|
|
|
|
printf("%s: unable to init oubound FIFO\n", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
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",
|
|
|
|
sc->sc_dv.dv_xname,
|
|
|
|
sc->sc_maxqueuecnt, le32toh(sc->sc_status.maxinboundmframes),
|
|
|
|
sc->sc_maxreplycnt, le32toh(sc->sc_status.maxoutboundmframes));
|
|
|
|
#endif
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
lockinit(&sc->sc_conflock, PRIBIO, "iopconf", hz * 30, 0);
|
2000-11-08 22:45:30 +03:00
|
|
|
SIMPLEQ_INIT(&sc->sc_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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)
|
|
|
|
{
|
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;
|
|
|
|
if (iop_status_get(iop) != 0) {
|
|
|
|
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;
|
|
|
|
iop_systab = malloc(i, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
memset(iop_systab, 0, i);
|
|
|
|
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
|
|
|
|
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,
|
|
|
|
5000) != 0) {
|
|
|
|
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;
|
|
|
|
sc->sc_eventii.ii_flags = II_DISCARD | II_UTILITY;
|
|
|
|
sc->sc_eventii.ii_tid = I2O_TID_IOP;
|
|
|
|
if (iop_initiator_register(sc, &sc->sc_eventii) != 0) {
|
|
|
|
printf("%s: unable to register initiator", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (iop_util_eventreg(sc, &sc->sc_eventii, 0xffffffff)) {
|
|
|
|
printf("%s: unable to register for events", sc->sc_dv.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notyet
|
2000-11-08 22:45:30 +03:00
|
|
|
/* Attempt to match and attach a product-specific extension. */
|
|
|
|
ia.ia_class = I2O_CLASS_ANY;
|
|
|
|
ia.ia_tid = I2O_TID_IOP;
|
|
|
|
config_found_sm(self, &ia, iop_vendor_print, iop_submatch);
|
2000-12-03 16:17:03 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((rv = iop_reconfigure(sc, 0)) != 0) {
|
|
|
|
printf("%s: configure failed (%d)\n", sc->sc_dv.dv_xname, rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_flags |= IOP_ONLINE;
|
|
|
|
|
|
|
|
rv = kthread_create1(iop_reconfigure_proc, sc, &sc->sc_reconf_proc,
|
|
|
|
"%s", sc->sc_dv.dv_xname);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: unable to create thread (%d)",
|
|
|
|
sc->sc_dv.dv_xname, rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconfiguration thread; listens for LCT change notification, and
|
|
|
|
* initiates re-configuration if recieved.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_reconfigure_proc(void *cookie)
|
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
|
|
|
struct i2o_lct lct;
|
|
|
|
u_int32_t chgind;
|
|
|
|
|
|
|
|
sc = cookie;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
chgind = le32toh(sc->sc_chgindicator) + 1;
|
|
|
|
|
|
|
|
if (iop_lct_get0(sc, &lct, sizeof(lct), chgind) == 0) {
|
|
|
|
DPRINTF(("%s: async reconfiguration (0x%08x)\n",
|
|
|
|
sc->sc_dv.dv_xname, le32toh(lct.changeindicator)));
|
|
|
|
iop_reconfigure(sc, lct.changeindicator);
|
|
|
|
}
|
|
|
|
|
|
|
|
tsleep(iop_reconfigure_proc, PWAIT, "iopzzz", hz * 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconfigure: find new and removed devices.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_reconfigure(struct iop_softc *sc, u_int32_t chgind)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_hba_bus_scan *mb;
|
|
|
|
struct i2o_lct_entry *le;
|
|
|
|
struct iop_initiator *ii, *nextii;
|
|
|
|
int rv, tid, i;
|
|
|
|
|
|
|
|
rv = lockmgr(&sc->sc_conflock, LK_EXCLUSIVE | LK_RECURSEFAIL, NULL);
|
|
|
|
if (rv != 0) {
|
|
|
|
DPRINTF(("iop_reconfigure: unable to acquire lock\n"));
|
|
|
|
return (rv);
|
|
|
|
}
|
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"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
tid = le32toh(le->localtid) & 4095;
|
|
|
|
|
|
|
|
rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR);
|
|
|
|
if (rv != 0) {
|
|
|
|
DPRINTF(("iop_reconfigure: alloc msg\n"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb = (struct i2o_hba_bus_scan *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_hba_bus_scan);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(tid, I2O_HBA_BUS_SCAN);
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
|
|
|
|
DPRINTF(("%s: scanning bus %d\n", sc->sc_dv.dv_xname,
|
|
|
|
tid));
|
|
|
|
|
|
|
|
rv = iop_msg_enqueue(sc, im, 5*60*1000);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
if (rv != 0) {
|
|
|
|
DPRINTF(("iop_reconfigure: scan failed\n"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (chgind == sc->sc_chgindicator) {
|
|
|
|
DPRINTF(("%s: LCT unchanged (async)\n", sc->sc_dv.dv_xname));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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"));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: %d LCT entries\n", sc->sc_dv.dv_xname, sc->sc_nlctent));
|
|
|
|
|
|
|
|
if (sc->sc_lct->changeindicator == sc->sc_chgindicator) {
|
|
|
|
DPRINTF(("%s: LCT unchanged\n", sc->sc_dv.dv_xname));
|
|
|
|
/* Nothing to do. */
|
|
|
|
rv = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
DPRINTF(("%s: LCT changed\n", sc->sc_dv.dv_xname));
|
|
|
|
sc->sc_chgindicator = sc->sc_lct->changeindicator;
|
|
|
|
|
|
|
|
if (sc->sc_tidmap != NULL)
|
|
|
|
free(sc->sc_tidmap, M_DEVBUF);
|
|
|
|
sc->sc_tidmap = malloc(sc->sc_nlctent * sizeof(struct iop_tidmap),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
|
|
|
memset(sc->sc_tidmap, 0, sc->sc_nlctent * sizeof(struct iop_tidmap));
|
|
|
|
|
|
|
|
/* Match and attach child devices. */
|
|
|
|
iop_configure_devices(sc);
|
|
|
|
|
|
|
|
for (ii = LIST_FIRST(&sc->sc_iilist); ii != NULL; ii = nextii) {
|
|
|
|
nextii = LIST_NEXT(ii, ii_list);
|
|
|
|
if ((ii->ii_flags & II_UTILITY) != 0)
|
|
|
|
continue;
|
|
|
|
if ((ii->ii_flags & II_CONFIGURED) == 0) {
|
|
|
|
ii->ii_flags |= II_CONFIGURED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
|
|
|
|
return (rv);
|
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
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_configure_devices(struct iop_softc *sc)
|
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-01 22:03:30 +03:00
|
|
|
int i, j, nent;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
nent = sc->sc_nlctent;
|
|
|
|
for (i = 0, le = sc->sc_lct->entry; i < nent; i++, le++) {
|
2000-12-03 16:17:03 +03:00
|
|
|
/*
|
|
|
|
* Ignore the device if it's in use.
|
|
|
|
*/
|
|
|
|
if ((le32toh(le->usertid) & 4095) != 4095)
|
2000-11-08 22:45:30 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ia.ia_class = le16toh(le->classid) & 4095;
|
2000-12-03 16:17:03 +03:00
|
|
|
ia.ia_tid = le32toh(le->localtid) & 4095;
|
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]) &&
|
|
|
|
(iop_class[j].ic_flags & IC_CONFIGURE) == 0)
|
|
|
|
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) {
|
|
|
|
if ((ii->ii_flags & II_UTILITY) != 0)
|
|
|
|
continue;
|
2000-12-03 16:17:03 +03:00
|
|
|
if (ia.ia_tid == ii->ii_tid)
|
|
|
|
break;
|
2000-12-03 18:51:36 +03:00
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
if (ii != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (config_found_sm(&sc->sc_dv, &ia, iop_print, iop_submatch))
|
|
|
|
sc->sc_tidmap[i].it_flags |= IT_CONFIGURED;
|
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);
|
|
|
|
printf("%s at %s", devinfo, pnp);
|
|
|
|
}
|
|
|
|
printf(" tid %d", ia->ia_tid);
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef notyet
|
2000-11-08 22:45:30 +03:00
|
|
|
static int
|
|
|
|
iop_vendor_print(void *aux, const char *pnp)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (pnp != NULL)
|
|
|
|
printf("vendor specific extension at %s", pnp);
|
|
|
|
return (UNCONF);
|
|
|
|
}
|
2000-12-03 16:17:03 +03:00
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return ((*cf->cf_attach->ca_match)(parent, cf, aux));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shut down all configured IOPs.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_shutdown(void *junk)
|
|
|
|
{
|
|
|
|
struct iop_softc *sc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("shutting down iop devices... ");
|
|
|
|
|
|
|
|
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;
|
|
|
|
iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_SYS_QUIESCE, IOP_ICTX,
|
|
|
|
0, 5000);
|
|
|
|
iop_simple_cmd(sc, I2O_TID_IOP, I2O_EXEC_IOP_CLEAR, IOP_ICTX,
|
|
|
|
0, 5000);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait. Some boards could still be flushing, stupidly enough. */
|
|
|
|
delay(5000*1000);
|
|
|
|
printf(" done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve adapter status.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_status_get(struct iop_softc *sc)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_exec_status_get *mb;
|
|
|
|
int rv, s;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOWAIT | IM_NOICTX)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_exec_status_get *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_status_get);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_STATUS_GET);
|
|
|
|
mb->reserved[0] = 0;
|
|
|
|
mb->reserved[1] = 0;
|
|
|
|
mb->reserved[2] = 0;
|
|
|
|
mb->reserved[3] = 0;
|
|
|
|
mb->addrlow = kvtop((caddr_t)&sc->sc_status); /* XXX */
|
|
|
|
mb->addrhigh = 0;
|
|
|
|
mb->length = sizeof(sc->sc_status);
|
|
|
|
|
|
|
|
s = splbio();
|
2000-12-03 16:17:03 +03:00
|
|
|
memset(&sc->sc_status, 0, sizeof(sc->sc_status));
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
if ((rv = iop_msg_send(sc, im, 0)) != 0) {
|
|
|
|
splx(s);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
POLL(2500, *((volatile u_char *)&sc->sc_status.syncbyte) == 0xff);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (*((volatile u_char *)&sc->sc_status.syncbyte) != 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initalize and populate the adapter's outbound FIFO.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_ofifo_init(struct iop_softc *sc)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
volatile u_int32_t status;
|
|
|
|
bus_addr_t addr;
|
2000-12-03 16:17:03 +03:00
|
|
|
bus_dma_segment_t seg;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct i2o_exec_outbound_init *mb;
|
2000-12-03 16:17:03 +03:00
|
|
|
int i, rseg, rv;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOWAIT | IM_NOICTX)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_exec_outbound_init *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_outbound_init);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_OUTBOUND_INIT);
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
2000-11-14 21:42:55 +03:00
|
|
|
mb->pagesize = PAGE_SIZE;
|
2000-12-03 16:17:03 +03:00
|
|
|
mb->flags = 0x80 | ((IOP_MAX_REPLY_SIZE >> 2) << 16); /* XXX */
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
status = 0;
|
|
|
|
|
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
|
|
|
|
* necessary; this isn't the case (and in fact appears to be a bad
|
|
|
|
* thing).
|
|
|
|
*/
|
|
|
|
iop_msg_map(sc, im, (void *)&status, sizeof(status), 0);
|
2000-11-08 22:45:30 +03:00
|
|
|
if ((rv = iop_msg_send(sc, im, 0)) != 0) {
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/* XXX */
|
|
|
|
POLL(5000, status == I2O_EXEC_OUTBOUND_INIT_COMPLETE);
|
|
|
|
if (status != I2O_EXEC_OUTBOUND_INIT_COMPLETE) {
|
|
|
|
printf("%s: outbound FIFO init failed\n", sc->sc_dv.dv_xname);
|
|
|
|
return (EIO);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we need to allocate DMA safe memory, do it now. */
|
|
|
|
if (sc->sc_rep_phys == 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
sc->sc_rep_size = sc->sc_maxreplycnt * IOP_MAX_REPLY_SIZE;
|
|
|
|
|
|
|
|
rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_rep_size, PAGE_SIZE,
|
|
|
|
0, &seg, 1, &rseg, BUS_DMA_NOWAIT);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: dma alloc = %d\n", sc->sc_dv.dv_xname,
|
|
|
|
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) {
|
|
|
|
printf("%s: dma map = %d\n", sc->sc_dv.dv_xname, rv);
|
|
|
|
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) {
|
|
|
|
printf("%s: dma create = %d\n", sc->sc_dv.dv_xname, rv);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = bus_dmamap_load(sc->sc_dmat, sc->sc_rep_dmamap, sc->sc_rep,
|
|
|
|
sc->sc_rep_size, NULL, BUS_DMA_NOWAIT);
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("%s: dma load = %d\n", sc->sc_dv.dv_xname, rv);
|
|
|
|
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. */
|
2000-12-03 16:17:03 +03:00
|
|
|
for (i = sc->sc_maxreplycnt, addr = sc->sc_rep_phys; i != 0; i--) {
|
|
|
|
iop_outl(sc, IOP_REG_OFIFO, (u_int32_t)addr);
|
|
|
|
addr += IOP_MAX_REPLY_SIZE;
|
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;
|
|
|
|
struct i2o_exec_hrt_get *mb;
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR)) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_exec_hrt_get *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_hrt_get);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_HRT_GET);
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
|
|
|
|
iop_msg_map(sc, im, hrt, size, 0);
|
2000-12-03 16:17:03 +03:00
|
|
|
rv = iop_msg_enqueue(sc, im, 5000);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((rv = iop_hrt_get0(sc, &hrthdr, sizeof(hrthdr))) != 0)
|
|
|
|
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) +
|
|
|
|
(htole32(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
|
|
|
|
* is an verbatim notification request, so the caller is prepared
|
|
|
|
* 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;
|
|
|
|
struct i2o_exec_lct_notify *mb;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR)) != 0)
|
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
memset(lct, 0, size);
|
2000-12-03 16:17:03 +03:00
|
|
|
memset(im->im_msg, 0, sizeof(im->im_msg));
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
mb = (struct i2o_exec_lct_notify *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_lct_notify);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_LCT_NOTIFY);
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
mb->classid = I2O_CLASS_ANY;
|
2000-12-03 16:17:03 +03:00
|
|
|
mb->changeindicator = chgind;
|
|
|
|
|
|
|
|
DPRINTF(("iop_lct_get0: reading LCT\n"));
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
iop_msg_map(sc, im, lct, size, 0);
|
2000-12-03 16:17:03 +03:00
|
|
|
rv = iop_msg_enqueue(sc, im, (chgind == 0 ? 120*1000 : 0));
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Request the specified parameter group from the target.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_param_op(struct iop_softc *sc, int tid, int write, int group, void *buf,
|
|
|
|
int size)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_util_params_op *mb;
|
|
|
|
int rv, func, op;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct {
|
|
|
|
struct i2o_param_op_list_header olh;
|
|
|
|
struct i2o_param_op_all_template oat;
|
|
|
|
} req;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if (write) {
|
|
|
|
func = I2O_UTIL_PARAMS_SET;
|
|
|
|
op = I2O_PARAMS_OP_FIELD_SET;
|
|
|
|
} else {
|
|
|
|
func = I2O_UTIL_PARAMS_GET;
|
|
|
|
op = I2O_PARAMS_OP_FIELD_GET;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb = (struct i2o_util_params_op *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_util_params_op);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(tid, func);
|
2000-11-08 22:45:30 +03:00
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
mb->flags = 0;
|
|
|
|
|
|
|
|
req.olh.count = htole16(1);
|
|
|
|
req.olh.reserved = htole16(0);
|
2000-12-03 16:17:03 +03:00
|
|
|
req.oat.operation = htole16(op);
|
2000-11-08 22:45:30 +03:00
|
|
|
req.oat.fieldcount = htole16(0xffff);
|
|
|
|
req.oat.group = htole16(group);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
memset(buf, 0, size);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_map(sc, im, &req, sizeof(req), 1);
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_msg_map(sc, im, buf, size, write);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
rv = iop_msg_enqueue(sc, im, 5000);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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;
|
|
|
|
struct i2o_msg *mb;
|
2000-12-03 16:17:03 +03:00
|
|
|
int rv, fl;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
fl = (async != 0 ? IM_NOWAIT : 0);
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, fl | IM_NOINTR)) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_msg *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_msg);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(tid, function);
|
|
|
|
mb->msgictx = ictx;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if (async)
|
|
|
|
rv = iop_msg_enqueue(sc, im, timo);
|
|
|
|
else
|
|
|
|
rv = iop_msg_send(sc, im, timo);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
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)
|
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_exec_sys_tab_set *mb;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct iop_msg *im;
|
|
|
|
u_int32_t mema[2], ioa[2];
|
|
|
|
int rv;
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR)) != 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_exec_sys_tab_set *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_sys_tab_set);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_SYS_TAB_SET);
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
2000-12-03 16:17:03 +03:00
|
|
|
mb->iopid = (sc->sc_dv.dv_unit + 2) << 12;
|
|
|
|
mb->segnumber = 0;
|
|
|
|
|
|
|
|
/* XXX This is questionable, but better than nothing... */
|
|
|
|
mema[0] = le32toh(sc->sc_status.currentprivmembase);
|
|
|
|
mema[1] = le32toh(sc->sc_status.currentprivmemsize);
|
|
|
|
ioa[0] = le32toh(sc->sc_status.currentpriviobase);
|
|
|
|
ioa[1] = le32toh(sc->sc_status.currentpriviosize);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_msg_map(sc, im, iop_systab, iop_systab_size, 1);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_map(sc, im, mema, sizeof(mema), 1);
|
|
|
|
iop_msg_map(sc, im, ioa, sizeof(ioa), 1);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
rv = iop_msg_enqueue(sc, im, 5000);
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_unmap(sc, im);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the adapter. Must be called with interrupts disabled.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
iop_reset(struct iop_softc *sc)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
volatile u_int32_t sw;
|
|
|
|
u_int32_t mfa;
|
|
|
|
struct i2o_exec_iop_reset *mb;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, NULL, &im, IM_NOWAIT | IM_NOICTX)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
sw = 0;
|
|
|
|
|
|
|
|
mb = (struct i2o_exec_iop_reset *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_exec_iop_reset);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(I2O_TID_IOP, I2O_EXEC_IOP_RESET);
|
|
|
|
mb->reserved[0] = 0;
|
|
|
|
mb->reserved[1] = 0;
|
|
|
|
mb->reserved[2] = 0;
|
|
|
|
mb->reserved[3] = 0;
|
|
|
|
mb->statuslow = kvtop((caddr_t)&sw); /* XXX */
|
|
|
|
mb->statushigh = 0;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_send(sc, im, 0)))
|
|
|
|
return (rv);
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
|
|
|
|
POLL(2500, sw != 0); /* XXX */
|
|
|
|
if (sw != I2O_RESET_IN_PROGRESS) {
|
|
|
|
printf("%s: reset rejected\n", sc->sc_dv.dv_xname);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if (sw == I2O_RESET_REJECTED)
|
|
|
|
printf("%s: reset rejected?\n", sc->sc_dv.dv_xname);
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_release_mfa(sc, mfa);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a new initiator.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_initiator_register(struct iop_softc *sc, struct iop_initiator *ii)
|
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
static int ictx;
|
|
|
|
static int stctx;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/* 0 is reserved for system messages. */
|
|
|
|
ii->ii_ictx = ++ictx;
|
|
|
|
ii->ii_stctx = ++stctx | 0x80000000;
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&sc->sc_iilist, ii, ii_list);
|
|
|
|
LIST_INSERT_HEAD(IOP_ICTXHASH(ii->ii_ictx), ii, ii_hash);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unregister an initiator.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iop_initiator_unregister(struct iop_softc *sc, struct iop_initiator *ii)
|
|
|
|
{
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
LIST_REMOVE(ii, ii_list);
|
|
|
|
LIST_REMOVE(ii, ii_hash);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Handle a reply frame from the adapter.
|
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;
|
|
|
|
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);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
/* Perform reply queue DMA synchronisation... */
|
2000-11-08 22:45:30 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, off, IOP_MAX_MSG_SIZE,
|
|
|
|
BUS_DMASYNC_POSTREAD);
|
|
|
|
if (--sc->sc_stat.is_cur_hwqueue != 0)
|
|
|
|
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
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_reply_print(sc, NULL, rb);
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
2000-12-03 16:17:03 +03:00
|
|
|
printf("%s: WARNING: bad ictx returned (%x)",
|
|
|
|
sc->sc_dv.dv_xname, ictx);
|
|
|
|
|
|
|
|
/* Return the reply frame to the IOP's outbound FIFO. */
|
|
|
|
iop_outl(sc, IOP_REG_OFIFO, rmfa);
|
|
|
|
return (-1);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status = rb->reqstatus;
|
|
|
|
|
|
|
|
if (ii == NULL || (ii->ii_flags & II_DISCARD) == 0) {
|
|
|
|
/*
|
|
|
|
* This initiator tracks state using message wrappers.
|
|
|
|
*
|
|
|
|
* Find the originating message wrapper, and if requested
|
|
|
|
* notify the initiator.
|
|
|
|
*/
|
|
|
|
tctx = le32toh(rb->msgtctx);
|
2000-12-03 16:17:03 +03:00
|
|
|
im = TAILQ_FIRST(IOP_TCTXHASH(tctx));
|
2000-11-08 22:45:30 +03:00
|
|
|
for (; im != NULL; im = TAILQ_NEXT(im, im_hash))
|
|
|
|
if (im->im_tctx == tctx)
|
|
|
|
break;
|
2000-12-03 16:17:03 +03:00
|
|
|
if (im == NULL || (im->im_flags & IM_ALLOCED) == 0) {
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
iop_reply_print(sc, NULL, rb);
|
|
|
|
#endif
|
|
|
|
printf("%s: WARNING: bad tctx returned (%x, %p)",
|
2000-11-08 22:45:30 +03:00
|
|
|
sc->sc_dv.dv_xname, tctx, im);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
/* Return the reply frame to the IOP's outbound FIFO. */
|
|
|
|
iop_outl(sc, IOP_REG_OFIFO, rmfa);
|
|
|
|
return (-1);
|
|
|
|
}
|
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
|
|
|
|
if (rb->reqstatus != 0)
|
|
|
|
iop_reply_print(sc, im, rb);
|
|
|
|
#endif
|
|
|
|
/* Notify the initiator. */
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((im->im_flags & IM_WAITING) != 0) {
|
|
|
|
size = (le32toh(rb->msgflags) >> 14) & ~3;
|
|
|
|
if (size > IOP_MAX_REPLY_SIZE)
|
|
|
|
size = IOP_MAX_REPLY_SIZE;
|
|
|
|
memcpy(im->im_msg, rb, size);
|
2000-11-08 22:45:30 +03:00
|
|
|
wakeup(im);
|
2000-12-03 16:17:03 +03:00
|
|
|
} else if ((im->im_flags & IM_NOINTR) == 0)
|
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 the reply frame to the IOP's outbound FIFO. */
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_OFIFO, rmfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* Run the queue. */
|
|
|
|
if ((im = SIMPLEQ_FIRST(&sc->sc_queue)) != NULL)
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_msg_enqueue(sc, im, 0);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an interrupt from the adapter.
|
|
|
|
*/
|
|
|
|
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. */
|
|
|
|
if ((rmfa = iop_inl(sc, IOP_REG_OFIFO)) == IOP_MFA_EMPTY &&
|
|
|
|
(rmfa = iop_inl(sc, IOP_REG_OFIFO)) == IOP_MFA_EMPTY)
|
|
|
|
break;
|
|
|
|
iop_handle_reply(sc, 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;
|
|
|
|
event = le32toh(rb->event);
|
|
|
|
|
|
|
|
#ifndef I2ODEBUG
|
|
|
|
if (event == I2O_EVENT_GEN_EVENT_MASK_MODIFIED)
|
|
|
|
return;
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
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.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_msg_alloc(struct iop_softc *sc, struct iop_initiator *ii,
|
|
|
|
struct iop_msg **imp, int flags)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
2000-12-03 16:17:03 +03:00
|
|
|
static int tctxgen = 666;
|
|
|
|
int s, rv, i, tctx;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((flags & IM_SYSMASK) != 0)
|
|
|
|
panic("iop_msg_alloc: system flags specified");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splbio(); /* XXX */
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if (ii != NULL && (ii->ii_flags & II_DISCARD) != 0) {
|
|
|
|
flags |= IM_DISCARD;
|
|
|
|
tctx = ii->ii_stctx;
|
|
|
|
} else
|
|
|
|
tctx = tctxgen++ & 0x7fffffff;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
im = (struct iop_msg *)pool_get(iop_msgpool,
|
|
|
|
(flags & IM_NOWAIT) == 0 ? PR_WAITOK : 0);
|
|
|
|
if (im == NULL) {
|
|
|
|
splx(s);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER, IOP_MAX_SGL_ENTRIES,
|
|
|
|
IOP_MAX_XFER, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,
|
|
|
|
&im->im_xfer[0].ix_map);
|
|
|
|
if (rv != 0) {
|
|
|
|
pool_put(iop_msgpool, im);
|
|
|
|
splx(s);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & (IM_DISCARD | IM_NOICTX)) == 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
TAILQ_INSERT_TAIL(IOP_TCTXHASH(tctx), im, im_hash);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
im->im_tctx = tctx;
|
2000-11-08 22:45:30 +03:00
|
|
|
im->im_flags = flags | IM_ALLOCED;
|
|
|
|
for (i = 0; i < IOP_MAX_MSG_XFERS; i++)
|
|
|
|
im->im_xfer[i].ix_size = 0;
|
|
|
|
*imp = im;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free a message wrapper.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
iop_msg_free(struct iop_softc *sc, struct iop_initiator *ii, struct iop_msg *im)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((im->im_flags & IM_ALLOCED) == 0)
|
|
|
|
panic("iop_msg_free: wrapper not allocated");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, im->im_xfer[0].ix_map);
|
|
|
|
|
|
|
|
s = splbio(); /* XXX */
|
|
|
|
|
|
|
|
if ((im->im_flags & (IM_DISCARD | IM_NOICTX)) == 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
TAILQ_REMOVE(IOP_TCTXHASH(im->im_tctx), im, im_hash);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
im->im_flags = 0;
|
|
|
|
pool_put(iop_msgpool, im);
|
|
|
|
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
|
|
|
|
iop_msg_map(struct iop_softc *sc, struct iop_msg *im, void *xferaddr,
|
|
|
|
int xfersize, int out)
|
|
|
|
{
|
|
|
|
struct iop_xfer *ix;
|
|
|
|
u_int32_t *mb;
|
2000-12-03 16:17:03 +03:00
|
|
|
int rv, seg, i;
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
for (i = 0, ix = im->im_xfer; i < IOP_MAX_MSG_XFERS; i++, ix++)
|
|
|
|
if (ix->ix_size == 0)
|
|
|
|
break;
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (i == IOP_MAX_MSG_XFERS)
|
|
|
|
panic("iop_msg_map: too many xfers");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Only the first DMA map is static. */
|
|
|
|
if (i != 0) {
|
|
|
|
rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,
|
|
|
|
IOP_MAX_SGL_ENTRIES, IOP_MAX_XFER, 0,
|
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ix->ix_map);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
ix->ix_flags = (out ? IX_OUT : IX_IN);
|
2000-11-08 22:45:30 +03:00
|
|
|
ix->ix_size = xfersize;
|
|
|
|
|
|
|
|
rv = bus_dmamap_load(sc->sc_dmat, ix->ix_map, xferaddr, xfersize,
|
|
|
|
NULL, 0);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ix->ix_map, 0, xfersize,
|
|
|
|
out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);
|
|
|
|
|
|
|
|
mb = im->im_msg + (im->im_msg[0] >> 16);
|
|
|
|
if (out)
|
|
|
|
out = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;
|
|
|
|
else
|
|
|
|
out = I2O_SGL_SIMPLE;
|
|
|
|
|
|
|
|
for (seg = 0; seg < ix->ix_map->dm_nsegs; seg++) {
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((seg << 1) + (im->im_msg[0] >> 16) >=
|
|
|
|
(IOP_MAX_MSG_SIZE >> 2))
|
|
|
|
panic("iop_map_xfer: message frame too large");
|
|
|
|
#endif
|
|
|
|
if (seg == ix->ix_map->dm_nsegs - 1)
|
|
|
|
out |= I2O_SGL_END_BUFFER;
|
|
|
|
*mb++ = (u_int32_t)ix->ix_map->dm_segs[seg].ds_len | out;
|
|
|
|
*mb++ = (u_int32_t)ix->ix_map->dm_segs[seg].ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2000-11-08 22:45:30 +03:00
|
|
|
im->im_msg[0] += ((im->im_msg[0] >> 16) + seg * 2) << 4;
|
2000-11-09 15:51:36 +03:00
|
|
|
im->im_flags |= IM_SGLOFFADJ;
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
im->im_msg[0] += (seg << 17);
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (i = 0, ix = im->im_xfer; i < IOP_MAX_MSG_XFERS; i++, ix++) {
|
|
|
|
if (ix->ix_size == 0)
|
2000-11-09 15:51:36 +03:00
|
|
|
break;
|
2000-11-08 22:45:30 +03:00
|
|
|
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);
|
|
|
|
|
|
|
|
ix->ix_size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a message to the IOP. Optionally, poll on completion. Return
|
|
|
|
* non-zero if failure status is returned and IM_NOINTR is set.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
iop_msg_send(struct iop_softc *sc, struct iop_msg *im, int timo)
|
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
u_int32_t mfa, rmfa;
|
2000-11-09 15:51:36 +03:00
|
|
|
int rv, status, i, s;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if ((im->im_flags & IM_NOICTX) == 0)
|
|
|
|
if (im->im_msg[3] == IOP_ICTX &&
|
|
|
|
(im->im_flags & IM_NOINTR) == 0)
|
|
|
|
panic("iop_msg_send: IOP_ICTX and !IM_NOINTR");
|
|
|
|
if ((im->im_flags & IM_DISCARD) != 0)
|
|
|
|
panic("iop_msg_send: IM_DISCARD");
|
|
|
|
#endif
|
|
|
|
|
2000-11-09 15:51:36 +03:00
|
|
|
s = splbio(); /* XXX */
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* Wait up to 250ms for an MFA. */
|
2000-12-03 16:17:03 +03:00
|
|
|
POLL(250, (mfa = iop_inl(sc, IOP_REG_IFIFO)) != IOP_MFA_EMPTY);
|
2000-11-08 22:45:30 +03:00
|
|
|
if (mfa == IOP_MFA_EMPTY) {
|
|
|
|
DPRINTF(("%s: mfa not forthcoming\n", sc->sc_dv.dv_xname));
|
2000-11-09 15:51:36 +03:00
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Perform reply queue DMA synchronisation and update counters. */
|
|
|
|
if ((im->im_flags & IM_NOICTX) == 0) {
|
|
|
|
if (sc->sc_stat.is_cur_hwqueue == 0)
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, 0,
|
|
|
|
sc->sc_rep_size, BUS_DMASYNC_PREREAD);
|
|
|
|
for (i = 0; i < IOP_MAX_MSG_XFERS; i++)
|
|
|
|
sc->sc_stat.is_bytes += im->im_xfer[i].ix_size;
|
|
|
|
sc->sc_stat.is_requests++;
|
|
|
|
if (++sc->sc_stat.is_cur_hwqueue > sc->sc_stat.is_peak_hwqueue)
|
|
|
|
sc->sc_stat.is_peak_hwqueue =
|
|
|
|
sc->sc_stat.is_cur_hwqueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate scatter/gather lists. */
|
|
|
|
if ((im->im_flags & IM_SGLOFFADJ) != 0)
|
|
|
|
im->im_msg[(im->im_msg[0] >> 16) - 2] |= I2O_SGL_END;
|
|
|
|
|
|
|
|
/* Post the message frame. */
|
|
|
|
bus_space_write_region_4(sc->sc_iot, sc->sc_ioh, mfa,
|
|
|
|
im->im_msg, im->im_msg[0] >> 16);
|
2000-12-03 16:17:03 +03:00
|
|
|
bus_space_barrier(sc->sc_iot, sc->sc_ioh, mfa,
|
|
|
|
(im->im_msg[0] >> 14) & ~3, BUS_SPACE_BARRIER_WRITE);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* Post the MFA back to the IOP, thus starting the command. */
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_IFIFO, mfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
if (timo == 0) {
|
2000-11-09 15:51:36 +03:00
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
if (rmfa != IOP_MFA_EMPTY)
|
|
|
|
status = iop_handle_reply(sc, rmfa);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
if ((im->im_flags & IM_REPLIED) != 0)
|
|
|
|
break;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
|
2000-11-09 15:51:36 +03:00
|
|
|
splx(s);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
if (timo == 0) {
|
2000-12-03 16:17:03 +03:00
|
|
|
#ifdef I2ODEBUG
|
|
|
|
printf("%s: poll - no reply\n", sc->sc_dv.dv_xname);
|
|
|
|
if (iop_status_get(sc) != 0)
|
|
|
|
printf("iop_msg_send: unable to retrieve status\n");
|
|
|
|
else
|
|
|
|
printf("iop_msg_send: IOP state = %d\n",
|
|
|
|
(le32toh(sc->sc_status.segnumber) >> 16) & 0xff);
|
|
|
|
#endif
|
2000-11-08 22:45:30 +03:00
|
|
|
rv = EBUSY;
|
|
|
|
} else if ((im->im_flags & IM_NOINTR) != 0)
|
|
|
|
rv = (status != I2O_STATUS_SUCCESS ? EIO : 0);
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to post a message to the adapter; if that's not possible, enqueue it
|
2000-12-03 16:17:03 +03:00
|
|
|
* with us. If a timeout is specified, wait for the message to complete.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
|
|
|
int
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_msg_enqueue(struct iop_softc *sc, struct iop_msg *im, int timo)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
|
|
|
u_int mfa;
|
2000-12-03 16:17:03 +03:00
|
|
|
int s, fromqueue, i, rv;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (im == NULL)
|
|
|
|
panic("iop_msg_enqueue: im == NULL");
|
|
|
|
if (sc == NULL)
|
|
|
|
panic("iop_msg_enqueue: sc == NULL");
|
|
|
|
if ((im->im_flags & IM_NOICTX) != 0)
|
|
|
|
panic("iop_msg_enqueue: IM_NOICTX");
|
|
|
|
if (im->im_msg[3] == IOP_ICTX && (im->im_flags & IM_NOINTR) == 0)
|
2000-12-03 16:17:03 +03:00
|
|
|
panic("iop_msg_enqueue: IOP_ICTX and no IM_NOINTR");
|
|
|
|
if ((im->im_flags & IM_DISCARD) != 0 && timo != 0)
|
|
|
|
panic("iop_msg_enqueue: IM_DISCARD && timo != 0");
|
|
|
|
if ((im->im_flags & IM_NOINTR) == 0 && timo != 0)
|
|
|
|
panic("iop_msg_enqueue: !IM_NOINTR && timo != 0");
|
2000-11-08 22:45:30 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
s = splbio(); /* XXX */
|
|
|
|
fromqueue = (im == SIMPLEQ_FIRST(&sc->sc_queue));
|
|
|
|
|
|
|
|
if (sc->sc_stat.is_cur_hwqueue >= sc->sc_maxqueuecnt) {
|
|
|
|
/*
|
|
|
|
* While the IOP may be able to accept more inbound message
|
|
|
|
* frames than it advertises, don't push harder than it
|
|
|
|
* wants to go lest we starve it.
|
|
|
|
*
|
|
|
|
* XXX We should be handling IOP resource shortages.
|
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
mfa = IOP_MFA_EMPTY;
|
|
|
|
DPRINTF(("iop_msg_enqueue: exceeded max queue count\n"));
|
2000-11-08 22:45:30 +03:00
|
|
|
} else {
|
|
|
|
/* Double read to account for IOP bug. */
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((mfa = iop_inl(sc, IOP_REG_IFIFO)) == IOP_MFA_EMPTY)
|
|
|
|
mfa = iop_inl(sc, IOP_REG_IFIFO);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mfa == IOP_MFA_EMPTY) {
|
2000-12-03 16:17:03 +03:00
|
|
|
DPRINTF(("iop_msg_enqueue: no mfa\n"));
|
2000-11-08 22:45:30 +03:00
|
|
|
/* Can't transfer to h/w queue - queue with us. */
|
|
|
|
if (!fromqueue) {
|
|
|
|
SIMPLEQ_INSERT_TAIL(&sc->sc_queue, im, im_queue);
|
|
|
|
if (++sc->sc_stat.is_cur_swqueue >
|
|
|
|
sc->sc_stat.is_peak_swqueue)
|
|
|
|
sc->sc_stat.is_peak_swqueue =
|
|
|
|
sc->sc_stat.is_cur_swqueue;
|
|
|
|
}
|
|
|
|
splx(s);
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((im->im_flags & IM_NOINTR) != 0)
|
|
|
|
rv = iop_msg_wait(sc, im, timo);
|
|
|
|
else
|
|
|
|
rv = 0;
|
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
} else if (fromqueue) {
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&sc->sc_queue, im, im_queue);
|
|
|
|
sc->sc_stat.is_cur_swqueue--;
|
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((im->im_flags & IM_NOINTR) != 0)
|
|
|
|
im->im_flags |= IM_WAITING;
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
/* Perform reply queue DMA synchronisation and update counters. */
|
|
|
|
if (sc->sc_stat.is_cur_hwqueue == 0)
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_rep_dmamap, 0,
|
|
|
|
sc->sc_rep_size, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
for (i = 0; i < IOP_MAX_MSG_XFERS; i++)
|
|
|
|
sc->sc_stat.is_bytes += im->im_xfer[i].ix_size;
|
|
|
|
sc->sc_stat.is_requests++;
|
|
|
|
if (++sc->sc_stat.is_cur_hwqueue > sc->sc_stat.is_peak_hwqueue)
|
|
|
|
sc->sc_stat.is_peak_hwqueue = sc->sc_stat.is_cur_hwqueue;
|
|
|
|
|
|
|
|
/* Terminate the scatter/gather list. */
|
|
|
|
if ((im->im_flags & IM_SGLOFFADJ) != 0)
|
|
|
|
im->im_msg[(im->im_msg[0] >> 16) - 2] |= I2O_SGL_END;
|
|
|
|
|
|
|
|
/* Post the message frame. */
|
|
|
|
bus_space_write_region_4(sc->sc_iot, sc->sc_ioh, mfa,
|
|
|
|
im->im_msg, im->im_msg[0] >> 16);
|
2000-12-03 16:17:03 +03:00
|
|
|
bus_space_barrier(sc->sc_iot, sc->sc_ioh, mfa,
|
|
|
|
(im->im_msg[0] >> 14) & ~3, BUS_SPACE_BARRIER_WRITE);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* Post the MFA back to the IOP, thus starting the command. */
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, IOP_REG_IFIFO, mfa);
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
/* If this is a discardable message wrapper, free it. */
|
|
|
|
if ((im->im_flags & IM_DISCARD) != 0)
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
splx(s);
|
2000-12-03 16:17:03 +03:00
|
|
|
|
|
|
|
if ((im->im_flags & IM_NOINTR) != 0)
|
|
|
|
rv = iop_msg_wait(sc, im, timo);
|
|
|
|
else
|
|
|
|
rv = 0;
|
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Wait for the specified message to complete.
|
2000-11-08 22:45:30 +03:00
|
|
|
*/
|
2000-12-03 16:17:03 +03:00
|
|
|
static int
|
2000-11-08 22:45:30 +03:00
|
|
|
iop_msg_wait(struct iop_softc *sc, struct iop_msg *im, int timo)
|
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_reply *rb;
|
|
|
|
int rv, s;
|
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);
|
2000-11-08 22:45:30 +03:00
|
|
|
return (0);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|
|
|
|
rv = tsleep(im, PRIBIO, "iopmsg", timo * hz / 1000);
|
|
|
|
splx(s);
|
|
|
|
#ifdef I2ODEBUG
|
|
|
|
if (rv != 0) {
|
|
|
|
printf("iop_msg_wait: tsleep() == %d\n", rv);
|
|
|
|
if (iop_status_get(sc) != 0)
|
|
|
|
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
|
|
|
|
if ((im->im_flags & (IM_REPLIED | IM_NOSTATUS)) == IM_REPLIED) {
|
|
|
|
rb = (struct i2o_reply *)im->im_msg;
|
|
|
|
rv = (rb->reqstatus != I2O_STATUS_SUCCESS ? EIO : 0);
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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. */
|
2000-12-03 16:17:03 +03:00
|
|
|
iop_outl(sc, mfa, I2O_VERSION_11 | (4 << 16));
|
|
|
|
iop_outl(sc, mfa + 4, I2O_MSGFUNC(I2O_TID_IOP, I2O_UTIL_NOP));
|
|
|
|
iop_outl(sc, mfa + 8, 0);
|
|
|
|
iop_outl(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
|
|
|
|
/*
|
|
|
|
* Print status information from a failure reply frame.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
iop_reply_print(struct iop_softc *sc, struct iop_msg *im,
|
|
|
|
struct i2o_reply *rb)
|
|
|
|
{
|
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
|
|
|
if (im != NULL && (im->im_flags & IM_REPLIED) == 0)
|
2000-11-08 22:45:30 +03:00
|
|
|
panic("iop_msg_print_status: %p not replied to", im);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/*
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
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,
|
|
|
|
int flags)
|
2000-11-08 22:45:30 +03:00
|
|
|
{
|
2000-12-03 16:17:03 +03:00
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_claim *mb;
|
|
|
|
int rv, func;
|
|
|
|
|
|
|
|
func = release ? I2O_UTIL_CLAIM_RELEASE : I2O_UTIL_CLAIM;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, ii, &im, IM_NOINTR)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
/* We can use the same structure, as both are identical. */
|
|
|
|
mb = (struct i2o_util_claim *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_util_claim);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(ii->ii_tid, func);
|
|
|
|
mb->msgictx = ii->ii_ictx;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
mb->flags = flags;
|
|
|
|
|
|
|
|
rv = iop_msg_enqueue(sc, im, 5000);
|
|
|
|
iop_msg_free(sc, ii, im);
|
|
|
|
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,
|
|
|
|
int tctxabort, int flags)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_abort *mb;
|
|
|
|
int rv;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((rv = iop_msg_alloc(sc, ii, &im, IM_NOINTR)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_util_abort *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_util_abort);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_ABORT);
|
|
|
|
mb->msgictx = ii->ii_ictx;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
mb->flags = (func << 24) | flags;
|
|
|
|
mb->tctxabort = tctxabort;
|
|
|
|
|
|
|
|
rv = iop_msg_enqueue(sc, im, 5000);
|
|
|
|
iop_msg_free(sc, ii, im);
|
|
|
|
return (rv);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-03 16:17:03 +03:00
|
|
|
* Enable or disable event types 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)
|
|
|
|
{
|
|
|
|
struct iop_msg *im;
|
|
|
|
struct i2o_util_event_register *mb;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if ((rv = iop_msg_alloc(sc, ii, &im, 0)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
mb = (struct i2o_util_event_register *)im->im_msg;
|
|
|
|
mb->msgflags = I2O_MSGFLAGS(i2o_util_event_register);
|
|
|
|
mb->msgfunc = I2O_MSGFUNC(ii->ii_tid, I2O_UTIL_EVENT_REGISTER);
|
|
|
|
mb->msgictx = ii->ii_ictx;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
mb->eventmask = mask;
|
|
|
|
|
|
|
|
return (iop_msg_enqueue(sc, im, 0));
|
|
|
|
}
|
|
|
|
|
2000-11-08 22:45:30 +03:00
|
|
|
int
|
2000-12-03 16:17:03 +03: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;
|
|
|
|
int unit, error;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
|
|
|
|
sc = device_lookup(&iop_cd, minor(dev));
|
|
|
|
if ((sc = iop_cd.cd_devs[unit]) == NULL)
|
2000-11-08 22:45:30 +03:00
|
|
|
return (ENXIO);
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((sc->sc_flags & IOP_OPEN) != 0)
|
|
|
|
return (EBUSY);
|
|
|
|
if ((sc->sc_flags & IOP_ONLINE) == 0)
|
|
|
|
return (EIO);
|
|
|
|
sc->sc_flags |= IOP_OPEN;
|
|
|
|
|
|
|
|
return (0);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
int
|
|
|
|
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));
|
|
|
|
sc->sc_flags &= ~IOP_OPEN;
|
|
|
|
return (0);
|
2000-11-08 22:45:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-12-03 16:17:03 +03: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;
|
|
|
|
struct ioppt *pt;
|
2000-11-08 22:45:30 +03:00
|
|
|
struct iop_msg *im;
|
2000-12-03 16:17:03 +03:00
|
|
|
struct i2o_msg *mb;
|
|
|
|
struct i2o_reply *rb;
|
|
|
|
int rv, i;
|
|
|
|
|
|
|
|
if (securelevel >= 2)
|
|
|
|
return (EPERM);
|
|
|
|
|
|
|
|
sc = device_lookup(&iop_cd, minor(dev));
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case IOPIOCPT:
|
|
|
|
pt = (struct ioppt *)data;
|
|
|
|
|
|
|
|
if (pt->pt_msglen > IOP_MAX_MSG_SIZE ||
|
|
|
|
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) {
|
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
rv = iop_msg_alloc(sc, NULL, &im, IM_NOINTR | IM_NOSTATUS);
|
|
|
|
if (rv != 0)
|
|
|
|
break;
|
2000-11-08 22:45:30 +03:00
|
|
|
|
2000-12-03 16:17:03 +03:00
|
|
|
if ((rv = copyin(pt->pt_msg, im->im_msg, pt->pt_msglen)) != 0) {
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb = (struct i2o_msg *)im->im_msg;
|
|
|
|
mb->msgictx = IOP_ICTX;
|
|
|
|
mb->msgtctx = im->im_tctx;
|
|
|
|
|
|
|
|
for (i = 0; i < pt->pt_nbufs; i++) {
|
|
|
|
rv = iop_msg_map(sc, im, pt->pt_bufs[i].ptb_data,
|
|
|
|
pt->pt_bufs[i].ptb_datalen,
|
|
|
|
pt->pt_bufs[i].ptb_out != 0);
|
|
|
|
if (rv != 0) {
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = iop_msg_enqueue(sc, im, pt->pt_timo)) == 0) {
|
|
|
|
rb = (struct i2o_reply *)im->im_msg;
|
|
|
|
i = (le32toh(rb->msgflags) >> 14) & ~3; /* XXX */
|
|
|
|
if (i > IOP_MAX_REPLY_SIZE)
|
|
|
|
i = IOP_MAX_REPLY_SIZE;
|
|
|
|
if (i > pt->pt_replylen)
|
|
|
|
i = pt->pt_replylen;
|
|
|
|
rv = copyout(rb, pt->pt_reply, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
iop_msg_free(sc, NULL, im);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IOPIOCGLCT:
|
|
|
|
iov = (struct iovec *)data;
|
|
|
|
rv = lockmgr(&sc->sc_conflock, LK_EXCLUSIVE, NULL);
|
|
|
|
if (rv == 0) {
|
|
|
|
i = le16toh(sc->sc_lct->tablesize) << 2;
|
|
|
|
if (i > iov->iov_len)
|
|
|
|
i = iov->iov_len;
|
|
|
|
else
|
|
|
|
iov->iov_len = i;
|
|
|
|
rv = copyout(sc->sc_lct, iov->iov_base, i);
|
|
|
|
lockmgr(&sc->sc_conflock, LK_RELEASE, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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)
|
|
|
|
rv = copyout(&sc->sc_status, iov->iov_base, i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IOPIOCRECONFIG:
|
|
|
|
rv = iop_reconfigure(sc, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#if defined(DIAGNOSTIC) || defined(I2ODEBUG)
|
|
|
|
printf("%s: unknown ioctl %lx\n", sc->sc_dv.dv_xname, cmd);
|
|
|
|
#endif
|
|
|
|
rv = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-08 22:45:30 +03:00
|
|
|
|
|
|
|
return (rv);
|
2000-12-03 16:17:03 +03:00
|
|
|
}
|