Home | History | Annotate | Line # | Download | only in i2o
ld_iop.c revision 1.10
      1  1.10  lukem /*	$NetBSD: ld_iop.c,v 1.10 2001/11/13 12:24:59 lukem Exp $	*/
      2   1.1     ad 
      3   1.1     ad /*-
      4   1.6     ad  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
      5   1.1     ad  * All rights reserved.
      6   1.1     ad  *
      7   1.1     ad  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1     ad  * by Andrew Doran.
      9   1.1     ad  *
     10   1.1     ad  * Redistribution and use in source and binary forms, with or without
     11   1.1     ad  * modification, are permitted provided that the following conditions
     12   1.1     ad  * are met:
     13   1.1     ad  * 1. Redistributions of source code must retain the above copyright
     14   1.1     ad  *    notice, this list of conditions and the following disclaimer.
     15   1.1     ad  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1     ad  *    notice, this list of conditions and the following disclaimer in the
     17   1.1     ad  *    documentation and/or other materials provided with the distribution.
     18   1.1     ad  * 3. All advertising materials mentioning features or use of this software
     19   1.1     ad  *    must display the following acknowledgement:
     20   1.1     ad  *        This product includes software developed by the NetBSD
     21   1.1     ad  *        Foundation, Inc. and its contributors.
     22   1.1     ad  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1     ad  *    contributors may be used to endorse or promote products derived
     24   1.1     ad  *    from this software without specific prior written permission.
     25   1.1     ad  *
     26   1.1     ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1     ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1     ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1     ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1     ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1     ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1     ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1     ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1     ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1     ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1     ad  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1     ad  */
     38   1.1     ad 
     39   1.1     ad /*
     40   1.1     ad  * I2O front-end for ld(4) driver, supporting random block storage class
     41   1.2     ad  * devices.  Currently, this doesn't handle anything more complex than
     42   1.2     ad  * fixed direct-access devices.
     43   1.1     ad  */
     44  1.10  lukem 
     45  1.10  lukem #include <sys/cdefs.h>
     46  1.10  lukem __KERNEL_RCSID(0, "$NetBSD: ld_iop.c,v 1.10 2001/11/13 12:24:59 lukem Exp $");
     47   1.1     ad 
     48   1.1     ad #include "opt_i2o.h"
     49   1.1     ad #include "rnd.h"
     50   1.1     ad 
     51   1.1     ad #include <sys/param.h>
     52   1.1     ad #include <sys/systm.h>
     53   1.1     ad #include <sys/kernel.h>
     54   1.1     ad #include <sys/device.h>
     55   1.1     ad #include <sys/buf.h>
     56   1.1     ad #include <sys/endian.h>
     57   1.1     ad #include <sys/dkio.h>
     58   1.1     ad #include <sys/disk.h>
     59   1.1     ad #include <sys/proc.h>
     60   1.1     ad #if NRND > 0
     61   1.1     ad #include <sys/rnd.h>
     62   1.1     ad #endif
     63   1.1     ad 
     64   1.1     ad #include <machine/bus.h>
     65   1.1     ad 
     66   1.1     ad #include <dev/ldvar.h>
     67   1.1     ad 
     68   1.1     ad #include <dev/i2o/i2o.h>
     69   1.6     ad #include <dev/i2o/iopio.h>
     70   1.1     ad #include <dev/i2o/iopvar.h>
     71   1.1     ad 
     72   1.6     ad #define	LD_IOP_TIMEOUT		30*1000
     73   1.6     ad 
     74   1.6     ad #define	LD_IOP_CLAIMED		0x01
     75   1.6     ad #define	LD_IOP_NEW_EVTMASK	0x02
     76   1.1     ad 
     77   1.1     ad struct ld_iop_softc {
     78   1.1     ad 	struct	ld_softc sc_ld;
     79   1.1     ad 	struct	iop_initiator sc_ii;
     80   1.2     ad 	struct	iop_initiator sc_eventii;
     81   1.6     ad 	int	sc_flags;
     82   1.1     ad };
     83   1.1     ad 
     84   1.6     ad static void	ld_iop_adjqparam(struct device *, int);
     85   1.1     ad static void	ld_iop_attach(struct device *, struct device *, void *);
     86   1.2     ad static int	ld_iop_detach(struct device *, int);
     87   1.1     ad static int	ld_iop_dump(struct ld_softc *, void *, int, int);
     88   1.1     ad static int	ld_iop_flush(struct ld_softc *);
     89   1.1     ad static void	ld_iop_intr(struct device *, struct iop_msg *, void *);
     90   1.2     ad static void	ld_iop_intr_event(struct device *, struct iop_msg *, void *);
     91   1.6     ad static int	ld_iop_match(struct device *, struct cfdata *, void *);
     92   1.1     ad static int	ld_iop_start(struct ld_softc *, struct buf *);
     93   1.6     ad static void	ld_iop_unconfig(struct ld_iop_softc *, int);
     94   1.1     ad 
     95   1.1     ad struct cfattach ld_iop_ca = {
     96   1.2     ad 	sizeof(struct ld_iop_softc),
     97   1.2     ad 	ld_iop_match,
     98   1.2     ad 	ld_iop_attach,
     99   1.2     ad 	ld_iop_detach
    100   1.1     ad };
    101   1.1     ad 
    102   1.1     ad #ifdef I2OVERBOSE
    103   1.6     ad static const char * const ld_iop_errors[] = {
    104   1.1     ad 	"success",
    105   1.1     ad 	"media error",
    106   1.6     ad 	"access error",
    107   1.1     ad 	"device failure",
    108   1.6     ad 	"device not ready",
    109   1.1     ad 	"media not present",
    110   1.6     ad 	"media locked",
    111   1.1     ad 	"media failure",
    112   1.6     ad 	"protocol failure",
    113   1.6     ad 	"bus failure",
    114   1.6     ad 	"access violation",
    115   1.6     ad 	"media write protected",
    116   1.1     ad 	"device reset",
    117   1.6     ad 	"volume changed, waiting for acknowledgement",
    118   1.6     ad 	"timeout",
    119   1.1     ad };
    120   1.1     ad #endif
    121   1.1     ad 
    122   1.1     ad static int
    123   1.1     ad ld_iop_match(struct device *parent, struct cfdata *match, void *aux)
    124   1.1     ad {
    125   1.1     ad 	struct iop_attach_args *ia;
    126   1.1     ad 
    127   1.1     ad 	ia = aux;
    128   1.1     ad 
    129   1.3     ad 	return (ia->ia_class == I2O_CLASS_RANDOM_BLOCK_STORAGE);
    130   1.1     ad }
    131   1.1     ad 
    132   1.1     ad static void
    133   1.1     ad ld_iop_attach(struct device *parent, struct device *self, void *aux)
    134   1.1     ad {
    135   1.1     ad 	struct iop_attach_args *ia;
    136   1.1     ad 	struct ld_softc *ld;
    137   1.1     ad 	struct ld_iop_softc *sc;
    138   1.1     ad 	struct iop_softc *iop;
    139   1.2     ad 	int rv, evreg, enable;
    140   1.6     ad 	char *typestr, *fixedstr;
    141   1.1     ad 	u_int cachesz;
    142   1.9     ad 	u_int32_t timeoutbase, rwvtimeoutbase, rwvtimeout;
    143   1.1     ad 	struct {
    144   1.1     ad 		struct	i2o_param_op_results pr;
    145   1.1     ad 		struct	i2o_param_read_results prr;
    146   1.1     ad 		union {
    147   1.1     ad 			struct	i2o_param_rbs_cache_control cc;
    148   1.1     ad 			struct	i2o_param_rbs_device_info bdi;
    149   1.1     ad 		} p;
    150   1.8     ad 	} __attribute__ ((__packed__)) param;
    151   1.1     ad 
    152   1.1     ad 	sc = (struct ld_iop_softc *)self;
    153   1.1     ad 	ld = &sc->sc_ld;
    154   1.1     ad 	iop = (struct iop_softc *)parent;
    155   1.1     ad 	ia = (struct iop_attach_args *)aux;
    156   1.2     ad 	evreg = 0;
    157   1.1     ad 
    158   1.1     ad 	/* Register us as an initiator. */
    159   1.1     ad 	sc->sc_ii.ii_dv = self;
    160   1.1     ad 	sc->sc_ii.ii_intr = ld_iop_intr;
    161   1.6     ad 	sc->sc_ii.ii_adjqparam = ld_iop_adjqparam;
    162   1.1     ad 	sc->sc_ii.ii_flags = 0;
    163   1.2     ad 	sc->sc_ii.ii_tid = ia->ia_tid;
    164   1.6     ad 	iop_initiator_register(iop, &sc->sc_ii);
    165   1.1     ad 
    166   1.2     ad 	/* Register another initiator to handle events from the device. */
    167   1.2     ad 	sc->sc_eventii.ii_dv = self;
    168   1.2     ad 	sc->sc_eventii.ii_intr = ld_iop_intr_event;
    169   1.8     ad 	sc->sc_eventii.ii_flags = II_NOTCTX | II_UTILITY;
    170   1.2     ad 	sc->sc_eventii.ii_tid = ia->ia_tid;
    171   1.6     ad 	iop_initiator_register(iop, &sc->sc_eventii);
    172   1.6     ad 
    173   1.6     ad 	rv = iop_util_eventreg(iop, &sc->sc_eventii,
    174   1.6     ad 	    I2O_EVENT_GEN_EVENT_MASK_MODIFIED |
    175   1.6     ad 	    I2O_EVENT_GEN_DEVICE_RESET |
    176   1.6     ad 	    I2O_EVENT_GEN_STATE_CHANGE |
    177   1.6     ad 	    I2O_EVENT_GEN_GENERAL_WARNING);
    178   1.6     ad 	if (rv != 0) {
    179   1.2     ad 		printf("%s: unable to register for events", self->dv_xname);
    180   1.2     ad 		goto bad;
    181   1.2     ad 	}
    182   1.2     ad 	evreg = 1;
    183   1.2     ad 
    184   1.6     ad 	/*
    185   1.6     ad 	 * Start out with one queued command.  The `iop' driver will adjust
    186   1.6     ad 	 * the queue parameters once we're up and running.
    187   1.6     ad 	 */
    188   1.6     ad 	ld->sc_maxqueuecnt = 1;
    189   1.6     ad 
    190   1.1     ad 	ld->sc_maxxfer = IOP_MAX_XFER;
    191   1.1     ad 	ld->sc_dump = ld_iop_dump;
    192   1.1     ad 	ld->sc_flush = ld_iop_flush;
    193   1.1     ad 	ld->sc_start = ld_iop_start;
    194   1.1     ad 
    195   1.1     ad 	/* Say what the device is. */
    196   1.6     ad 	printf(":");
    197   1.6     ad 	iop_print_ident(iop, ia->ia_tid);
    198   1.1     ad 
    199   1.2     ad 	/*
    200   1.2     ad 	 * Claim the device so that we don't get any nasty surprises.  Allow
    201   1.2     ad 	 * failure.
    202   1.2     ad 	 */
    203   1.6     ad 	rv = iop_util_claim(iop, &sc->sc_ii, 0,
    204   1.1     ad 	    I2O_UTIL_CLAIM_CAPACITY_SENSITIVE |
    205   1.1     ad 	    I2O_UTIL_CLAIM_NO_PEER_SERVICE |
    206   1.1     ad 	    I2O_UTIL_CLAIM_NO_MANAGEMENT_SERVICE |
    207   1.1     ad 	    I2O_UTIL_CLAIM_PRIMARY_USER);
    208   1.6     ad 	sc->sc_flags = rv ? 0 : LD_IOP_CLAIMED;
    209   1.1     ad 
    210   1.9     ad 	rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_RBS_DEVICE_INFO,
    211   1.9     ad 	    &param, sizeof(param), NULL);
    212   1.9     ad 	if (rv != 0)
    213   1.1     ad 		goto bad;
    214   1.1     ad 
    215   1.1     ad 	ld->sc_secsize = le32toh(param.p.bdi.blocksize);
    216   1.1     ad 	ld->sc_secperunit = (int)
    217   1.1     ad 	    (le64toh(param.p.bdi.capacity) / ld->sc_secsize);
    218   1.1     ad 
    219   1.1     ad 	switch (param.p.bdi.type) {
    220   1.1     ad 	case I2O_RBS_TYPE_DIRECT:
    221   1.1     ad 		typestr = "direct access";
    222   1.2     ad 		enable = 1;
    223   1.1     ad 		break;
    224   1.1     ad 	case I2O_RBS_TYPE_WORM:
    225   1.1     ad 		typestr = "WORM";
    226   1.2     ad 		enable = 0;
    227   1.1     ad 		break;
    228   1.1     ad 	case I2O_RBS_TYPE_CDROM:
    229   1.6     ad 		typestr = "CD-ROM";
    230   1.2     ad 		enable = 0;
    231   1.1     ad 		break;
    232   1.1     ad 	case I2O_RBS_TYPE_OPTICAL:
    233   1.1     ad 		typestr = "optical";
    234   1.2     ad 		enable = 0;
    235   1.1     ad 		break;
    236   1.1     ad 	default:
    237   1.1     ad 		typestr = "unknown";
    238   1.2     ad 		enable = 0;
    239   1.1     ad 		break;
    240   1.1     ad 	}
    241   1.1     ad 
    242   1.1     ad 	if ((le32toh(param.p.bdi.capabilities) & I2O_RBS_CAP_REMOVEABLE_MEDIA)
    243   1.1     ad 	    != 0) {
    244   1.2     ad 		/* ld->sc_flags = LDF_REMOVEABLE; */
    245   1.1     ad 		fixedstr = "removeable";
    246   1.2     ad 		enable = 0;
    247   1.2     ad 	} else
    248   1.1     ad 		fixedstr = "fixed";
    249   1.2     ad 
    250   1.6     ad 	printf(" %s, %s", typestr, fixedstr);
    251   1.1     ad 
    252   1.1     ad 	/*
    253   1.1     ad 	 * Determine if the device has an private cache.  If so, print the
    254   1.1     ad 	 * cache size.  Even if the device doesn't appear to have a cache,
    255   1.6     ad 	 * we perform a flush at shutdown.
    256   1.1     ad 	 */
    257   1.9     ad 	rv = iop_field_get_all(iop, ia->ia_tid, I2O_PARAM_RBS_CACHE_CONTROL,
    258   1.9     ad 	    &param, sizeof(param), NULL);
    259   1.9     ad 	if (rv != 0)
    260   1.1     ad 		goto bad;
    261   1.1     ad 
    262   1.1     ad 	if ((cachesz = le32toh(param.p.cc.totalcachesize)) != 0)
    263   1.1     ad 		printf(", %dkB cache", cachesz >> 10);
    264   1.1     ad 
    265   1.2     ad 	printf("\n");
    266   1.2     ad 
    267   1.2     ad 	/*
    268   1.2     ad 	 * Configure the DDM's timeout functions to time out all commands
    269   1.6     ad 	 * after 30 seconds.
    270   1.2     ad 	 */
    271   1.9     ad 	timeoutbase = htole32(LD_IOP_TIMEOUT * 1000);
    272   1.9     ad 	rwvtimeoutbase = htole32(LD_IOP_TIMEOUT * 1000);
    273   1.9     ad 	rwvtimeout = 0;
    274   1.9     ad 
    275   1.9     ad 	iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
    276   1.9     ad 	    &timeoutbase, sizeof(timeoutbase),
    277   1.9     ad 	    I2O_PARAM_RBS_OPERATION_timeoutbase);
    278   1.9     ad 	iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
    279   1.9     ad 	    &rwvtimeoutbase, sizeof(rwvtimeoutbase),
    280   1.9     ad 	    I2O_PARAM_RBS_OPERATION_rwvtimeoutbase);
    281   1.9     ad 	iop_field_set(iop, ia->ia_tid, I2O_PARAM_RBS_OPERATION,
    282   1.9     ad 	    &rwvtimeout, sizeof(rwvtimeout),
    283   1.9     ad 	    I2O_PARAM_RBS_OPERATION_rwvtimeoutbase);
    284   1.2     ad 
    285   1.2     ad 	if (enable)
    286   1.2     ad 		ld->sc_flags |= LDF_ENABLED;
    287   1.2     ad 	else
    288   1.2     ad 		printf("%s: device not yet supported\n", self->dv_xname);
    289   1.2     ad 
    290   1.1     ad 	ldattach(ld);
    291   1.1     ad 	return;
    292   1.1     ad 
    293   1.6     ad  bad:
    294   1.6     ad 	ld_iop_unconfig(sc, evreg);
    295   1.6     ad }
    296   1.6     ad 
    297   1.6     ad static void
    298   1.6     ad ld_iop_unconfig(struct ld_iop_softc *sc, int evreg)
    299   1.6     ad {
    300   1.6     ad 	struct iop_softc *iop;
    301   1.6     ad 	int s;
    302   1.6     ad 
    303   1.6     ad 	iop = (struct iop_softc *)sc->sc_ld.sc_dv.dv_parent;
    304   1.6     ad 
    305   1.6     ad 	if ((sc->sc_flags & LD_IOP_CLAIMED) != 0)
    306   1.2     ad 		iop_util_claim(iop, &sc->sc_ii, 1,
    307   1.2     ad 		    I2O_UTIL_CLAIM_PRIMARY_USER);
    308   1.6     ad 
    309   1.6     ad 	if (evreg) {
    310   1.6     ad 		/*
    311   1.6     ad 		 * Mask off events, and wait up to 5 seconds for a reply.
    312   1.6     ad 		 * Note that some adapters won't reply to this (XXX We
    313   1.6     ad 		 * should check the event capabilities).
    314   1.6     ad 		 */
    315   1.6     ad 		sc->sc_flags &= ~LD_IOP_NEW_EVTMASK;
    316   1.6     ad 		iop_util_eventreg(iop, &sc->sc_eventii,
    317   1.6     ad 		    I2O_EVENT_GEN_EVENT_MASK_MODIFIED);
    318   1.6     ad 		s = splbio();
    319   1.6     ad 		if ((sc->sc_flags & LD_IOP_NEW_EVTMASK) == 0)
    320   1.6     ad 			tsleep(&sc->sc_eventii, PRIBIO, "ld_iopevt", hz * 5);
    321   1.6     ad 		splx(s);
    322   1.6     ad #ifdef I2ODEBUG
    323   1.6     ad 		if ((sc->sc_flags & LD_IOP_NEW_EVTMASK) == 0)
    324   1.6     ad 			printf("%s: didn't reply to event unregister",
    325   1.6     ad 			    sc->sc_ld.sc_dv.dv_xname);
    326   1.6     ad #endif
    327   1.6     ad 	}
    328   1.6     ad 
    329   1.6     ad 	iop_initiator_unregister(iop, &sc->sc_eventii);
    330   1.1     ad 	iop_initiator_unregister(iop, &sc->sc_ii);
    331   1.1     ad }
    332   1.1     ad 
    333   1.1     ad static int
    334   1.2     ad ld_iop_detach(struct device *self, int flags)
    335   1.2     ad {
    336   1.2     ad 	struct ld_iop_softc *sc;
    337   1.2     ad 	struct iop_softc *iop;
    338   1.4     ad 	int rv;
    339   1.2     ad 
    340   1.2     ad 	sc = (struct ld_iop_softc *)self;
    341   1.6     ad 	iop = (struct iop_softc *)self->dv_parent;
    342   1.2     ad 
    343   1.5     ad 	if ((rv = ldbegindetach(&sc->sc_ld, flags)) != 0)
    344   1.4     ad 		return (rv);
    345   1.2     ad 
    346   1.2     ad 	/*
    347   1.2     ad 	 * Abort any requests queued with the IOP, but allow requests that
    348   1.2     ad 	 * are already in progress to complete.
    349   1.2     ad 	 */
    350   1.2     ad 	if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0)
    351   1.2     ad 		iop_util_abort(iop, &sc->sc_ii, 0, 0,
    352   1.2     ad 		    I2O_UTIL_ABORT_WILD | I2O_UTIL_ABORT_CLEAN);
    353   1.2     ad 
    354   1.5     ad 	ldenddetach(&sc->sc_ld);
    355   1.2     ad 
    356   1.6     ad 	/* Un-claim the target, and un-register our initiators. */
    357   1.6     ad 	if ((sc->sc_ld.sc_flags & LDF_ENABLED) != 0)
    358   1.6     ad 		ld_iop_unconfig(sc, 1);
    359   1.2     ad 
    360   1.2     ad 	return (0);
    361   1.2     ad }
    362   1.2     ad 
    363   1.2     ad static int
    364   1.1     ad ld_iop_start(struct ld_softc *ld, struct buf *bp)
    365   1.1     ad {
    366   1.1     ad 	struct iop_msg *im;
    367   1.1     ad 	struct iop_softc *iop;
    368   1.1     ad 	struct ld_iop_softc *sc;
    369   1.6     ad 	struct i2o_rbs_block_read *mf;
    370   1.6     ad 	u_int rv, flags, write;
    371   1.1     ad 	u_int64_t ba;
    372   1.6     ad 	u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    373   1.1     ad 
    374   1.1     ad 	sc = (struct ld_iop_softc *)ld;
    375   1.1     ad 	iop = (struct iop_softc *)ld->sc_dv.dv_parent;
    376   1.1     ad 
    377   1.8     ad 	im = iop_msg_alloc(iop, 0);
    378   1.1     ad 	im->im_dvcontext = bp;
    379   1.1     ad 
    380   1.1     ad 	write = ((bp->b_flags & B_READ) == 0);
    381   1.1     ad 	ba = (u_int64_t)bp->b_rawblkno * ld->sc_secsize;
    382   1.1     ad 
    383   1.2     ad 	/*
    384   1.2     ad 	 * Write through the cache when performing synchronous writes.  When
    385   1.2     ad 	 * performing a read, we don't request that the DDM cache the data,
    386   1.2     ad 	 * as there's little advantage to it.
    387   1.2     ad 	 */
    388   1.1     ad 	if (write) {
    389   1.2     ad 		if ((bp->b_flags & B_ASYNC) == 0)
    390   1.1     ad 			flags = I2O_RBS_BLOCK_WRITE_CACHE_WT;
    391   1.1     ad 		else
    392   1.1     ad 			flags = I2O_RBS_BLOCK_WRITE_CACHE_WB;
    393   1.2     ad 	} else
    394   1.2     ad 		flags = 0;
    395   1.1     ad 
    396   1.1     ad 	/*
    397   1.1     ad 	 * Fill the message frame.  We can use the block_read structure for
    398   1.1     ad 	 * both reads and writes, as it's almost identical to the
    399   1.1     ad 	 * block_write structure.
    400   1.1     ad 	 */
    401   1.6     ad 	mf = (struct i2o_rbs_block_read *)mb;
    402   1.6     ad 	mf->msgflags = I2O_MSGFLAGS(i2o_rbs_block_read);
    403   1.6     ad 	mf->msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid,
    404   1.1     ad 	    write ? I2O_RBS_BLOCK_WRITE : I2O_RBS_BLOCK_READ);
    405   1.6     ad 	mf->msgictx = sc->sc_ii.ii_ictx;
    406   1.6     ad 	mf->msgtctx = im->im_tctx;
    407   1.6     ad 	mf->flags = flags | (1 << 16);		/* flags & time multiplier */
    408   1.6     ad 	mf->datasize = bp->b_bcount;
    409   1.6     ad 	mf->lowoffset = (u_int32_t)ba;
    410   1.6     ad 	mf->highoffset = (u_int32_t)(ba >> 32);
    411   1.6     ad 
    412   1.6     ad 	/* Map the data transfer and enqueue the command. */
    413   1.6     ad 	rv = iop_msg_map_bio(iop, im, mb, bp->b_data, bp->b_bcount, write);
    414   1.6     ad 	if (rv == 0) {
    415   1.8     ad 		if ((rv = iop_post(iop, mb)) != 0) {
    416   1.6     ad 			iop_msg_unmap(iop, im);
    417   1.6     ad 			iop_msg_free(iop, im);
    418   1.6     ad 		}
    419   1.6     ad 	}
    420   1.1     ad 	return (rv);
    421   1.1     ad }
    422   1.1     ad 
    423   1.1     ad static int
    424   1.1     ad ld_iop_dump(struct ld_softc *ld, void *data, int blkno, int blkcnt)
    425   1.1     ad {
    426   1.1     ad 	struct iop_msg *im;
    427   1.1     ad 	struct iop_softc *iop;
    428   1.1     ad 	struct ld_iop_softc *sc;
    429   1.6     ad 	struct i2o_rbs_block_write *mf;
    430   1.1     ad 	int rv, bcount;
    431   1.1     ad 	u_int64_t ba;
    432   1.6     ad 	u_int32_t mb[IOP_MAX_MSG_SIZE / sizeof(u_int32_t)];
    433   1.1     ad 
    434   1.1     ad 	sc = (struct ld_iop_softc *)ld;
    435   1.1     ad 	iop = (struct iop_softc *)ld->sc_dv.dv_parent;
    436   1.1     ad 	bcount = blkcnt * ld->sc_secsize;
    437   1.1     ad 	ba = (u_int64_t)blkno * ld->sc_secsize;
    438   1.8     ad 	im = iop_msg_alloc(iop, IM_POLL);
    439   1.1     ad 
    440   1.6     ad 	mf = (struct i2o_rbs_block_write *)mb;
    441   1.6     ad 	mf->msgflags = I2O_MSGFLAGS(i2o_rbs_block_write);
    442   1.6     ad 	mf->msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_RBS_BLOCK_WRITE);
    443   1.6     ad 	mf->msgictx = sc->sc_ii.ii_ictx;
    444   1.6     ad 	mf->msgtctx = im->im_tctx;
    445   1.6     ad 	mf->flags = I2O_RBS_BLOCK_WRITE_CACHE_WT | (1 << 16);
    446   1.6     ad 	mf->datasize = bcount;
    447   1.6     ad 	mf->lowoffset = (u_int32_t)ba;
    448   1.6     ad 	mf->highoffset = (u_int32_t)(ba >> 32);
    449   1.1     ad 
    450   1.8     ad 	if ((rv = iop_msg_map(iop, im, mb, data, bcount, 1, NULL)) != 0) {
    451   1.6     ad 		iop_msg_free(iop, im);
    452   1.1     ad 		return (rv);
    453   1.1     ad 	}
    454   1.1     ad 
    455   1.6     ad 	rv = iop_msg_post(iop, im, mb, LD_IOP_TIMEOUT * 2);
    456   1.1     ad 	iop_msg_unmap(iop, im);
    457   1.6     ad 	iop_msg_free(iop, im);
    458   1.1     ad  	return (rv);
    459   1.1     ad }
    460   1.1     ad 
    461   1.1     ad static int
    462   1.1     ad ld_iop_flush(struct ld_softc *ld)
    463   1.1     ad {
    464   1.1     ad 	struct iop_msg *im;
    465   1.1     ad 	struct iop_softc *iop;
    466   1.1     ad 	struct ld_iop_softc *sc;
    467   1.6     ad 	struct i2o_rbs_cache_flush mf;
    468   1.1     ad 	int rv;
    469   1.1     ad 
    470   1.1     ad 	sc = (struct ld_iop_softc *)ld;
    471   1.1     ad 	iop = (struct iop_softc *)ld->sc_dv.dv_parent;
    472   1.8     ad 	im = iop_msg_alloc(iop, IM_WAIT);
    473   1.1     ad 
    474   1.6     ad 	mf.msgflags = I2O_MSGFLAGS(i2o_rbs_cache_flush);
    475   1.6     ad 	mf.msgfunc = I2O_MSGFUNC(sc->sc_ii.ii_tid, I2O_RBS_CACHE_FLUSH);
    476   1.6     ad 	mf.msgictx = sc->sc_ii.ii_ictx;
    477   1.6     ad 	mf.msgtctx = im->im_tctx;
    478   1.6     ad 	mf.flags = 1 << 16;			/* time multiplier */
    479   1.1     ad 
    480   1.8     ad 	/* XXX Aincent disks will return an error here. */
    481   1.6     ad 	rv = iop_msg_post(iop, im, &mf, LD_IOP_TIMEOUT * 2);
    482   1.6     ad 	iop_msg_free(iop, im);
    483   1.1     ad 	return (rv);
    484   1.1     ad }
    485   1.1     ad 
    486   1.1     ad void
    487   1.1     ad ld_iop_intr(struct device *dv, struct iop_msg *im, void *reply)
    488   1.1     ad {
    489   1.1     ad 	struct i2o_rbs_reply *rb;
    490   1.1     ad 	struct buf *bp;
    491   1.1     ad 	struct ld_iop_softc *sc;
    492   1.1     ad 	struct iop_softc *iop;
    493   1.6     ad 	int err, detail;
    494   1.1     ad #ifdef I2OVERBOSE
    495   1.1     ad 	const char *errstr;
    496   1.1     ad #endif
    497   1.1     ad 
    498   1.1     ad 	rb = reply;
    499   1.1     ad 	bp = im->im_dvcontext;
    500   1.1     ad 	sc = (struct ld_iop_softc *)dv;
    501   1.1     ad 	iop = (struct iop_softc *)dv->dv_parent;
    502   1.1     ad 
    503   1.6     ad 	err = ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0);
    504   1.6     ad 
    505   1.6     ad 	if (!err && rb->reqstatus != I2O_STATUS_SUCCESS) {
    506   1.6     ad 		detail = le16toh(rb->detail);
    507   1.1     ad #ifdef I2OVERBOSE
    508   1.1     ad 		if (detail > sizeof(ld_iop_errors) / sizeof(ld_iop_errors[0]))
    509   1.6     ad 			errstr = "<unknown>";
    510   1.1     ad 		else
    511   1.1     ad 			errstr = ld_iop_errors[detail];
    512   1.6     ad 		printf("%s: error 0x%04x: %s\n", dv->dv_xname, detail, errstr);
    513   1.1     ad #else
    514   1.6     ad 		printf("%s: error 0x%04x\n", dv->dv_xname, detail);
    515   1.1     ad #endif
    516   1.6     ad 		err = 1;
    517   1.6     ad 	}
    518   1.6     ad 
    519   1.6     ad 	if (err) {
    520   1.1     ad 		bp->b_flags |= B_ERROR;
    521   1.1     ad 		bp->b_error = EIO;
    522   1.1     ad 		bp->b_resid = bp->b_bcount;
    523   1.1     ad 	} else
    524   1.6     ad 		bp->b_resid = bp->b_bcount - le32toh(rb->transfercount);
    525   1.1     ad 
    526   1.1     ad 	iop_msg_unmap(iop, im);
    527   1.6     ad 	iop_msg_free(iop, im);
    528   1.1     ad 	lddone(&sc->sc_ld, bp);
    529   1.2     ad }
    530   1.2     ad 
    531   1.2     ad static void
    532   1.2     ad ld_iop_intr_event(struct device *dv, struct iop_msg *im, void *reply)
    533   1.2     ad {
    534   1.2     ad 	struct i2o_util_event_register_reply *rb;
    535   1.6     ad 	struct ld_iop_softc *sc;
    536   1.2     ad 	u_int event;
    537   1.2     ad 
    538   1.2     ad 	rb = reply;
    539   1.6     ad 
    540   1.6     ad 	if ((rb->msgflags & I2O_MSGFLAGS_FAIL) != 0)
    541   1.6     ad 		return;
    542   1.6     ad 
    543   1.2     ad 	event = le32toh(rb->event);
    544   1.6     ad 	sc = (struct ld_iop_softc *)dv;
    545   1.2     ad 
    546   1.6     ad 	if (event == I2O_EVENT_GEN_EVENT_MASK_MODIFIED) {
    547   1.6     ad 		sc->sc_flags |= LD_IOP_NEW_EVTMASK;
    548   1.6     ad 		wakeup(&sc->sc_eventii);
    549   1.2     ad #ifndef I2ODEBUG
    550   1.2     ad 		return;
    551   1.2     ad #endif
    552   1.6     ad 	}
    553   1.2     ad 
    554   1.2     ad 	printf("%s: event 0x%08x received\n", dv->dv_xname, event);
    555   1.6     ad }
    556   1.6     ad 
    557   1.6     ad static void
    558   1.6     ad ld_iop_adjqparam(struct device *dv, int mpi)
    559   1.6     ad {
    560   1.6     ad 	struct iop_softc *iop;
    561   1.6     ad 
    562   1.6     ad 	/*
    563   1.6     ad 	 * AMI controllers seem to loose the plot if you hand off lots of
    564   1.6     ad 	 * queued commands.
    565   1.6     ad 	 */
    566   1.6     ad 	iop = (struct iop_softc *)dv->dv_parent;
    567   1.6     ad 	if (le16toh(I2O_ORG_AMI) == iop->sc_status.orgid && mpi > 64)
    568   1.6     ad 		mpi = 64;
    569   1.6     ad 
    570   1.6     ad 	ldadjqparam((struct ld_softc *)dv, mpi);
    571   1.1     ad }
    572