Home | History | Annotate | Line # | Download | only in i2o
dpti.c revision 1.3.4.2
      1  1.3.4.2  thorpej /*	$NetBSD: dpti.c,v 1.3.4.2 2002/01/10 19:53:59 thorpej Exp $	*/
      2  1.3.4.2  thorpej 
      3  1.3.4.2  thorpej /*-
      4  1.3.4.2  thorpej  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.3.4.2  thorpej  * All rights reserved.
      6  1.3.4.2  thorpej  *
      7  1.3.4.2  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.3.4.2  thorpej  * by Andrew Doran.
      9  1.3.4.2  thorpej  *
     10  1.3.4.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.3.4.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.3.4.2  thorpej  * are met:
     13  1.3.4.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.3.4.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.3.4.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.3.4.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.3.4.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.3.4.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.3.4.2  thorpej  *    must display the following acknowledgement:
     20  1.3.4.2  thorpej  *        This product includes software developed by the NetBSD
     21  1.3.4.2  thorpej  *        Foundation, Inc. and its contributors.
     22  1.3.4.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.3.4.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.3.4.2  thorpej  *    from this software without specific prior written permission.
     25  1.3.4.2  thorpej  *
     26  1.3.4.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.3.4.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.3.4.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.3.4.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.3.4.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.3.4.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.3.4.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.3.4.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.3.4.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.3.4.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.3.4.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.3.4.2  thorpej  */
     38  1.3.4.2  thorpej 
     39  1.3.4.2  thorpej /*
     40  1.3.4.2  thorpej  * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
     41  1.3.4.2  thorpej  * Copyright (c) 2000 Adaptec Corporation
     42  1.3.4.2  thorpej  * All rights reserved.
     43  1.3.4.2  thorpej  *
     44  1.3.4.2  thorpej  * TERMS AND CONDITIONS OF USE
     45  1.3.4.2  thorpej  *
     46  1.3.4.2  thorpej  * Redistribution and use in source form, with or without modification, are
     47  1.3.4.2  thorpej  * permitted provided that redistributions of source code must retain the
     48  1.3.4.2  thorpej  * above copyright notice, this list of conditions and the following disclaimer.
     49  1.3.4.2  thorpej  *
     50  1.3.4.2  thorpej  * This software is provided `as is' by Adaptec and any express or implied
     51  1.3.4.2  thorpej  * warranties, including, but not limited to, the implied warranties of
     52  1.3.4.2  thorpej  * merchantability and fitness for a particular purpose, are disclaimed. In no
     53  1.3.4.2  thorpej  * event shall Adaptec be liable for any direct, indirect, incidental, special,
     54  1.3.4.2  thorpej  * exemplary or consequential damages (including, but not limited to,
     55  1.3.4.2  thorpej  * procurement of substitute goods or services; loss of use, data, or profits;
     56  1.3.4.2  thorpej  * or business interruptions) however caused and on any theory of liability,
     57  1.3.4.2  thorpej  * whether in contract, strict liability, or tort (including negligence or
     58  1.3.4.2  thorpej  * otherwise) arising in any way out of the use of this driver software, even
     59  1.3.4.2  thorpej  * if advised of the possibility of such damage.
     60  1.3.4.2  thorpej  */
     61  1.3.4.2  thorpej 
     62  1.3.4.2  thorpej /*
     63  1.3.4.2  thorpej  * Adaptec/DPT I2O control interface.
     64  1.3.4.2  thorpej  */
     65  1.3.4.2  thorpej 
     66  1.3.4.2  thorpej #include <sys/cdefs.h>
     67  1.3.4.2  thorpej __KERNEL_RCSID(0, "$NetBSD: dpti.c,v 1.3.4.2 2002/01/10 19:53:59 thorpej Exp $");
     68  1.3.4.2  thorpej 
     69  1.3.4.2  thorpej #include "opt_i2o.h"
     70  1.3.4.2  thorpej 
     71  1.3.4.2  thorpej #include <sys/param.h>
     72  1.3.4.2  thorpej #include <sys/systm.h>
     73  1.3.4.2  thorpej #include <sys/kernel.h>
     74  1.3.4.2  thorpej #include <sys/device.h>
     75  1.3.4.2  thorpej #include <sys/queue.h>
     76  1.3.4.2  thorpej #include <sys/proc.h>
     77  1.3.4.2  thorpej #include <sys/endian.h>
     78  1.3.4.2  thorpej #include <sys/malloc.h>
     79  1.3.4.2  thorpej #include <sys/conf.h>
     80  1.3.4.2  thorpej #include <sys/ioctl.h>
     81  1.3.4.2  thorpej 
     82  1.3.4.2  thorpej #include <uvm/uvm_extern.h>
     83  1.3.4.2  thorpej 
     84  1.3.4.2  thorpej #include <machine/bus.h>
     85  1.3.4.2  thorpej #ifdef i386
     86  1.3.4.2  thorpej #include <machine/pio.h>
     87  1.3.4.2  thorpej #endif
     88  1.3.4.2  thorpej 
     89  1.3.4.2  thorpej #include <dev/i2o/i2o.h>
     90  1.3.4.2  thorpej #include <dev/i2o/i2odpt.h>
     91  1.3.4.2  thorpej #include <dev/i2o/iopio.h>
     92  1.3.4.2  thorpej #include <dev/i2o/iopvar.h>
     93  1.3.4.2  thorpej #include <dev/i2o/dptivar.h>
     94  1.3.4.2  thorpej 
     95  1.3.4.2  thorpej #ifdef I2ODEBUG
     96  1.3.4.2  thorpej #define	DPRINTF(x)		printf x
     97  1.3.4.2  thorpej #else
     98  1.3.4.2  thorpej #define	DPRINTF(x)
     99  1.3.4.2  thorpej #endif
    100  1.3.4.2  thorpej 
    101  1.3.4.2  thorpej static struct dpt_sig dpti_sig = {
    102  1.3.4.2  thorpej 	{ 'd', 'P', 't', 'S', 'i', 'G'},
    103  1.3.4.2  thorpej 	SIG_VERSION,
    104  1.3.4.2  thorpej #if defined(i386)
    105  1.3.4.2  thorpej 	PROC_INTEL,
    106  1.3.4.2  thorpej #elif defined(powerpc)
    107  1.3.4.2  thorpej 	PROC_POWERPC,
    108  1.3.4.2  thorpej #elif defined(alpha)
    109  1.3.4.2  thorpej 	PROC_ALPHA,
    110  1.3.4.2  thorpej #elif defined(mips)
    111  1.3.4.2  thorpej 	PROC_MIPS,
    112  1.3.4.2  thorpej #elif defined(sparc64)
    113  1.3.4.2  thorpej 	PROC_ULTRASPARC,
    114  1.3.4.2  thorpej #endif
    115  1.3.4.2  thorpej #if defined(i386)
    116  1.3.4.2  thorpej 	PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM,
    117  1.3.4.2  thorpej #else
    118  1.3.4.2  thorpej 	0,
    119  1.3.4.2  thorpej #endif
    120  1.3.4.2  thorpej 	FT_HBADRVR,
    121  1.3.4.2  thorpej 	0,
    122  1.3.4.2  thorpej 	OEM_DPT,
    123  1.3.4.2  thorpej 	OS_FREE_BSD,	/* XXX */
    124  1.3.4.2  thorpej 	CAP_ABOVE16MB,
    125  1.3.4.2  thorpej 	DEV_ALL,
    126  1.3.4.2  thorpej 	ADF_ALL_SC5,
    127  1.3.4.2  thorpej 	0,
    128  1.3.4.2  thorpej 	0,
    129  1.3.4.2  thorpej 	DPTI_VERSION,
    130  1.3.4.2  thorpej 	DPTI_REVISION,
    131  1.3.4.2  thorpej 	DPTI_SUBREVISION,
    132  1.3.4.2  thorpej 	DPTI_MONTH,
    133  1.3.4.2  thorpej 	DPTI_DAY,
    134  1.3.4.2  thorpej 	DPTI_YEAR,
    135  1.3.4.2  thorpej 	""		/* Will be filled later */
    136  1.3.4.2  thorpej };
    137  1.3.4.2  thorpej 
    138  1.3.4.2  thorpej void	dpti_attach(struct device *, struct device *, void *);
    139  1.3.4.2  thorpej int	dpti_blinkled(struct dpti_softc *);
    140  1.3.4.2  thorpej int	dpti_ctlrinfo(struct dpti_softc *, u_long, caddr_t);
    141  1.3.4.2  thorpej int	dpti_match(struct device *, struct cfdata *, void *);
    142  1.3.4.2  thorpej int	dpti_passthrough(struct dpti_softc *, caddr_t, struct proc *);
    143  1.3.4.2  thorpej int	dpti_sysinfo(struct dpti_softc *, u_long, caddr_t);
    144  1.3.4.2  thorpej 
    145  1.3.4.2  thorpej cdev_decl(dpti);
    146  1.3.4.2  thorpej 
    147  1.3.4.2  thorpej extern struct cfdriver dpti_cd;
    148  1.3.4.2  thorpej 
    149  1.3.4.2  thorpej struct cfattach dpti_ca = {
    150  1.3.4.2  thorpej 	sizeof(struct dpti_softc), dpti_match, dpti_attach
    151  1.3.4.2  thorpej };
    152  1.3.4.2  thorpej 
    153  1.3.4.2  thorpej int
    154  1.3.4.2  thorpej dpti_match(struct device *parent, struct cfdata *match, void *aux)
    155  1.3.4.2  thorpej {
    156  1.3.4.2  thorpej 	struct iop_attach_args *ia;
    157  1.3.4.2  thorpej 	struct iop_softc *iop;
    158  1.3.4.2  thorpej 
    159  1.3.4.2  thorpej 	ia = aux;
    160  1.3.4.2  thorpej 	iop = (struct iop_softc *)parent;
    161  1.3.4.2  thorpej 
    162  1.3.4.2  thorpej 	if (ia->ia_class != I2O_CLASS_ANY || ia->ia_tid != I2O_TID_IOP)
    163  1.3.4.2  thorpej 		return (0);
    164  1.3.4.2  thorpej 
    165  1.3.4.2  thorpej 	if (le16toh(iop->sc_status.orgid) != I2O_ORG_DPT)
    166  1.3.4.2  thorpej 		return (0);
    167  1.3.4.2  thorpej 
    168  1.3.4.2  thorpej 	return (1);
    169  1.3.4.2  thorpej }
    170  1.3.4.2  thorpej 
    171  1.3.4.2  thorpej void
    172  1.3.4.2  thorpej dpti_attach(struct device *parent, struct device *self, void *aux)
    173  1.3.4.2  thorpej {
    174  1.3.4.2  thorpej 	struct iop_softc *iop;
    175  1.3.4.2  thorpej 	struct dpti_softc *sc;
    176  1.3.4.2  thorpej 	struct {
    177  1.3.4.2  thorpej 		struct	i2o_param_op_results pr;
    178  1.3.4.2  thorpej 		struct	i2o_param_read_results prr;
    179  1.3.4.2  thorpej 		struct	i2o_dpt_param_exec_iop_buffers dib;
    180  1.3.4.2  thorpej 	} __attribute__ ((__packed__)) param;
    181  1.3.4.2  thorpej 	int rv;
    182  1.3.4.2  thorpej 
    183  1.3.4.2  thorpej 	sc = (struct dpti_softc *)self;
    184  1.3.4.2  thorpej 	iop = (struct iop_softc *)parent;
    185  1.3.4.2  thorpej 
    186  1.3.4.2  thorpej 	/*
    187  1.3.4.2  thorpej 	 * Tell the world what we are.  The description in the signature
    188  1.3.4.2  thorpej 	 * must be no more than 46 bytes long (see dptivar.h).
    189  1.3.4.2  thorpej 	 */
    190  1.3.4.2  thorpej 	printf(": DPT/Adaptec RAID management interface\n");
    191  1.3.4.2  thorpej 	sprintf(dpti_sig.dsDescription, "NetBSD %s I2O OSM", osrelease);
    192  1.3.4.2  thorpej 
    193  1.3.4.2  thorpej 	rv = iop_field_get_all(iop, I2O_TID_IOP,
    194  1.3.4.2  thorpej 	    I2O_DPT_PARAM_EXEC_IOP_BUFFERS, &param,
    195  1.3.4.2  thorpej 	    sizeof(param), NULL);
    196  1.3.4.2  thorpej 	if (rv != 0)
    197  1.3.4.2  thorpej 		return;
    198  1.3.4.2  thorpej 
    199  1.3.4.2  thorpej 	sc->sc_blinkled = le32toh(param.dib.serialoutputoff) + 8;
    200  1.3.4.2  thorpej }
    201  1.3.4.2  thorpej 
    202  1.3.4.2  thorpej int
    203  1.3.4.2  thorpej dptiopen(dev_t dev, int flag, int mode, struct proc *p)
    204  1.3.4.2  thorpej {
    205  1.3.4.2  thorpej 
    206  1.3.4.2  thorpej 	if (securelevel > 1)
    207  1.3.4.2  thorpej 		return (EPERM);
    208  1.3.4.2  thorpej 	if (device_lookup(&dpti_cd, minor(dev)) == NULL)
    209  1.3.4.2  thorpej 		return (ENXIO);
    210  1.3.4.2  thorpej 
    211  1.3.4.2  thorpej 	return (0);
    212  1.3.4.2  thorpej }
    213  1.3.4.2  thorpej 
    214  1.3.4.2  thorpej int
    215  1.3.4.2  thorpej dpticlose(dev_t dev, int flag, int mode, struct proc *p)
    216  1.3.4.2  thorpej {
    217  1.3.4.2  thorpej 
    218  1.3.4.2  thorpej 	return (0);
    219  1.3.4.2  thorpej }
    220  1.3.4.2  thorpej 
    221  1.3.4.2  thorpej int
    222  1.3.4.2  thorpej dptiioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
    223  1.3.4.2  thorpej {
    224  1.3.4.2  thorpej 	struct iop_softc *iop;
    225  1.3.4.2  thorpej 	struct dpti_softc *sc;
    226  1.3.4.2  thorpej 	struct ioctl_pt *pt;
    227  1.3.4.2  thorpej 	int i, size, rv;
    228  1.3.4.2  thorpej 
    229  1.3.4.2  thorpej 	sc = device_lookup(&dpti_cd, minor(dev));
    230  1.3.4.2  thorpej 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    231  1.3.4.2  thorpej 
    232  1.3.4.2  thorpej 	/*
    233  1.3.4.2  thorpej 	 * Currently, we only take ioctls passed down from the Linux
    234  1.3.4.2  thorpej 	 * emulation layer.
    235  1.3.4.2  thorpej 	 */
    236  1.3.4.2  thorpej 	if (cmd == PTIOCLINUX) {
    237  1.3.4.2  thorpej 		pt = (struct ioctl_pt *)data;
    238  1.3.4.2  thorpej 		cmd = pt->com;
    239  1.3.4.2  thorpej 		data = pt->data;
    240  1.3.4.2  thorpej 	} else
    241  1.3.4.2  thorpej 		return (ENOTTY);
    242  1.3.4.2  thorpej 
    243  1.3.4.2  thorpej 	size = IOCPARM_LEN(cmd);
    244  1.3.4.2  thorpej 
    245  1.3.4.2  thorpej 	switch (cmd & 0xffff) {
    246  1.3.4.2  thorpej 	case DPT_SIGNATURE:
    247  1.3.4.2  thorpej 		if (size > sizeof(dpti_sig))
    248  1.3.4.2  thorpej 			size = sizeof(dpti_sig);
    249  1.3.4.2  thorpej 		memcpy(data, &dpti_sig, size);
    250  1.3.4.2  thorpej 		return (0);
    251  1.3.4.2  thorpej 
    252  1.3.4.2  thorpej 	case DPT_CTRLINFO:
    253  1.3.4.2  thorpej 		return (dpti_ctlrinfo(sc, cmd, data));
    254  1.3.4.2  thorpej 
    255  1.3.4.2  thorpej 	case DPT_SYSINFO:
    256  1.3.4.2  thorpej 		return (dpti_sysinfo(sc, cmd, data));
    257  1.3.4.2  thorpej 
    258  1.3.4.2  thorpej 	case DPT_BLINKLED:
    259  1.3.4.2  thorpej 		if ((i = dpti_blinkled(sc)) == -1)
    260  1.3.4.2  thorpej 			i = 0;
    261  1.3.4.2  thorpej 
    262  1.3.4.2  thorpej 		if (size == 0)
    263  1.3.4.2  thorpej 			return (copyout(&i, *(caddr_t *)data, sizeof(i)));
    264  1.3.4.2  thorpej 
    265  1.3.4.2  thorpej 		*(int *)data = i;
    266  1.3.4.2  thorpej 		return (0);
    267  1.3.4.2  thorpej 
    268  1.3.4.2  thorpej 	case DPT_TARGET_BUSY:
    269  1.3.4.2  thorpej 		/*
    270  1.3.4.2  thorpej 		 * XXX This is here to stop linux_machdepioctl() from
    271  1.3.4.2  thorpej 		 * whining about an unknown ioctl.  Really, it should be
    272  1.3.4.2  thorpej 		 * implemented.
    273  1.3.4.2  thorpej 		 */
    274  1.3.4.2  thorpej 		return (EIO);
    275  1.3.4.2  thorpej 
    276  1.3.4.2  thorpej 	case DPT_I2OUSRCMD:
    277  1.3.4.2  thorpej 		if (sc->sc_nactive++ >= 2)
    278  1.3.4.2  thorpej 			tsleep(&sc->sc_nactive, PRIBIO, "dptislp", 0);
    279  1.3.4.2  thorpej 
    280  1.3.4.2  thorpej 		rv = dpti_passthrough(sc, data, p);
    281  1.3.4.2  thorpej 
    282  1.3.4.2  thorpej 		sc->sc_nactive--;
    283  1.3.4.2  thorpej 		wakeup_one(&sc->sc_nactive);
    284  1.3.4.2  thorpej 		return (rv);
    285  1.3.4.2  thorpej 
    286  1.3.4.2  thorpej 	case DPT_I2ORESETCMD:
    287  1.3.4.2  thorpej 		printf("%s: I2ORESETCMD not implemented\n",
    288  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname);
    289  1.3.4.2  thorpej 		return (EOPNOTSUPP);
    290  1.3.4.2  thorpej 
    291  1.3.4.2  thorpej 	case DPT_I2ORESCANCMD:
    292  1.3.4.2  thorpej 		return (iop_reconfigure(iop, 0));
    293  1.3.4.2  thorpej 
    294  1.3.4.2  thorpej 	default:
    295  1.3.4.2  thorpej 		return (ENOTTY);
    296  1.3.4.2  thorpej 	}
    297  1.3.4.2  thorpej }
    298  1.3.4.2  thorpej 
    299  1.3.4.2  thorpej int
    300  1.3.4.2  thorpej dpti_blinkled(struct dpti_softc *sc)
    301  1.3.4.2  thorpej {
    302  1.3.4.2  thorpej 	struct iop_softc *iop;
    303  1.3.4.2  thorpej 	u_int v;
    304  1.3.4.2  thorpej 
    305  1.3.4.2  thorpej 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    306  1.3.4.2  thorpej 
    307  1.3.4.2  thorpej 	v = bus_space_read_1(iop->sc_iot, iop->sc_ioh, sc->sc_blinkled + 0);
    308  1.3.4.2  thorpej 	if (v == 0xbc) {
    309  1.3.4.2  thorpej 		v = bus_space_read_1(iop->sc_iot, iop->sc_ioh,
    310  1.3.4.2  thorpej 		    sc->sc_blinkled + 1);
    311  1.3.4.2  thorpej 		return (v);
    312  1.3.4.2  thorpej 	}
    313  1.3.4.2  thorpej 
    314  1.3.4.2  thorpej 	return (-1);
    315  1.3.4.2  thorpej }
    316  1.3.4.2  thorpej 
    317  1.3.4.2  thorpej int
    318  1.3.4.2  thorpej dpti_ctlrinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
    319  1.3.4.2  thorpej {
    320  1.3.4.2  thorpej 	struct dpt_ctlrinfo info;
    321  1.3.4.2  thorpej 	struct iop_softc *iop;
    322  1.3.4.2  thorpej 	int rv, i;
    323  1.3.4.2  thorpej 
    324  1.3.4.2  thorpej 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    325  1.3.4.2  thorpej 
    326  1.3.4.2  thorpej 	memset(&info, 0, sizeof(info));
    327  1.3.4.2  thorpej 
    328  1.3.4.2  thorpej 	info.length = sizeof(info) - sizeof(u_int16_t);
    329  1.3.4.2  thorpej 	info.drvrHBAnum = sc->sc_dv.dv_unit;
    330  1.3.4.2  thorpej 	info.baseAddr = iop->sc_memaddr;
    331  1.3.4.2  thorpej 	if ((i = dpti_blinkled(sc)) == -1)
    332  1.3.4.2  thorpej 		i = 0;
    333  1.3.4.2  thorpej 	info.blinkState = i;
    334  1.3.4.2  thorpej 	info.pciBusNum = iop->sc_pcibus;
    335  1.3.4.2  thorpej 	info.pciDeviceNum = iop->sc_pcidev;
    336  1.3.4.2  thorpej 	info.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
    337  1.3.4.2  thorpej 	info.Interrupt = 10;			/* XXX */
    338  1.3.4.2  thorpej 
    339  1.3.4.2  thorpej 	if (IOCPARM_LEN(cmd) > sizeof(*data)) {
    340  1.3.4.2  thorpej 		memcpy(data, &info, min(sizeof(info), IOCPARM_LEN(cmd)));
    341  1.3.4.2  thorpej 		rv = 0;
    342  1.3.4.2  thorpej 	} else
    343  1.3.4.2  thorpej 		rv = copyout(&info, *(caddr_t *)data, sizeof(info));
    344  1.3.4.2  thorpej 
    345  1.3.4.2  thorpej 	return (rv);
    346  1.3.4.2  thorpej }
    347  1.3.4.2  thorpej 
    348  1.3.4.2  thorpej int
    349  1.3.4.2  thorpej dpti_sysinfo(struct dpti_softc *sc, u_long cmd, caddr_t data)
    350  1.3.4.2  thorpej {
    351  1.3.4.2  thorpej 	struct dpt_sysinfo info;
    352  1.3.4.2  thorpej 	int rv;
    353  1.3.4.2  thorpej #ifdef i386
    354  1.3.4.2  thorpej 	int i, j;
    355  1.3.4.2  thorpej #endif
    356  1.3.4.2  thorpej 
    357  1.3.4.2  thorpej 	memset(&info, 0, sizeof(info));
    358  1.3.4.2  thorpej 
    359  1.3.4.2  thorpej #ifdef i386
    360  1.3.4.2  thorpej 	outb (0x70, 0x12);
    361  1.3.4.2  thorpej 	i = inb(0x71);
    362  1.3.4.2  thorpej 	j = i >> 4;
    363  1.3.4.2  thorpej 	if (i == 0x0f) {
    364  1.3.4.2  thorpej 		outb (0x70, 0x19);
    365  1.3.4.2  thorpej 		j = inb (0x71);
    366  1.3.4.2  thorpej 	}
    367  1.3.4.2  thorpej 	info.drive0CMOS = j;
    368  1.3.4.2  thorpej 
    369  1.3.4.2  thorpej 	j = i & 0x0f;
    370  1.3.4.2  thorpej 	if (i == 0x0f) {
    371  1.3.4.2  thorpej 		outb (0x70, 0x1a);
    372  1.3.4.2  thorpej 		j = inb (0x71);
    373  1.3.4.2  thorpej 	}
    374  1.3.4.2  thorpej 	info.drive1CMOS = j;
    375  1.3.4.2  thorpej 	info.processorFamily = dpti_sig.dsProcessorFamily;
    376  1.3.4.2  thorpej 
    377  1.3.4.2  thorpej 	/*
    378  1.3.4.2  thorpej 	 * Get the conventional memory size from CMOS.
    379  1.3.4.2  thorpej 	 */
    380  1.3.4.2  thorpej 	outb(0x70, 0x16);
    381  1.3.4.2  thorpej 	j = inb(0x71);
    382  1.3.4.2  thorpej 	j <<= 8;
    383  1.3.4.2  thorpej 	outb(0x70, 0x15);
    384  1.3.4.2  thorpej 	j |= inb(0x71);
    385  1.3.4.2  thorpej 	info.conventionalMemSize = j;
    386  1.3.4.2  thorpej 
    387  1.3.4.2  thorpej 	/*
    388  1.3.4.2  thorpej 	 * Get the extended memory size from CMOS.
    389  1.3.4.2  thorpej 	 */
    390  1.3.4.2  thorpej 	outb(0x70, 0x31);
    391  1.3.4.2  thorpej 	j = inb(0x71);
    392  1.3.4.2  thorpej 	j <<= 8;
    393  1.3.4.2  thorpej 	outb(0x70, 0x30);
    394  1.3.4.2  thorpej 	j |= inb(0x71);
    395  1.3.4.2  thorpej 	info.extendedMemSize = j;
    396  1.3.4.2  thorpej 
    397  1.3.4.2  thorpej 	switch (cpu_class) {
    398  1.3.4.2  thorpej 	case CPUCLASS_386:
    399  1.3.4.2  thorpej 		info.processorType = PROC_386;
    400  1.3.4.2  thorpej 		break;
    401  1.3.4.2  thorpej 	case CPUCLASS_486:
    402  1.3.4.2  thorpej 		info.processorType = PROC_486;
    403  1.3.4.2  thorpej 		break;
    404  1.3.4.2  thorpej 	case CPUCLASS_586:
    405  1.3.4.2  thorpej 		info.processorType = PROC_PENTIUM;
    406  1.3.4.2  thorpej 		break;
    407  1.3.4.2  thorpej 	case CPUCLASS_686:
    408  1.3.4.2  thorpej 	default:
    409  1.3.4.2  thorpej 		info.processorType = PROC_SEXIUM;
    410  1.3.4.2  thorpej 		break;
    411  1.3.4.2  thorpej 	}
    412  1.3.4.2  thorpej 
    413  1.3.4.2  thorpej 	info.flags = SI_CMOS_Valid | SI_BusTypeValid |
    414  1.3.4.2  thorpej 	    SI_MemorySizeValid | SI_NO_SmartROM;
    415  1.3.4.2  thorpej #else
    416  1.3.4.2  thorpej 	info.flags = SI_BusTypeValid | SI_NO_SmartROM;
    417  1.3.4.2  thorpej #endif
    418  1.3.4.2  thorpej 
    419  1.3.4.2  thorpej 	info.busType = SI_PCI_BUS;
    420  1.3.4.2  thorpej 
    421  1.3.4.2  thorpej 	/*
    422  1.3.4.2  thorpej 	 * Copy out the info structure to the user.
    423  1.3.4.2  thorpej 	 */
    424  1.3.4.2  thorpej 	if (IOCPARM_LEN(cmd) > sizeof(*data)) {
    425  1.3.4.2  thorpej 		memcpy(data, &info, min(sizeof(info), IOCPARM_LEN(cmd)));
    426  1.3.4.2  thorpej 		rv = 0;
    427  1.3.4.2  thorpej 	} else
    428  1.3.4.2  thorpej 		rv = copyout(&info, *(caddr_t *)data, sizeof(info));
    429  1.3.4.2  thorpej 
    430  1.3.4.2  thorpej 	return (rv);
    431  1.3.4.2  thorpej }
    432  1.3.4.2  thorpej 
    433  1.3.4.2  thorpej int
    434  1.3.4.2  thorpej dpti_passthrough(struct dpti_softc *sc, caddr_t data, struct proc *proc)
    435  1.3.4.2  thorpej {
    436  1.3.4.2  thorpej 	struct iop_softc *iop;
    437  1.3.4.2  thorpej 	struct i2o_msg mh, *mf;
    438  1.3.4.2  thorpej 	struct i2o_reply rh;
    439  1.3.4.2  thorpej 	struct iop_msg *im;
    440  1.3.4.2  thorpej 	struct dpti_ptbuf bufs[IOP_MAX_MSG_XFERS];
    441  1.3.4.2  thorpej 	u_int32_t mbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    442  1.3.4.2  thorpej 	u_int32_t rbtmp[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    443  1.3.4.2  thorpej 	int rv, msgsize, repsize, sgoff, i, mapped, nbuf, nfrag, j, sz;
    444  1.3.4.2  thorpej 	u_int32_t *p, *pmax, *pstart;
    445  1.3.4.2  thorpej 
    446  1.3.4.2  thorpej 	iop = (struct iop_softc *)sc->sc_dv.dv_parent;
    447  1.3.4.2  thorpej 	im = NULL;
    448  1.3.4.2  thorpej 
    449  1.3.4.2  thorpej 	if ((rv = dpti_blinkled(sc)) != -1) {
    450  1.3.4.2  thorpej 		if (rv != 0) {
    451  1.3.4.2  thorpej 			printf("%s: adapter blinkled = 0x%02x\n",
    452  1.3.4.2  thorpej 			    sc->sc_dv.dv_xname, rv);
    453  1.3.4.2  thorpej 			return (EIO);
    454  1.3.4.2  thorpej 		}
    455  1.3.4.2  thorpej 	}
    456  1.3.4.2  thorpej 
    457  1.3.4.2  thorpej 	/*
    458  1.3.4.2  thorpej 	 * Copy in the message frame header and determine the size of the
    459  1.3.4.2  thorpej 	 * full message frame.
    460  1.3.4.2  thorpej 	 */
    461  1.3.4.2  thorpej 	if ((rv = copyin(data, &mh, sizeof(mh))) != 0) {
    462  1.3.4.2  thorpej 		DPRINTF(("%s: message copyin failed\n",
    463  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    464  1.3.4.2  thorpej 		return (rv);
    465  1.3.4.2  thorpej 	}
    466  1.3.4.2  thorpej 
    467  1.3.4.2  thorpej 	msgsize = (mh.msgflags >> 14) & ~3;
    468  1.3.4.2  thorpej 	if (msgsize < sizeof(mh) || msgsize >= IOP_MAX_MSG_SIZE) {
    469  1.3.4.2  thorpej 		DPRINTF(("%s: bad message frame size\n",
    470  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    471  1.3.4.2  thorpej 		return (EINVAL);
    472  1.3.4.2  thorpej 	}
    473  1.3.4.2  thorpej 
    474  1.3.4.2  thorpej 	/*
    475  1.3.4.2  thorpej 	 * Handle special commands.
    476  1.3.4.2  thorpej 	 */
    477  1.3.4.2  thorpej 	switch (mh.msgfunc >> 24) {
    478  1.3.4.2  thorpej 	case I2O_EXEC_IOP_RESET:
    479  1.3.4.2  thorpej 		printf("%s: I2O_EXEC_IOP_RESET not implemented\n",
    480  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname);
    481  1.3.4.2  thorpej 		return (EOPNOTSUPP);
    482  1.3.4.2  thorpej 
    483  1.3.4.2  thorpej 	case I2O_EXEC_OUTBOUND_INIT:
    484  1.3.4.2  thorpej 		printf("%s: I2O_EXEC_OUTBOUND_INIT not implemented\n",
    485  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname);
    486  1.3.4.2  thorpej 		return (EOPNOTSUPP);
    487  1.3.4.2  thorpej 
    488  1.3.4.2  thorpej 	case I2O_EXEC_SYS_TAB_SET:
    489  1.3.4.2  thorpej 		printf("%s: I2O_EXEC_SYS_TAB_SET not implemented\n",
    490  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname);
    491  1.3.4.2  thorpej 		return (EOPNOTSUPP);
    492  1.3.4.2  thorpej 
    493  1.3.4.2  thorpej 	case I2O_EXEC_STATUS_GET:
    494  1.3.4.2  thorpej 		if ((rv = iop_status_get(iop, 0)) == 0)
    495  1.3.4.2  thorpej 			rv = copyout(&iop->sc_status, data + msgsize,
    496  1.3.4.2  thorpej 			    sizeof(iop->sc_status));
    497  1.3.4.2  thorpej 		return (rv);
    498  1.3.4.2  thorpej 	}
    499  1.3.4.2  thorpej 
    500  1.3.4.2  thorpej 	/*
    501  1.3.4.2  thorpej 	 * Copy in the full message frame.
    502  1.3.4.2  thorpej 	 */
    503  1.3.4.2  thorpej 	if ((rv = copyin(data, mbtmp, msgsize)) != 0) {
    504  1.3.4.2  thorpej 		DPRINTF(("%s: full message copyin failed\n",
    505  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    506  1.3.4.2  thorpej 		return (rv);
    507  1.3.4.2  thorpej 	}
    508  1.3.4.2  thorpej 
    509  1.3.4.2  thorpej 	/*
    510  1.3.4.2  thorpej 	 * Determine the size of the reply frame, and copy it in.
    511  1.3.4.2  thorpej 	 */
    512  1.3.4.2  thorpej 	if ((rv = copyin(data + msgsize, &rh, sizeof(rh))) != 0) {
    513  1.3.4.2  thorpej 		DPRINTF(("%s: reply copyin failed\n",
    514  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    515  1.3.4.2  thorpej 		return (rv);
    516  1.3.4.2  thorpej 	}
    517  1.3.4.2  thorpej 
    518  1.3.4.2  thorpej 	repsize = (rh.msgflags >> 14) & ~3;
    519  1.3.4.2  thorpej 	if (repsize < sizeof(rh) || repsize >= IOP_MAX_MSG_SIZE) {
    520  1.3.4.2  thorpej 		DPRINTF(("%s: bad reply header size\n",
    521  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    522  1.3.4.2  thorpej 		return (EINVAL);
    523  1.3.4.2  thorpej 	}
    524  1.3.4.2  thorpej 
    525  1.3.4.2  thorpej 	if ((rv = copyin(data + msgsize, rbtmp, repsize)) != 0) {
    526  1.3.4.2  thorpej 		DPRINTF(("%s: reply too large\n", sc->sc_dv.dv_xname));
    527  1.3.4.2  thorpej 		return (rv);
    528  1.3.4.2  thorpej 	}
    529  1.3.4.2  thorpej 
    530  1.3.4.2  thorpej 	/*
    531  1.3.4.2  thorpej 	 * If the message has a scatter gather list, it must be comprised of
    532  1.3.4.2  thorpej 	 * simple elements.  If any one transfer contains multiple segments,
    533  1.3.4.2  thorpej 	 * we allocate a temporary buffer for it; otherwise, the buffer will
    534  1.3.4.2  thorpej 	 * be mapped directly.
    535  1.3.4.2  thorpej 	 */
    536  1.3.4.2  thorpej 	if ((sgoff = ((mh.msgflags >> 4) & 15)) != 0) {
    537  1.3.4.2  thorpej 		if ((sgoff + 2) > (msgsize >> 2)) {
    538  1.3.4.2  thorpej 			DPRINTF(("%s: invalid message size fields\n",
    539  1.3.4.2  thorpej 			    sc->sc_dv.dv_xname));
    540  1.3.4.2  thorpej 			return (EINVAL);
    541  1.3.4.2  thorpej 		}
    542  1.3.4.2  thorpej 
    543  1.3.4.2  thorpej 		memset(bufs, 0, sizeof(bufs));
    544  1.3.4.2  thorpej 	} else
    545  1.3.4.2  thorpej 		nbuf = -1;
    546  1.3.4.2  thorpej 
    547  1.3.4.2  thorpej 	rv = EINVAL;
    548  1.3.4.2  thorpej 
    549  1.3.4.2  thorpej 	if (sgoff != 0) {
    550  1.3.4.2  thorpej 		p = mbtmp + sgoff;
    551  1.3.4.2  thorpej 		pmax = mbtmp + (msgsize >> 2) - 2;
    552  1.3.4.2  thorpej 
    553  1.3.4.2  thorpej 		for (nbuf = 0; nbuf < IOP_MAX_MSG_XFERS; nbuf++, p += 2) {
    554  1.3.4.2  thorpej 			if (p > pmax) {
    555  1.3.4.2  thorpej 				DPRINTF(("%s: invalid SGL (1)\n",
    556  1.3.4.2  thorpej 				    sc->sc_dv.dv_xname));
    557  1.3.4.2  thorpej 				goto bad;
    558  1.3.4.2  thorpej 			}
    559  1.3.4.2  thorpej 
    560  1.3.4.2  thorpej 			if ((p[0] & 0x30000000) != I2O_SGL_SIMPLE) {
    561  1.3.4.2  thorpej 				DPRINTF(("%s: invalid SGL (2)\n",
    562  1.3.4.2  thorpej 				    sc->sc_dv.dv_xname));
    563  1.3.4.2  thorpej 				goto bad;
    564  1.3.4.2  thorpej 			}
    565  1.3.4.2  thorpej 
    566  1.3.4.2  thorpej 			bufs[nbuf].db_out = (p[0] & I2O_SGL_DATA_OUT) != 0;
    567  1.3.4.2  thorpej 			bufs[nbuf].db_ptr = NULL;
    568  1.3.4.2  thorpej 
    569  1.3.4.2  thorpej 			if ((p[0] & I2O_SGL_END_BUFFER) != 0) {
    570  1.3.4.2  thorpej 				if ((p[0] & 0x00ffffff) > IOP_MAX_XFER) {
    571  1.3.4.2  thorpej 					DPRINTF(("%s: buffer too large\n",
    572  1.3.4.2  thorpej 					    sc->sc_dv.dv_xname));
    573  1.3.4.2  thorpej 					goto bad;
    574  1.3.4.2  thorpej 				}
    575  1.3.4.2  thorpej 
    576  1.3.4.2  thorpej 				bufs[nbuf].db_ptr = (caddr_t)p[1];
    577  1.3.4.2  thorpej 				bufs[nbuf].db_proc = proc;
    578  1.3.4.2  thorpej 				bufs[nbuf].db_size = p[0] & 0x00ffffff;
    579  1.3.4.2  thorpej 
    580  1.3.4.2  thorpej 				if ((p[0] & I2O_SGL_END) != 0)
    581  1.3.4.2  thorpej 					break;
    582  1.3.4.2  thorpej 
    583  1.3.4.2  thorpej 				continue;
    584  1.3.4.2  thorpej 			}
    585  1.3.4.2  thorpej 
    586  1.3.4.2  thorpej 			/*
    587  1.3.4.2  thorpej 			 * The buffer has multiple segments.  Determine the
    588  1.3.4.2  thorpej 			 * total size.
    589  1.3.4.2  thorpej 			 */
    590  1.3.4.2  thorpej 			nfrag = 0;
    591  1.3.4.2  thorpej 			sz = 0;
    592  1.3.4.2  thorpej 			for (pstart = p; p <= pmax; p += 2) {
    593  1.3.4.2  thorpej 				if (nfrag == DPTI_MAX_SEGS) {
    594  1.3.4.2  thorpej 					DPRINTF(("%s: too many segments\n",
    595  1.3.4.2  thorpej 					    sc->sc_dv.dv_xname));
    596  1.3.4.2  thorpej 					goto bad;
    597  1.3.4.2  thorpej 				}
    598  1.3.4.2  thorpej 
    599  1.3.4.2  thorpej 				bufs[nbuf].db_frags[nfrag].iov_len =
    600  1.3.4.2  thorpej 				    p[0] & 0x00ffffff;
    601  1.3.4.2  thorpej 				bufs[nbuf].db_frags[nfrag].iov_base =
    602  1.3.4.2  thorpej 				    (void *)p[1];
    603  1.3.4.2  thorpej 
    604  1.3.4.2  thorpej 				sz += p[0] & 0x00ffffff;
    605  1.3.4.2  thorpej 				nfrag++;
    606  1.3.4.2  thorpej 
    607  1.3.4.2  thorpej 				if ((p[0] & I2O_SGL_END) != 0) {
    608  1.3.4.2  thorpej 					if ((p[0] & I2O_SGL_END_BUFFER) == 0) {
    609  1.3.4.2  thorpej 						DPRINTF((
    610  1.3.4.2  thorpej 						    "%s: invalid SGL (3)\n",
    611  1.3.4.2  thorpej 						    sc->sc_dv.dv_xname));
    612  1.3.4.2  thorpej 						goto bad;
    613  1.3.4.2  thorpej 					}
    614  1.3.4.2  thorpej 					break;
    615  1.3.4.2  thorpej 				}
    616  1.3.4.2  thorpej 				if ((p[0] & I2O_SGL_END_BUFFER) != 0)
    617  1.3.4.2  thorpej 					break;
    618  1.3.4.2  thorpej 			}
    619  1.3.4.2  thorpej 			bufs[nbuf].db_nfrag = nfrag;
    620  1.3.4.2  thorpej 
    621  1.3.4.2  thorpej 			if (p > pmax) {
    622  1.3.4.2  thorpej 				DPRINTF(("%s: invalid SGL (4)\n",
    623  1.3.4.2  thorpej 				    sc->sc_dv.dv_xname));
    624  1.3.4.2  thorpej 				goto bad;
    625  1.3.4.2  thorpej 			}
    626  1.3.4.2  thorpej 
    627  1.3.4.2  thorpej 			if (sz > IOP_MAX_XFER) {
    628  1.3.4.2  thorpej 				DPRINTF(("%s: buffer too large\n",
    629  1.3.4.2  thorpej 				    sc->sc_dv.dv_xname));
    630  1.3.4.2  thorpej 				goto bad;
    631  1.3.4.2  thorpej 			}
    632  1.3.4.2  thorpej 
    633  1.3.4.2  thorpej 			bufs[nbuf].db_size = sz;
    634  1.3.4.2  thorpej 			bufs[nbuf].db_ptr = malloc(sz, M_DEVBUF, M_WAITOK);
    635  1.3.4.2  thorpej 			if (bufs[nbuf].db_ptr == NULL) {
    636  1.3.4.2  thorpej 				DPRINTF(("%s: allocation failure\n",
    637  1.3.4.2  thorpej 				    sc->sc_dv.dv_xname));
    638  1.3.4.2  thorpej 				rv = ENOMEM;
    639  1.3.4.2  thorpej 				goto bad;
    640  1.3.4.2  thorpej 			}
    641  1.3.4.2  thorpej 
    642  1.3.4.2  thorpej 			for (i = 0, sz = 0; i < bufs[nbuf].db_nfrag; i++) {
    643  1.3.4.2  thorpej 				rv = copyin(bufs[nbuf].db_frags[i].iov_base,
    644  1.3.4.2  thorpej 				    bufs[nbuf].db_ptr + sz,
    645  1.3.4.2  thorpej 				    bufs[nbuf].db_frags[i].iov_len);
    646  1.3.4.2  thorpej 				if (rv != 0) {
    647  1.3.4.2  thorpej 					DPRINTF(("%s: frag copyin\n",
    648  1.3.4.2  thorpej 					    sc->sc_dv.dv_xname));
    649  1.3.4.2  thorpej 					goto bad;
    650  1.3.4.2  thorpej 				}
    651  1.3.4.2  thorpej 				sz += bufs[nbuf].db_frags[i].iov_len;
    652  1.3.4.2  thorpej 			}
    653  1.3.4.2  thorpej 
    654  1.3.4.2  thorpej 			if ((p[0] & I2O_SGL_END) != 0)
    655  1.3.4.2  thorpej 				break;
    656  1.3.4.2  thorpej 		}
    657  1.3.4.2  thorpej 
    658  1.3.4.2  thorpej 		if (nbuf == IOP_MAX_MSG_XFERS) {
    659  1.3.4.2  thorpej 			DPRINTF(("%s: too many transfers\n",
    660  1.3.4.2  thorpej 			    sc->sc_dv.dv_xname));
    661  1.3.4.2  thorpej 			goto bad;
    662  1.3.4.2  thorpej 		}
    663  1.3.4.2  thorpej 	}
    664  1.3.4.2  thorpej 
    665  1.3.4.2  thorpej 	/*
    666  1.3.4.2  thorpej 	 * Allocate a wrapper, and adjust the message header fields to
    667  1.3.4.2  thorpej 	 * indicate that no scatter-gather list is currently present.
    668  1.3.4.2  thorpej 	 */
    669  1.3.4.2  thorpej 	mapped = 0;
    670  1.3.4.2  thorpej 
    671  1.3.4.2  thorpej 	im = iop_msg_alloc(iop, IM_WAIT | IM_NOSTATUS);
    672  1.3.4.2  thorpej 	im->im_rb = (struct i2o_reply *)rbtmp;
    673  1.3.4.2  thorpej 	mf = (struct i2o_msg *)mbtmp;
    674  1.3.4.2  thorpej 	mf->msgictx = IOP_ICTX;
    675  1.3.4.2  thorpej 	mf->msgtctx = im->im_tctx;
    676  1.3.4.2  thorpej 
    677  1.3.4.2  thorpej 	if (sgoff != 0)
    678  1.3.4.2  thorpej 		mf->msgflags = (mf->msgflags & 0xff0f) | (sgoff << 16);
    679  1.3.4.2  thorpej 
    680  1.3.4.2  thorpej 	/*
    681  1.3.4.2  thorpej 	 * Map the data transfer(s).
    682  1.3.4.2  thorpej 	 */
    683  1.3.4.2  thorpej 	for (i = 0; i <= nbuf; i++) {
    684  1.3.4.2  thorpej 		rv = iop_msg_map(iop, im, mbtmp, bufs[i].db_ptr,
    685  1.3.4.2  thorpej 		    bufs[i].db_size, bufs[i].db_out, bufs[i].db_proc);
    686  1.3.4.2  thorpej 		if (rv != 0) {
    687  1.3.4.2  thorpej 			DPRINTF(("%s: msg_map failed, rv = %d\n",
    688  1.3.4.2  thorpej 			    sc->sc_dv.dv_xname, rv));
    689  1.3.4.2  thorpej 			goto bad;
    690  1.3.4.2  thorpej 		}
    691  1.3.4.2  thorpej 		mapped = 1;
    692  1.3.4.2  thorpej 	}
    693  1.3.4.2  thorpej 
    694  1.3.4.2  thorpej 	/*
    695  1.3.4.2  thorpej 	 * Start the command and sleep until it completes.
    696  1.3.4.2  thorpej 	 */
    697  1.3.4.2  thorpej 	if ((rv = iop_msg_post(iop, im, mbtmp, 5*60*1000)) != 0)
    698  1.3.4.2  thorpej 		goto bad;
    699  1.3.4.2  thorpej 
    700  1.3.4.2  thorpej 	/*
    701  1.3.4.2  thorpej 	 * Copy out the reply frame.
    702  1.3.4.2  thorpej 	 */
    703  1.3.4.2  thorpej 	if ((rv = copyout(rbtmp, data + msgsize, repsize)) != 0)
    704  1.3.4.2  thorpej 		DPRINTF(("%s: reply copyout() failed\n",
    705  1.3.4.2  thorpej 		    sc->sc_dv.dv_xname));
    706  1.3.4.2  thorpej 
    707  1.3.4.2  thorpej  bad:
    708  1.3.4.2  thorpej 	/*
    709  1.3.4.2  thorpej 	 * Free resources and return to the caller.
    710  1.3.4.2  thorpej 	 */
    711  1.3.4.2  thorpej 	if (im != NULL) {
    712  1.3.4.2  thorpej 		if (mapped)
    713  1.3.4.2  thorpej 			iop_msg_unmap(iop, im);
    714  1.3.4.2  thorpej 		iop_msg_free(iop, im);
    715  1.3.4.2  thorpej 	}
    716  1.3.4.2  thorpej 
    717  1.3.4.2  thorpej 	for (i = 0; i <= nbuf; i++) {
    718  1.3.4.2  thorpej 		if (bufs[i].db_proc != NULL)
    719  1.3.4.2  thorpej 			continue;
    720  1.3.4.2  thorpej 
    721  1.3.4.2  thorpej 		if (!bufs[i].db_out && rv == 0) {
    722  1.3.4.2  thorpej 			for (j = 0, sz = 0; j < bufs[i].db_nfrag; j++) {
    723  1.3.4.2  thorpej 				rv = copyout(bufs[i].db_ptr + sz,
    724  1.3.4.2  thorpej 				    bufs[i].db_frags[j].iov_base,
    725  1.3.4.2  thorpej 				    bufs[i].db_frags[j].iov_len);
    726  1.3.4.2  thorpej 				if (rv != 0)
    727  1.3.4.2  thorpej 					break;
    728  1.3.4.2  thorpej 				sz += bufs[i].db_frags[j].iov_len;
    729  1.3.4.2  thorpej 			}
    730  1.3.4.2  thorpej 		}
    731  1.3.4.2  thorpej 
    732  1.3.4.2  thorpej 		if (bufs[i].db_ptr != NULL)
    733  1.3.4.2  thorpej 			free(bufs[i].db_ptr, M_DEVBUF);
    734  1.3.4.2  thorpej 	}
    735  1.3.4.2  thorpej 
    736  1.3.4.2  thorpej 	return (rv);
    737  1.3.4.2  thorpej }
    738