Home | History | Annotate | Line # | Download | only in dev
if_xe.c revision 1.13.2.4
      1  1.13.2.4     skrll /*	$NetBSD: if_xe.c,v 1.13.2.4 2004/09/21 13:19:41 skrll Exp $	*/
      2       1.1       dbj /*
      3       1.1       dbj  * Copyright (c) 1998 Darrin B. Jewell
      4       1.1       dbj  * All rights reserved.
      5       1.1       dbj  *
      6       1.1       dbj  * Redistribution and use in source and binary forms, with or without
      7       1.1       dbj  * modification, are permitted provided that the following conditions
      8       1.1       dbj  * are met:
      9       1.1       dbj  * 1. Redistributions of source code must retain the above copyright
     10       1.1       dbj  *    notice, this list of conditions and the following disclaimer.
     11       1.1       dbj  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1       dbj  *    notice, this list of conditions and the following disclaimer in the
     13       1.1       dbj  *    documentation and/or other materials provided with the distribution.
     14       1.1       dbj  * 3. All advertising materials mentioning features or use of this software
     15       1.1       dbj  *    must display the following acknowledgement:
     16       1.1       dbj  *      This product includes software developed by Darrin B. Jewell
     17       1.1       dbj  * 4. The name of the author may not be used to endorse or promote products
     18       1.1       dbj  *    derived from this software without specific prior written permission
     19       1.1       dbj  *
     20       1.1       dbj  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21       1.1       dbj  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22       1.1       dbj  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23       1.1       dbj  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24       1.1       dbj  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25       1.1       dbj  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26       1.1       dbj  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27       1.1       dbj  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28       1.1       dbj  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29       1.1       dbj  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30       1.1       dbj  */
     31       1.1       dbj 
     32  1.13.2.1     skrll #include <sys/cdefs.h>
     33  1.13.2.4     skrll __KERNEL_RCSID(0, "$NetBSD: if_xe.c,v 1.13.2.4 2004/09/21 13:19:41 skrll Exp $");
     34  1.13.2.1     skrll 
     35       1.2  jonathan #include "opt_inet.h"
     36       1.1       dbj #include "bpfilter.h"
     37       1.1       dbj 
     38       1.1       dbj #include <sys/param.h>
     39       1.1       dbj #include <sys/systm.h>
     40       1.1       dbj #include <sys/mbuf.h>
     41       1.1       dbj #include <sys/syslog.h>
     42       1.1       dbj #include <sys/socket.h>
     43       1.1       dbj #include <sys/device.h>
     44       1.1       dbj 
     45       1.1       dbj #include <net/if.h>
     46       1.1       dbj #include <net/if_ether.h>
     47       1.1       dbj #include <net/if_media.h>
     48       1.1       dbj 
     49       1.1       dbj #ifdef INET
     50       1.1       dbj #include <netinet/in.h>
     51       1.1       dbj #include <netinet/if_inarp.h>
     52       1.1       dbj #endif
     53       1.1       dbj 
     54       1.1       dbj #include <machine/autoconf.h>
     55       1.1       dbj #include <machine/cpu.h>
     56       1.1       dbj #include <machine/intr.h>
     57       1.1       dbj #include <machine/bus.h>
     58       1.1       dbj 
     59       1.1       dbj #include <next68k/next68k/isr.h>
     60       1.1       dbj 
     61       1.1       dbj #include <next68k/dev/mb8795reg.h>
     62       1.1       dbj #include <next68k/dev/mb8795var.h>
     63       1.1       dbj 
     64       1.7   mycroft #include <next68k/dev/bmapreg.h>
     65       1.7   mycroft #include <next68k/dev/intiovar.h>
     66       1.1       dbj #include <next68k/dev/nextdmareg.h>
     67       1.1       dbj #include <next68k/dev/nextdmavar.h>
     68       1.1       dbj 
     69       1.1       dbj #include <next68k/dev/if_xevar.h>
     70       1.7   mycroft #include <next68k/dev/if_xereg.h>
     71       1.7   mycroft 
     72       1.7   mycroft #ifdef DEBUG
     73       1.7   mycroft #define XE_DEBUG
     74       1.7   mycroft #endif
     75       1.1       dbj 
     76       1.7   mycroft #ifdef XE_DEBUG
     77       1.7   mycroft int xe_debug = 0;
     78       1.7   mycroft #define DPRINTF(x) if (xe_debug) printf x;
     79       1.7   mycroft extern char *ndtracep;
     80       1.7   mycroft extern char ndtrace[];
     81       1.7   mycroft extern int ndtraceshow;
     82       1.7   mycroft #define NDTRACEIF(x) if (10 && ndtracep < (ndtrace + 8192)) do {x;} while (0)
     83       1.7   mycroft #else
     84       1.7   mycroft #define DPRINTF(x)
     85       1.7   mycroft #define NDTRACEIF(x)
     86       1.7   mycroft #endif
     87       1.7   mycroft #define PRINTF(x) printf x;
     88       1.7   mycroft 
     89       1.7   mycroft extern int turbo;
     90       1.1       dbj 
     91       1.1       dbj int	xe_match __P((struct device *, struct cfdata *, void *));
     92       1.1       dbj void	xe_attach __P((struct device *, struct device *, void *));
     93       1.1       dbj int	xe_tint __P((void *));
     94       1.1       dbj int	xe_rint __P((void *));
     95       1.1       dbj 
     96       1.7   mycroft struct mbuf * xe_dma_rxmap_load __P((struct mb8795_softc *,
     97       1.7   mycroft 		bus_dmamap_t map));
     98       1.7   mycroft 
     99       1.7   mycroft bus_dmamap_t xe_dma_rx_continue __P((void *));
    100       1.7   mycroft void xe_dma_rx_completed __P((bus_dmamap_t,void *));
    101       1.7   mycroft bus_dmamap_t xe_dma_tx_continue __P((void *));
    102       1.7   mycroft void xe_dma_tx_completed __P((bus_dmamap_t,void *));
    103       1.7   mycroft void xe_dma_rx_shutdown __P((void *));
    104       1.7   mycroft void xe_dma_tx_shutdown __P((void *));
    105       1.7   mycroft 
    106       1.7   mycroft static void	findchannel_defer __P((struct device *));
    107       1.7   mycroft 
    108      1.11   thorpej CFATTACH_DECL(xe, sizeof(struct xe_softc),
    109      1.11   thorpej     xe_match, xe_attach, NULL, NULL);
    110       1.1       dbj 
    111       1.7   mycroft static int xe_dma_medias[] = {
    112       1.6  christos 	IFM_ETHER|IFM_AUTO,
    113       1.6  christos 	IFM_ETHER|IFM_10_T,
    114       1.6  christos 	IFM_ETHER|IFM_10_2,
    115       1.6  christos };
    116       1.7   mycroft static int nxe_dma_medias = (sizeof(xe_dma_medias)/sizeof(xe_dma_medias[0]));
    117       1.7   mycroft 
    118       1.7   mycroft static int attached = 0;
    119       1.7   mycroft 
    120       1.7   mycroft /*
    121       1.7   mycroft  * Functions and the switch for the MI code.
    122       1.7   mycroft  */
    123       1.7   mycroft u_char		xe_read_reg __P((struct mb8795_softc *, int));
    124       1.7   mycroft void		xe_write_reg __P((struct mb8795_softc *, int, u_char));
    125       1.7   mycroft void		xe_dma_reset __P((struct mb8795_softc *));
    126       1.7   mycroft void		xe_dma_rx_setup __P((struct mb8795_softc *));
    127       1.7   mycroft void		xe_dma_rx_go __P((struct mb8795_softc *));
    128       1.7   mycroft struct mbuf *	xe_dma_rx_mbuf __P((struct mb8795_softc *));
    129       1.7   mycroft void		xe_dma_tx_setup __P((struct mb8795_softc *));
    130       1.7   mycroft void		xe_dma_tx_go __P((struct mb8795_softc *));
    131       1.7   mycroft int		xe_dma_tx_mbuf __P((struct mb8795_softc *, struct mbuf *));
    132       1.7   mycroft int		xe_dma_tx_isactive __P((struct mb8795_softc *));
    133       1.7   mycroft #if 0
    134       1.7   mycroft int	xe_dma_setup __P((struct mb8795_softc *, caddr_t *,
    135       1.7   mycroft 	    size_t *, int, size_t *));
    136       1.7   mycroft void	xe_dma_go __P((struct mb8795_softc *));
    137       1.7   mycroft void	xe_dma_stop __P((struct mb8795_softc *));
    138       1.7   mycroft int	xe_dma_isactive __P((struct mb8795_softc *));
    139       1.7   mycroft #endif
    140       1.7   mycroft 
    141       1.7   mycroft struct mb8795_glue xe_glue = {
    142       1.7   mycroft 	xe_read_reg,
    143       1.7   mycroft 	xe_write_reg,
    144       1.7   mycroft 	xe_dma_reset,
    145       1.7   mycroft 	xe_dma_rx_setup,
    146       1.7   mycroft 	xe_dma_rx_go,
    147       1.7   mycroft 	xe_dma_rx_mbuf,
    148       1.7   mycroft 	xe_dma_tx_setup,
    149       1.7   mycroft 	xe_dma_tx_go,
    150       1.7   mycroft 	xe_dma_tx_mbuf,
    151       1.7   mycroft 	xe_dma_tx_isactive,
    152       1.7   mycroft #if 0
    153       1.7   mycroft 	xe_dma_setup,
    154       1.7   mycroft 	xe_dma_go,
    155       1.7   mycroft 	xe_dma_stop,
    156       1.7   mycroft 	xe_dma_isactive,
    157       1.7   mycroft 	NULL,			/* gl_clear_latched_intr */
    158       1.7   mycroft #endif
    159       1.7   mycroft };
    160       1.6  christos 
    161       1.1       dbj int
    162       1.1       dbj xe_match(parent, match, aux)
    163       1.1       dbj 	struct device *parent;
    164       1.1       dbj 	struct cfdata *match;
    165       1.1       dbj 	void *aux;
    166       1.1       dbj {
    167       1.7   mycroft 	struct intio_attach_args *ia = (struct intio_attach_args *)aux;
    168       1.7   mycroft 
    169       1.7   mycroft 	if (attached)
    170       1.7   mycroft 		return (0);
    171       1.7   mycroft 
    172       1.7   mycroft 	ia->ia_addr = (void *)NEXT_P_ENET;
    173       1.7   mycroft 
    174       1.7   mycroft 	return (1);
    175       1.7   mycroft }
    176       1.7   mycroft 
    177       1.7   mycroft static void
    178       1.7   mycroft findchannel_defer(self)
    179       1.7   mycroft 	struct device *self;
    180       1.7   mycroft {
    181       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)self;
    182       1.7   mycroft 	struct mb8795_softc *sc = &xsc->sc_mb8795;
    183       1.7   mycroft 	int i, error;
    184       1.7   mycroft 
    185       1.7   mycroft 	if (!xsc->sc_txdma) {
    186       1.7   mycroft 		xsc->sc_txdma = nextdma_findchannel ("enetx");
    187       1.7   mycroft 		if (xsc->sc_txdma == NULL)
    188      1.13       wiz 			panic ("%s: can't find enetx DMA channel",
    189       1.7   mycroft 			       sc->sc_dev.dv_xname);
    190       1.7   mycroft 	}
    191       1.7   mycroft 	if (!xsc->sc_rxdma) {
    192       1.7   mycroft 		xsc->sc_rxdma = nextdma_findchannel ("enetr");
    193       1.7   mycroft 		if (xsc->sc_rxdma == NULL)
    194      1.13       wiz 			panic ("%s: can't find enetr DMA channel",
    195       1.7   mycroft 			       sc->sc_dev.dv_xname);
    196       1.7   mycroft 	}
    197      1.13       wiz 	printf ("%s: using DMA channels %s %s\n", sc->sc_dev.dv_xname,
    198       1.7   mycroft 		xsc->sc_txdma->sc_dev.dv_xname, xsc->sc_rxdma->sc_dev.dv_xname);
    199       1.7   mycroft 
    200       1.7   mycroft 	nextdma_setconf (xsc->sc_rxdma, continue_cb, xe_dma_rx_continue);
    201       1.7   mycroft 	nextdma_setconf (xsc->sc_rxdma, completed_cb, xe_dma_rx_completed);
    202       1.7   mycroft 	nextdma_setconf (xsc->sc_rxdma, shutdown_cb, xe_dma_rx_shutdown);
    203       1.7   mycroft 	nextdma_setconf (xsc->sc_rxdma, cb_arg, sc);
    204       1.7   mycroft 
    205       1.7   mycroft 	nextdma_setconf (xsc->sc_txdma, continue_cb, xe_dma_tx_continue);
    206       1.7   mycroft 	nextdma_setconf (xsc->sc_txdma, completed_cb, xe_dma_tx_completed);
    207       1.7   mycroft 	nextdma_setconf (xsc->sc_txdma, shutdown_cb, xe_dma_tx_shutdown);
    208       1.7   mycroft 	nextdma_setconf (xsc->sc_txdma, cb_arg, sc);
    209       1.7   mycroft 
    210      1.13       wiz 	/* Initialize the DMA maps */
    211       1.7   mycroft 	error = bus_dmamap_create(xsc->sc_txdma->sc_dmat, MCLBYTES,
    212       1.7   mycroft 				  (MCLBYTES/MSIZE), MCLBYTES, 0, BUS_DMA_ALLOCNOW,
    213       1.7   mycroft 				  &xsc->sc_tx_dmamap);
    214       1.7   mycroft 	if (error) {
    215       1.8    provos 		panic("%s: can't create tx DMA map, error = %d",
    216       1.7   mycroft 		      sc->sc_dev.dv_xname, error);
    217       1.7   mycroft 	}
    218       1.7   mycroft 
    219       1.7   mycroft 	for(i = 0; i < MB8795_NRXBUFS; i++) {
    220       1.7   mycroft 		error = bus_dmamap_create(xsc->sc_rxdma->sc_dmat, MCLBYTES,
    221       1.7   mycroft 					  (MCLBYTES/MSIZE), MCLBYTES, 0, BUS_DMA_ALLOCNOW,
    222       1.7   mycroft 					  &xsc->sc_rx_dmamap[i]);
    223       1.7   mycroft 		if (error) {
    224       1.8    provos 			panic("%s: can't create rx DMA map, error = %d",
    225       1.7   mycroft 			      sc->sc_dev.dv_xname, error);
    226       1.7   mycroft 		}
    227       1.7   mycroft 		xsc->sc_rx_mb_head[i] = NULL;
    228       1.7   mycroft 	}
    229       1.7   mycroft 	xsc->sc_rx_loaded_idx = 0;
    230       1.7   mycroft 	xsc->sc_rx_completed_idx = 0;
    231       1.7   mycroft 	xsc->sc_rx_handled_idx = 0;
    232       1.7   mycroft 
    233       1.7   mycroft 	/* @@@ more next hacks
    234       1.7   mycroft 	 * the  2000 covers at least a 1500 mtu + headers
    235       1.7   mycroft 	 * + DMA_BEGINALIGNMENT+ DMA_ENDALIGNMENT
    236       1.7   mycroft 	 */
    237       1.7   mycroft 	xsc->sc_txbuf = malloc(2000, M_DEVBUF, M_NOWAIT);
    238       1.7   mycroft 	if (!xsc->sc_txbuf)
    239       1.7   mycroft 		panic("%s: can't malloc tx DMA buffer", sc->sc_dev.dv_xname);
    240       1.7   mycroft 
    241       1.7   mycroft 	xsc->sc_tx_mb_head = NULL;
    242       1.7   mycroft 	xsc->sc_tx_loaded = 0;
    243       1.7   mycroft 
    244       1.7   mycroft 	mb8795_config(sc, xe_dma_medias, nxe_dma_medias, xe_dma_medias[0]);
    245       1.7   mycroft 
    246       1.7   mycroft 	isrlink_autovec(xe_tint, sc, NEXT_I_IPL(NEXT_I_ENETX), 1, NULL);
    247       1.7   mycroft 	INTR_ENABLE(NEXT_I_ENETX);
    248       1.7   mycroft 	isrlink_autovec(xe_rint, sc, NEXT_I_IPL(NEXT_I_ENETR), 1, NULL);
    249       1.7   mycroft 	INTR_ENABLE(NEXT_I_ENETR);
    250       1.1       dbj }
    251       1.1       dbj 
    252       1.1       dbj void
    253       1.1       dbj xe_attach(parent, self, aux)
    254       1.1       dbj 	struct device *parent, *self;
    255       1.1       dbj 	void *aux;
    256       1.1       dbj {
    257       1.7   mycroft 	struct intio_attach_args *ia = (struct intio_attach_args *)aux;
    258       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)self;
    259       1.7   mycroft 	struct mb8795_softc *sc = &xsc->sc_mb8795;
    260       1.7   mycroft 
    261       1.7   mycroft 	DPRINTF(("%s: xe_attach()\n",sc->sc_dev.dv_xname));
    262       1.7   mycroft 
    263       1.7   mycroft 	{
    264       1.7   mycroft 		extern u_char rom_enetaddr[6];     /* kludge from machdep.c:next68k_bootargs() */
    265       1.7   mycroft 		int i;
    266       1.7   mycroft 		for(i=0;i<6;i++) {
    267       1.7   mycroft 			sc->sc_enaddr[i] = rom_enetaddr[i];
    268       1.7   mycroft 		}
    269       1.7   mycroft 	}
    270       1.7   mycroft 
    271       1.7   mycroft 	printf("\n%s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
    272       1.7   mycroft 	       sc->sc_dev.dv_xname,
    273       1.7   mycroft 	       sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
    274       1.7   mycroft 	       sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5]);
    275       1.7   mycroft 
    276       1.7   mycroft 	xsc->sc_bst = ia->ia_bst;
    277       1.7   mycroft 	if (bus_space_map(xsc->sc_bst, NEXT_P_ENET,
    278       1.7   mycroft 			  XE_DEVICE_SIZE, 0, &xsc->sc_bsh)) {
    279       1.8    provos 		panic("\n%s: can't map mb8795 registers",
    280       1.7   mycroft 		      sc->sc_dev.dv_xname);
    281       1.7   mycroft 	}
    282       1.1       dbj 
    283       1.7   mycroft 	sc->sc_bmap_bst = ia->ia_bst;
    284       1.7   mycroft 	if (bus_space_map(sc->sc_bmap_bst, NEXT_P_BMAP,
    285       1.7   mycroft 			  BMAP_SIZE, 0, &sc->sc_bmap_bsh)) {
    286       1.8    provos 		panic("\n%s: can't map bmap registers",
    287       1.7   mycroft 		      sc->sc_dev.dv_xname);
    288       1.7   mycroft 	}
    289       1.1       dbj 
    290       1.7   mycroft 	/*
    291       1.7   mycroft 	 * Set up glue for MI code.
    292       1.1       dbj 	 */
    293       1.7   mycroft 	sc->sc_glue = &xe_glue;
    294       1.1       dbj 
    295       1.7   mycroft 	xsc->sc_txdma = nextdma_findchannel ("enetx");
    296       1.7   mycroft 	xsc->sc_rxdma = nextdma_findchannel ("enetr");
    297       1.7   mycroft 	if (xsc->sc_rxdma && xsc->sc_txdma) {
    298       1.7   mycroft 		findchannel_defer (self);
    299       1.7   mycroft 	} else {
    300       1.7   mycroft 		config_defer (self, findchannel_defer);
    301       1.7   mycroft 	}
    302       1.1       dbj 
    303       1.7   mycroft 	attached = 1;
    304       1.1       dbj }
    305       1.1       dbj 
    306       1.1       dbj int
    307       1.1       dbj xe_tint(arg)
    308       1.7   mycroft 	void *arg;
    309       1.1       dbj {
    310       1.7   mycroft 	if (!INTR_OCCURRED(NEXT_I_ENETX))
    311       1.7   mycroft 		return 0;
    312       1.7   mycroft 	mb8795_tint((struct mb8795_softc *)arg);
    313       1.7   mycroft 	return(1);
    314       1.1       dbj }
    315       1.1       dbj 
    316       1.1       dbj int
    317       1.1       dbj xe_rint(arg)
    318       1.7   mycroft 	void *arg;
    319       1.7   mycroft {
    320       1.7   mycroft 	if (!INTR_OCCURRED(NEXT_I_ENETR))
    321       1.7   mycroft 		return(0);
    322       1.7   mycroft 	mb8795_rint((struct mb8795_softc *)arg);
    323       1.7   mycroft 	return(1);
    324       1.7   mycroft }
    325       1.7   mycroft 
    326       1.7   mycroft /*
    327       1.7   mycroft  * Glue functions.
    328       1.7   mycroft  */
    329       1.7   mycroft 
    330       1.7   mycroft u_char
    331       1.7   mycroft xe_read_reg(sc, reg)
    332       1.7   mycroft 	struct mb8795_softc *sc;
    333       1.7   mycroft 	int reg;
    334       1.7   mycroft {
    335       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    336       1.7   mycroft 
    337       1.7   mycroft 	return(bus_space_read_1(xsc->sc_bst, xsc->sc_bsh, reg));
    338       1.7   mycroft }
    339       1.7   mycroft 
    340       1.7   mycroft void
    341       1.7   mycroft xe_write_reg(sc, reg, val)
    342       1.7   mycroft 	struct mb8795_softc *sc;
    343       1.7   mycroft 	int reg;
    344       1.7   mycroft 	u_char val;
    345       1.7   mycroft {
    346       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    347       1.7   mycroft 
    348       1.7   mycroft 	bus_space_write_1(xsc->sc_bst, xsc->sc_bsh, reg, val);
    349       1.7   mycroft }
    350       1.7   mycroft 
    351       1.7   mycroft void
    352       1.7   mycroft xe_dma_reset(sc)
    353       1.7   mycroft 	struct mb8795_softc *sc;
    354       1.7   mycroft {
    355       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    356       1.7   mycroft 	int i;
    357       1.7   mycroft 
    358      1.13       wiz 	DPRINTF(("xe DMA reset\n"));
    359       1.7   mycroft 
    360       1.7   mycroft 	nextdma_reset(xsc->sc_rxdma);
    361       1.7   mycroft 	nextdma_reset(xsc->sc_txdma);
    362       1.7   mycroft 
    363       1.7   mycroft 	if (xsc->sc_tx_loaded) {
    364       1.7   mycroft 		bus_dmamap_sync(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap,
    365       1.7   mycroft 				0, xsc->sc_tx_dmamap->dm_mapsize,
    366       1.7   mycroft 				BUS_DMASYNC_POSTWRITE);
    367       1.7   mycroft 		bus_dmamap_unload(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap);
    368       1.7   mycroft 		xsc->sc_tx_loaded = 0;
    369       1.7   mycroft 	}
    370       1.7   mycroft 	if (xsc->sc_tx_mb_head) {
    371       1.7   mycroft 		m_freem(xsc->sc_tx_mb_head);
    372       1.7   mycroft 		xsc->sc_tx_mb_head = NULL;
    373       1.7   mycroft 	}
    374       1.7   mycroft 
    375       1.7   mycroft 	for(i = 0; i < MB8795_NRXBUFS; i++) {
    376       1.7   mycroft 		if (xsc->sc_rx_mb_head[i]) {
    377       1.7   mycroft 			bus_dmamap_unload(xsc->sc_rxdma->sc_dmat, xsc->sc_rx_dmamap[i]);
    378       1.7   mycroft 			m_freem(xsc->sc_rx_mb_head[i]);
    379       1.7   mycroft 			xsc->sc_rx_mb_head[i] = NULL;
    380       1.7   mycroft 		}
    381       1.7   mycroft 	}
    382       1.7   mycroft }
    383       1.7   mycroft 
    384       1.7   mycroft void
    385       1.7   mycroft xe_dma_rx_setup (sc)
    386       1.7   mycroft 	struct mb8795_softc *sc;
    387       1.7   mycroft {
    388       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    389       1.7   mycroft 	int i;
    390       1.7   mycroft 
    391      1.13       wiz 	DPRINTF(("xe DMA rx setup\n"));
    392       1.7   mycroft 
    393       1.7   mycroft 	for(i = 0; i < MB8795_NRXBUFS; i++) {
    394       1.7   mycroft 		xsc->sc_rx_mb_head[i] =
    395       1.7   mycroft 			xe_dma_rxmap_load(sc, xsc->sc_rx_dmamap[i]);
    396       1.7   mycroft 	}
    397       1.7   mycroft 	xsc->sc_rx_loaded_idx = 0;
    398       1.7   mycroft 	xsc->sc_rx_completed_idx = 0;
    399       1.7   mycroft 	xsc->sc_rx_handled_idx = 0;
    400       1.7   mycroft 
    401       1.7   mycroft 	nextdma_init(xsc->sc_rxdma);
    402       1.7   mycroft }
    403       1.7   mycroft 
    404       1.7   mycroft void
    405       1.7   mycroft xe_dma_rx_go (sc)
    406       1.7   mycroft 	struct mb8795_softc *sc;
    407       1.7   mycroft {
    408       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    409       1.7   mycroft 
    410      1.13       wiz 	DPRINTF(("xe DMA rx go\n"));
    411       1.7   mycroft 
    412       1.7   mycroft 	nextdma_start(xsc->sc_rxdma, DMACSR_SETREAD);
    413       1.7   mycroft }
    414       1.7   mycroft 
    415       1.7   mycroft struct mbuf *
    416       1.7   mycroft xe_dma_rx_mbuf (sc)
    417       1.7   mycroft 	struct mb8795_softc *sc;
    418       1.7   mycroft {
    419       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    420       1.7   mycroft 	bus_dmamap_t map;
    421       1.7   mycroft 	struct mbuf *m;
    422       1.7   mycroft 
    423       1.7   mycroft 	m = NULL;
    424       1.7   mycroft 	if (xsc->sc_rx_handled_idx != xsc->sc_rx_completed_idx) {
    425       1.7   mycroft 		xsc->sc_rx_handled_idx++;
    426       1.7   mycroft 		xsc->sc_rx_handled_idx %= MB8795_NRXBUFS;
    427       1.7   mycroft 
    428       1.7   mycroft 		map = xsc->sc_rx_dmamap[xsc->sc_rx_handled_idx];
    429       1.7   mycroft 		m = xsc->sc_rx_mb_head[xsc->sc_rx_handled_idx];
    430       1.7   mycroft 
    431       1.7   mycroft 		m->m_len = map->dm_xfer_len;
    432       1.7   mycroft 
    433       1.7   mycroft 		bus_dmamap_sync(xsc->sc_rxdma->sc_dmat, map,
    434       1.7   mycroft 				0, map->dm_mapsize, BUS_DMASYNC_POSTREAD);
    435       1.7   mycroft 
    436       1.7   mycroft 		bus_dmamap_unload(xsc->sc_rxdma->sc_dmat, map);
    437       1.7   mycroft 
    438       1.7   mycroft 		/* Install a fresh mbuf for next packet */
    439       1.7   mycroft 
    440       1.7   mycroft 		xsc->sc_rx_mb_head[xsc->sc_rx_handled_idx] =
    441       1.7   mycroft 			xe_dma_rxmap_load(sc,map);
    442       1.7   mycroft 
    443       1.7   mycroft 		/* Punt runt packets
    444      1.13       wiz 		 * DMA restarts create 0 length packets for example
    445       1.7   mycroft 		 */
    446       1.7   mycroft 		if (m->m_len < ETHER_MIN_LEN) {
    447       1.7   mycroft 			m_freem(m);
    448       1.7   mycroft 			m = NULL;
    449       1.7   mycroft 		}
    450       1.7   mycroft 	}
    451       1.7   mycroft 	return (m);
    452       1.7   mycroft }
    453       1.7   mycroft 
    454       1.7   mycroft void
    455       1.7   mycroft xe_dma_tx_setup (sc)
    456       1.7   mycroft 	struct mb8795_softc *sc;
    457       1.7   mycroft {
    458       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    459       1.7   mycroft 
    460      1.13       wiz 	DPRINTF(("xe DMA tx setup\n"));
    461       1.7   mycroft 
    462       1.7   mycroft 	nextdma_init(xsc->sc_txdma);
    463       1.7   mycroft }
    464       1.7   mycroft 
    465       1.7   mycroft void
    466       1.7   mycroft xe_dma_tx_go (sc)
    467       1.7   mycroft 	struct mb8795_softc *sc;
    468       1.7   mycroft {
    469       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    470       1.7   mycroft 
    471      1.13       wiz 	DPRINTF(("xe DMA tx go\n"));
    472       1.7   mycroft 
    473       1.7   mycroft 	nextdma_start(xsc->sc_txdma, DMACSR_SETWRITE);
    474       1.7   mycroft }
    475       1.7   mycroft 
    476       1.7   mycroft int
    477       1.7   mycroft xe_dma_tx_mbuf (sc, m)
    478       1.7   mycroft 	struct mb8795_softc *sc;
    479       1.7   mycroft 	struct mbuf *m;
    480       1.7   mycroft {
    481       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    482       1.7   mycroft 	int error;
    483       1.7   mycroft 
    484       1.7   mycroft 	xsc->sc_tx_mb_head = m;
    485       1.7   mycroft 
    486       1.7   mycroft /* The following is a next specific hack that should
    487       1.7   mycroft  * probably be moved out of MI code.
    488       1.7   mycroft  * This macro assumes it can move forward as needed
    489       1.7   mycroft  * in the buffer.  Perhaps it should zero the extra buffer.
    490       1.7   mycroft  */
    491       1.7   mycroft #define REALIGN_DMABUF(s,l) \
    492       1.7   mycroft 	{ (s) = ((u_char *)(((unsigned)(s)+DMA_BEGINALIGNMENT-1) \
    493       1.7   mycroft 			&~(DMA_BEGINALIGNMENT-1))); \
    494       1.7   mycroft     (l) = ((u_char *)(((unsigned)((s)+(l))+DMA_ENDALIGNMENT-1) \
    495       1.7   mycroft 				&~(DMA_ENDALIGNMENT-1)))-(s);}
    496       1.7   mycroft 
    497       1.7   mycroft #if 0
    498       1.7   mycroft 	error = bus_dmamap_load_mbuf(xsc->sc_txdma->sc_dmat,
    499       1.7   mycroft 				     xsc->sc_tx_dmamap, xsc->sc_tx_mb_head, BUS_DMA_NOWAIT);
    500       1.7   mycroft #else
    501       1.7   mycroft 	{
    502       1.7   mycroft 		u_char *buf = xsc->sc_txbuf;
    503       1.7   mycroft 		int buflen = 0;
    504       1.7   mycroft 
    505       1.7   mycroft 		buflen = m->m_pkthdr.len;
    506       1.7   mycroft 
    507       1.7   mycroft 		{
    508       1.7   mycroft 			u_char *p = buf;
    509       1.7   mycroft 			for (m=xsc->sc_tx_mb_head; m; m = m->m_next) {
    510       1.7   mycroft 				if (m->m_len == 0) continue;
    511       1.7   mycroft 				bcopy(mtod(m, u_char *), p, m->m_len);
    512       1.7   mycroft 				p += m->m_len;
    513      1.12    bouyer 			}
    514      1.12    bouyer 			/* Fix runt packets */
    515      1.12    bouyer 			if (buflen < ETHER_MIN_LEN - ETHER_CRC_LEN) {
    516      1.12    bouyer 				memset(p, 0,
    517      1.12    bouyer 				    ETHER_MIN_LEN - ETHER_CRC_LEN - buflen);
    518      1.12    bouyer 				buflen = ETHER_MIN_LEN - ETHER_CRC_LEN;
    519       1.7   mycroft 			}
    520       1.7   mycroft 		}
    521       1.7   mycroft 
    522       1.7   mycroft 		error = bus_dmamap_load(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap,
    523       1.7   mycroft 					buf,buflen,NULL,BUS_DMA_NOWAIT);
    524       1.7   mycroft 	}
    525       1.7   mycroft #endif
    526       1.7   mycroft 	if (error) {
    527       1.7   mycroft 		printf("%s: can't load mbuf chain, error = %d\n",
    528       1.7   mycroft 		       sc->sc_dev.dv_xname, error);
    529       1.7   mycroft 		m_freem(xsc->sc_tx_mb_head);
    530       1.7   mycroft 		xsc->sc_tx_mb_head = NULL;
    531       1.7   mycroft 		return (error);
    532       1.7   mycroft 	}
    533       1.7   mycroft 
    534       1.7   mycroft #ifdef DIAGNOSTIC
    535       1.7   mycroft 	if (xsc->sc_tx_loaded != 0) {
    536       1.7   mycroft 		panic("%s: xsc->sc_tx_loaded is %d",sc->sc_dev.dv_xname,
    537       1.7   mycroft 		      xsc->sc_tx_loaded);
    538       1.7   mycroft 	}
    539       1.7   mycroft #endif
    540       1.7   mycroft 
    541       1.7   mycroft 	bus_dmamap_sync(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap, 0,
    542       1.7   mycroft 			xsc->sc_tx_dmamap->dm_mapsize, BUS_DMASYNC_PREWRITE);
    543       1.7   mycroft 
    544       1.7   mycroft 	return (0);
    545       1.7   mycroft }
    546       1.7   mycroft 
    547       1.7   mycroft int
    548       1.7   mycroft xe_dma_tx_isactive (sc)
    549       1.7   mycroft 	struct mb8795_softc *sc;
    550       1.7   mycroft {
    551       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    552       1.7   mycroft 
    553       1.7   mycroft 	return (xsc->sc_tx_loaded != 0);
    554       1.7   mycroft }
    555       1.7   mycroft 
    556       1.7   mycroft /****************************************************************/
    557       1.7   mycroft 
    558       1.7   mycroft void
    559       1.7   mycroft xe_dma_tx_completed(map, arg)
    560       1.7   mycroft 	bus_dmamap_t map;
    561       1.7   mycroft 	void *arg;
    562       1.7   mycroft {
    563  1.13.2.2     skrll #if defined (XE_DEBUG) || defined (DIAGNOSTIC)
    564       1.7   mycroft 	struct mb8795_softc *sc = arg;
    565  1.13.2.2     skrll #endif
    566  1.13.2.2     skrll #ifdef DIAGNOSTIC
    567       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    568  1.13.2.2     skrll #endif
    569       1.7   mycroft 
    570       1.7   mycroft 	DPRINTF(("%s: xe_dma_tx_completed()\n",sc->sc_dev.dv_xname));
    571       1.7   mycroft 
    572       1.7   mycroft #ifdef DIAGNOSTIC
    573       1.7   mycroft 	if (!xsc->sc_tx_loaded) {
    574      1.10    provos 		panic("%s: tx completed never loaded",sc->sc_dev.dv_xname);
    575       1.7   mycroft 	}
    576       1.7   mycroft 	if (map != xsc->sc_tx_dmamap) {
    577       1.7   mycroft 		panic("%s: unexpected tx completed map",sc->sc_dev.dv_xname);
    578       1.7   mycroft 	}
    579       1.7   mycroft 
    580       1.7   mycroft #endif
    581       1.7   mycroft }
    582       1.7   mycroft 
    583       1.7   mycroft void
    584       1.7   mycroft xe_dma_tx_shutdown(arg)
    585       1.7   mycroft 	void *arg;
    586       1.1       dbj {
    587       1.7   mycroft 	struct mb8795_softc *sc = arg;
    588       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    589       1.7   mycroft 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    590       1.7   mycroft 
    591       1.7   mycroft 	DPRINTF(("%s: xe_dma_tx_shutdown()\n",sc->sc_dev.dv_xname));
    592       1.7   mycroft 
    593       1.7   mycroft #ifdef DIAGNOSTIC
    594       1.7   mycroft 	if (!xsc->sc_tx_loaded) {
    595      1.10    provos 		panic("%s: tx shutdown never loaded",sc->sc_dev.dv_xname);
    596       1.7   mycroft 	}
    597       1.7   mycroft #endif
    598       1.7   mycroft 
    599       1.7   mycroft 	if (turbo)
    600       1.7   mycroft 		MB_WRITE_REG(sc, MB8795_TXMODE, MB8795_TXMODE_TURBO1);
    601       1.7   mycroft 	if (xsc->sc_tx_loaded) {
    602       1.7   mycroft 		bus_dmamap_sync(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap,
    603       1.7   mycroft 				0, xsc->sc_tx_dmamap->dm_mapsize,
    604       1.7   mycroft 				BUS_DMASYNC_POSTWRITE);
    605       1.7   mycroft 		bus_dmamap_unload(xsc->sc_txdma->sc_dmat, xsc->sc_tx_dmamap);
    606       1.7   mycroft 		m_freem(xsc->sc_tx_mb_head);
    607       1.7   mycroft 		xsc->sc_tx_mb_head = NULL;
    608       1.7   mycroft 
    609       1.7   mycroft 		xsc->sc_tx_loaded--;
    610       1.7   mycroft 	}
    611       1.7   mycroft 
    612       1.7   mycroft #ifdef DIAGNOSTIC
    613       1.7   mycroft 	if (xsc->sc_tx_loaded != 0) {
    614       1.7   mycroft 		panic("%s: sc->sc_tx_loaded is %d",sc->sc_dev.dv_xname,
    615       1.7   mycroft 		      xsc->sc_tx_loaded);
    616       1.7   mycroft 	}
    617       1.7   mycroft #endif
    618       1.7   mycroft 
    619       1.7   mycroft 	ifp->if_timer = 0;
    620       1.7   mycroft 
    621       1.7   mycroft #if 1
    622       1.7   mycroft 	if ((ifp->if_flags & IFF_RUNNING) && !IF_IS_EMPTY(&sc->sc_tx_snd)) {
    623       1.7   mycroft 		void mb8795_start_dma __P((struct mb8795_softc *)); /* XXXX */
    624       1.7   mycroft 		mb8795_start_dma(sc);
    625       1.7   mycroft 	}
    626       1.7   mycroft #endif
    627       1.7   mycroft 
    628       1.7   mycroft #if 0
    629       1.7   mycroft 	/* Enable ready interrupt */
    630       1.7   mycroft 	MB_WRITE_REG(sc, MB8795_TXMASK,
    631       1.7   mycroft 		     MB_READ_REG(sc, MB8795_TXMASK)
    632       1.7   mycroft 		     | MB8795_TXMASK_TXRXIE/* READYIE */);
    633       1.7   mycroft #endif
    634       1.7   mycroft }
    635       1.7   mycroft 
    636       1.7   mycroft 
    637       1.7   mycroft void
    638       1.7   mycroft xe_dma_rx_completed(map, arg)
    639       1.7   mycroft 	bus_dmamap_t map;
    640       1.7   mycroft 	void *arg;
    641       1.7   mycroft {
    642       1.7   mycroft 	struct mb8795_softc *sc = arg;
    643       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    644       1.7   mycroft 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    645       1.7   mycroft 
    646       1.7   mycroft 	if (ifp->if_flags & IFF_RUNNING) {
    647       1.7   mycroft 		xsc->sc_rx_completed_idx++;
    648       1.7   mycroft 		xsc->sc_rx_completed_idx %= MB8795_NRXBUFS;
    649       1.7   mycroft 
    650       1.7   mycroft 		DPRINTF(("%s: xe_dma_rx_completed(), sc->sc_rx_completed_idx = %d\n",
    651       1.7   mycroft 			 sc->sc_dev.dv_xname, xsc->sc_rx_completed_idx));
    652       1.7   mycroft 
    653       1.7   mycroft #if (defined(DIAGNOSTIC))
    654       1.7   mycroft 		if (map != xsc->sc_rx_dmamap[xsc->sc_rx_completed_idx]) {
    655       1.8    provos 			panic("%s: Unexpected rx dmamap completed",
    656       1.7   mycroft 			      sc->sc_dev.dv_xname);
    657       1.7   mycroft 		}
    658       1.7   mycroft #endif
    659       1.7   mycroft 	}
    660       1.7   mycroft #ifdef DIAGNOSTIC
    661       1.7   mycroft 	else
    662       1.7   mycroft 		DPRINTF(("%s: Unexpected rx dmamap completed while if not running\n",
    663       1.7   mycroft 			 sc->sc_dev.dv_xname));
    664       1.7   mycroft #endif
    665       1.7   mycroft }
    666       1.7   mycroft 
    667       1.7   mycroft void
    668       1.7   mycroft xe_dma_rx_shutdown(arg)
    669       1.7   mycroft 	void *arg;
    670       1.7   mycroft {
    671       1.7   mycroft 	struct mb8795_softc *sc = arg;
    672       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    673       1.7   mycroft 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    674       1.7   mycroft 
    675       1.7   mycroft 	if (ifp->if_flags & IFF_RUNNING) {
    676       1.7   mycroft 		DPRINTF(("%s: xe_dma_rx_shutdown(), restarting.\n",
    677       1.7   mycroft 			 sc->sc_dev.dv_xname));
    678       1.7   mycroft 
    679       1.7   mycroft 		nextdma_start(xsc->sc_rxdma, DMACSR_SETREAD);
    680       1.7   mycroft 		if (turbo)
    681       1.7   mycroft 			MB_WRITE_REG(sc, MB8795_RXMODE, MB8795_RXMODE_TEST | MB8795_RXMODE_MULTICAST);
    682       1.7   mycroft 	}
    683       1.7   mycroft #ifdef DIAGNOSTIC
    684       1.7   mycroft 	else
    685      1.13       wiz 		DPRINTF(("%s: Unexpected rx DMA shutdown while if not running\n",
    686       1.7   mycroft 			 sc->sc_dev.dv_xname));
    687       1.7   mycroft #endif
    688       1.7   mycroft }
    689       1.7   mycroft 
    690       1.7   mycroft /*
    691       1.7   mycroft  * load a dmamap with a freshly allocated mbuf
    692       1.7   mycroft  */
    693       1.7   mycroft struct mbuf *
    694       1.7   mycroft xe_dma_rxmap_load(sc,map)
    695       1.7   mycroft 	struct mb8795_softc *sc;
    696       1.7   mycroft 	bus_dmamap_t map;
    697       1.7   mycroft {
    698       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    699       1.7   mycroft 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    700       1.7   mycroft 	struct mbuf *m;
    701       1.7   mycroft 	int error;
    702       1.7   mycroft 
    703       1.7   mycroft 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    704       1.7   mycroft 	if (m) {
    705       1.7   mycroft 		MCLGET(m, M_DONTWAIT);
    706       1.7   mycroft 		if ((m->m_flags & M_EXT) == 0) {
    707       1.7   mycroft 			m_freem(m);
    708       1.7   mycroft 			m = NULL;
    709       1.7   mycroft 		} else {
    710       1.7   mycroft 			m->m_len = MCLBYTES;
    711       1.7   mycroft 		}
    712       1.7   mycroft 	}
    713       1.7   mycroft 	if (!m) {
    714       1.7   mycroft 		/* @@@ Handle this gracefully by reusing a scratch buffer
    715       1.7   mycroft 		 * or something.
    716       1.7   mycroft 		 */
    717       1.8    provos 		panic("Unable to get memory for incoming ethernet");
    718       1.7   mycroft 	}
    719       1.7   mycroft 
    720       1.7   mycroft 	/* Align buffer, @@@ next specific.
    721       1.7   mycroft 	 * perhaps should be using M_ALIGN here instead?
    722       1.7   mycroft 	 * First we give us a little room to align with.
    723       1.7   mycroft 	 */
    724       1.7   mycroft 	{
    725       1.7   mycroft 		u_char *buf = m->m_data;
    726       1.7   mycroft 		int buflen = m->m_len;
    727       1.7   mycroft 		buflen -= DMA_ENDALIGNMENT+DMA_BEGINALIGNMENT;
    728       1.7   mycroft 		REALIGN_DMABUF(buf, buflen);
    729       1.7   mycroft 		m->m_data = buf;
    730       1.7   mycroft 		m->m_len = buflen;
    731       1.7   mycroft 	}
    732       1.7   mycroft 
    733       1.7   mycroft 	m->m_pkthdr.rcvif = ifp;
    734       1.7   mycroft 	m->m_pkthdr.len = m->m_len;
    735       1.7   mycroft 
    736       1.7   mycroft 	error = bus_dmamap_load_mbuf(xsc->sc_rxdma->sc_dmat,
    737       1.7   mycroft 			map, m, BUS_DMA_NOWAIT);
    738       1.7   mycroft 
    739       1.7   mycroft 	bus_dmamap_sync(xsc->sc_rxdma->sc_dmat, map, 0,
    740       1.7   mycroft 			map->dm_mapsize, BUS_DMASYNC_PREREAD);
    741       1.7   mycroft 
    742       1.7   mycroft 	if (error) {
    743       1.7   mycroft 		DPRINTF(("DEBUG: m->m_data = %p, m->m_len = %d\n",
    744       1.7   mycroft 				m->m_data, m->m_len));
    745       1.7   mycroft 		DPRINTF(("DEBUG: MCLBYTES = %d, map->_dm_size = %ld\n",
    746       1.7   mycroft 				MCLBYTES, map->_dm_size));
    747       1.7   mycroft 
    748       1.8    provos 		panic("%s: can't load rx mbuf chain, error = %d",
    749       1.7   mycroft 				sc->sc_dev.dv_xname, error);
    750       1.7   mycroft 		m_freem(m);
    751       1.7   mycroft 		m = NULL;
    752       1.7   mycroft 	}
    753       1.7   mycroft 
    754       1.7   mycroft 	return(m);
    755       1.7   mycroft }
    756       1.7   mycroft 
    757       1.7   mycroft bus_dmamap_t
    758       1.7   mycroft xe_dma_rx_continue(arg)
    759       1.7   mycroft 	void *arg;
    760       1.7   mycroft {
    761       1.7   mycroft 	struct mb8795_softc *sc = arg;
    762       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    763       1.7   mycroft 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    764       1.7   mycroft 	bus_dmamap_t map = NULL;
    765       1.7   mycroft 
    766       1.7   mycroft 	if (ifp->if_flags & IFF_RUNNING) {
    767       1.7   mycroft 		if (((xsc->sc_rx_loaded_idx+1)%MB8795_NRXBUFS) == xsc->sc_rx_handled_idx) {
    768       1.7   mycroft 			/* make space for one packet by dropping one */
    769       1.7   mycroft 			struct mbuf *m;
    770       1.7   mycroft 			m = xe_dma_rx_mbuf (sc);
    771       1.7   mycroft 			if (m)
    772       1.7   mycroft 				m_freem(m);
    773       1.7   mycroft #if (defined(DIAGNOSTIC))
    774       1.7   mycroft 			DPRINTF(("%s: out of receive DMA buffers\n",sc->sc_dev.dv_xname));
    775       1.7   mycroft #endif
    776       1.7   mycroft 		}
    777       1.7   mycroft 		xsc->sc_rx_loaded_idx++;
    778       1.7   mycroft 		xsc->sc_rx_loaded_idx %= MB8795_NRXBUFS;
    779       1.7   mycroft 		map = xsc->sc_rx_dmamap[xsc->sc_rx_loaded_idx];
    780       1.7   mycroft 
    781       1.7   mycroft 		DPRINTF(("%s: xe_dma_rx_continue() xsc->sc_rx_loaded_idx = %d\nn",
    782       1.7   mycroft 			 sc->sc_dev.dv_xname,xsc->sc_rx_loaded_idx));
    783       1.7   mycroft 	}
    784       1.7   mycroft #ifdef DIAGNOSTIC
    785       1.7   mycroft 	else
    786      1.13       wiz 		panic("%s: Unexpected rx DMA continue while if not running",
    787       1.7   mycroft 		      sc->sc_dev.dv_xname);
    788       1.7   mycroft #endif
    789       1.7   mycroft 
    790       1.7   mycroft 	return(map);
    791       1.7   mycroft }
    792       1.7   mycroft 
    793       1.7   mycroft bus_dmamap_t
    794       1.7   mycroft xe_dma_tx_continue(arg)
    795       1.7   mycroft 	void *arg;
    796       1.7   mycroft {
    797       1.7   mycroft 	struct mb8795_softc *sc = arg;
    798       1.7   mycroft 	struct xe_softc *xsc = (struct xe_softc *)sc;
    799       1.7   mycroft 	bus_dmamap_t map;
    800       1.7   mycroft 
    801       1.7   mycroft 	DPRINTF(("%s: xe_dma_tx_continue()\n",sc->sc_dev.dv_xname));
    802       1.7   mycroft 
    803       1.7   mycroft 	if (xsc->sc_tx_loaded) {
    804       1.7   mycroft 		map = NULL;
    805       1.7   mycroft 	} else {
    806       1.7   mycroft 		map = xsc->sc_tx_dmamap;
    807       1.7   mycroft 		xsc->sc_tx_loaded++;
    808       1.7   mycroft 	}
    809       1.7   mycroft 
    810       1.7   mycroft #ifdef DIAGNOSTIC
    811       1.7   mycroft 	if (xsc->sc_tx_loaded != 1) {
    812       1.7   mycroft 		panic("%s: sc->sc_tx_loaded is %d",sc->sc_dev.dv_xname,
    813       1.7   mycroft 				xsc->sc_tx_loaded);
    814       1.7   mycroft 	}
    815       1.7   mycroft #endif
    816       1.7   mycroft 
    817       1.7   mycroft 	return(map);
    818       1.1       dbj }
    819