nsegs = ((IOP_MAX_MSG_SIZE / 4) - off) >> 1;
nsegs = ((IOP_MAX_MSG_SIZE / sizeof *mb) - off) >> 1;
iop_msg_map(struct iop_softc *sc, struct iop_msg *im, u_int32_t *mb,	    void *xferaddr, int xfersize, int out){	bus_dmamap_t dm;	bus_dma_segment_t *ds;	struct iop_xfer *ix;	u_int rv, i, nsegs, flg, off, xn;	u_int32_t *p;	for (xn = 0, ix = im->im_xfer; xn < IOP_MAX_MSG_XFERS; xn++, ix++)		if (ix->ix_size == 0)			break;#ifdef I2ODEBUG	if (xfersize == 0)		panic("iop_msg_map: null transfer");	if (xfersize > IOP_MAX_XFER)		panic("iop_msg_map: transfer too large");	if (xn == IOP_MAX_MSG_XFERS)		panic("iop_msg_map: too many xfers");#endif	/*	 * Only the first DMA map is static.	 */	if (xn != 0) {		rv = bus_dmamap_create(sc->sc_dmat, IOP_MAX_XFER,		    IOP_MAX_SEGS, IOP_MAX_XFER, 0,		    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ix->ix_map);		if (rv != 0)			return (rv);	}	dm = ix->ix_map;	rv = bus_dmamap_load(sc->sc_dmat, dm, xferaddr, xfersize, NULL, 0);	if (rv != 0)		goto bad;	/*	 * How many SIMPLE SG elements can we fit in this message?	 */	off = mb[0] >> 16;	p = mb + off;	nsegs = ((IOP_MAX_MSG_SIZE / 4) - off) >> 1;	if (dm->dm_nsegs > nsegs) {		bus_dmamap_unload(sc->sc_dmat, ix->ix_map);		rv = EFBIG;		DPRINTF(("iop_msg_map: too many segs\n"));		goto bad;	}	nsegs = dm->dm_nsegs;	xfersize = 0;	/*	 * Write out the SG list.	 */	if (out)		flg = I2O_SGL_SIMPLE | I2O_SGL_DATA_OUT;	else		flg = I2O_SGL_SIMPLE;	for (i = nsegs, ds = dm->dm_segs; i > 1; i--, p += 2, ds++) {		p[0] = (u_int32_t)ds->ds_len | flg;		p[1] = (u_int32_t)ds->ds_addr;		xfersize += ds->ds_len;	}	p[0] = (u_int32_t)ds->ds_len | flg | I2O_SGL_END_BUFFER;	p[1] = (u_int32_t)ds->ds_addr;	xfersize += ds->ds_len;	/* Fix up the transfer record, and sync the map. */	ix->ix_flags = (out ? IX_OUT : IX_IN);	ix->ix_size = xfersize;	bus_dmamap_sync(sc->sc_dmat, ix->ix_map,	    out ? BUS_DMASYNC_POSTWRITE : BUS_DMASYNC_POSTREAD);	/*	 * If this is the first xfer we've mapped for this message, adjust	 * the SGL offset field in the message header.	 */	if ((im->im_flags & IM_SGLOFFADJ) == 0) {		mb[0] += (mb[0] >> 12) & 0xf0;		im->im_flags |= IM_SGLOFFADJ;	}	mb[0] += (nsegs << 17);	return (0); bad: 	if (xn != 0)		bus_dmamap_destroy(sc->sc_dmat, ix->ix_map);	return (rv);}