sd->sd_mbuf = m;
sd->sd_mbuf = NULL;
hme_encap(sc, mhead, bixp)	struct hme_softc *sc;	struct mbuf *mhead;	int *bixp;{	struct hme_sxd *sd;	struct mbuf *m, *mx;	int frag, cur, cnt = 0;	u_int32_t flags;	struct hme_ring *hr = &sc->sc_rb;	cur = frag = *bixp;	sd = &sc->sc_txd[frag];	m = mhead;	while (m != NULL) {		if (m->m_len == 0) {			mx = m_free(m);			m = mx;			continue;		}		if ((HME_TX_RING_SIZE - (sc->sc_tx_cnt + cnt)) < 5)			goto err;		if (bus_dmamap_create(sc->sc_dmatag, MCLBYTES, 1,		    MCLBYTES, 0, BUS_DMA_NOWAIT, &sd->sd_map) != 0) {			sd->sd_map = NULL;			goto err;		}		if (bus_dmamap_load(sc->sc_dmatag, sd->sd_map,		    mtod(m, caddr_t), m->m_len, NULL, BUS_DMA_NOWAIT) != 0) {			bus_dmamap_destroy(sc->sc_dmatag, sd->sd_map);			sd->sd_map = NULL;			goto err;		}		bus_dmamap_sync(sc->sc_dmatag, sd->sd_map, 0,		    sd->sd_map->dm_mapsize, BUS_DMASYNC_PREWRITE);		sd->sd_mbuf = m;		flags = HME_XD_ENCODE_TSIZE(m->m_len);		if (cnt == 0)			flags |= HME_XD_SOP;		else			flags |= HME_XD_OWN;		HME_XD_SETADDR(sc->sc_pci, hr->rb_txd, frag,		    sd->sd_map->dm_segs[0].ds_addr);		HME_XD_SETFLAGS(sc->sc_pci, hr->rb_txd, frag, flags);		cur = frag;		cnt++;		if (++frag == HME_TX_RING_SIZE) {			frag = 0;			sd = sc->sc_txd;		} else			sd++;		m = m->m_next;	}	/* Set end of packet on last descriptor. */	flags = HME_XD_GETFLAGS(sc->sc_pci, hr->rb_txd, cur);	flags |= HME_XD_EOP;	HME_XD_SETFLAGS(sc->sc_pci, hr->rb_txd, cur, flags);	/* Give first frame over to the hardware. */	flags = HME_XD_GETFLAGS(sc->sc_pci, hr->rb_txd, (*bixp));	flags |= HME_XD_OWN;	HME_XD_SETFLAGS(sc->sc_pci, hr->rb_txd, (*bixp), flags);	sc->sc_tx_cnt += cnt;	*bixp = frag;	/* sync descriptors */	return (0);err:	/*	 * Invalidate the stuff we may have already put into place. We	 * will be called again to queue it later.	 */	for (; cnt > 0; cnt--) {		if (--frag == -1)			frag = HME_TX_RING_SIZE - 1;		sd = &sc->sc_txd[frag];		bus_dmamap_sync(sc->sc_dmatag, sd->sd_map, 0,		    sd->sd_map->dm_mapsize, BUS_DMASYNC_POSTWRITE);		bus_dmamap_unload(sc->sc_dmatag, sd->sd_map);		bus_dmamap_destroy(sc->sc_dmatag, sd->sd_map);		sd->sd_mbuf = NULL;		sd->sd_map = NULL;	}	return (ENOBUFS);}