Home | History | Annotate | Line # | Download | only in obio
if_mc_obio.c revision 1.17
      1  1.17       he /*	$NetBSD: if_mc_obio.c,v 1.17 2007/03/05 21:23:49 he Exp $	*/
      2   1.3   briggs 
      3   1.1   briggs /*-
      4  1.13      wiz  * Copyright (c) 1997 David Huang <khym (at) azeotrope.org>
      5   1.1   briggs  * All rights reserved.
      6   1.1   briggs  *
      7   1.1   briggs  * Portions of this code are based on code by Denton Gentry <denny1 (at) home.com>
      8   1.1   briggs  * and Yanagisawa Takeshi <yanagisw (at) aa.ap.titech.ac.jp>.
      9   1.1   briggs  *
     10   1.1   briggs  * Redistribution and use in source and binary forms, with or without
     11   1.1   briggs  * modification, are permitted provided that the following conditions
     12   1.1   briggs  * are met:
     13   1.1   briggs  * 1. Redistributions of source code must retain the above copyright
     14   1.1   briggs  *    notice, this list of conditions and the following disclaimer.
     15   1.1   briggs  * 2. The name of the author may not be used to endorse or promote products
     16   1.1   briggs  *    derived from this software without specific prior written permission
     17   1.1   briggs  *
     18   1.1   briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19   1.1   briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20   1.1   briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21   1.1   briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22   1.1   briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23   1.1   briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24   1.1   briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25   1.1   briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26   1.1   briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27   1.1   briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28   1.1   briggs  *
     29   1.1   briggs  */
     30   1.1   briggs 
     31   1.1   briggs /*
     32   1.1   briggs  * Bus attachment and DMA routines for the mc driver (Centris/Quadra
     33   1.1   briggs  * 660av and Quadra 840av onboard ethernet, based on the AMD Am79C940
     34   1.1   briggs  * MACE ethernet chip). Also uses the PSC (Peripheral Subsystem
     35   1.1   briggs  * Controller) for DMA to and from the MACE.
     36   1.1   briggs  */
     37  1.12    lukem 
     38  1.12    lukem #include <sys/cdefs.h>
     39  1.17       he __KERNEL_RCSID(0, "$NetBSD: if_mc_obio.c,v 1.17 2007/03/05 21:23:49 he Exp $");
     40   1.6   scottr 
     41   1.6   scottr #include "opt_ddb.h"
     42   1.1   briggs 
     43   1.1   briggs #include <sys/param.h>
     44   1.1   briggs #include <sys/device.h>
     45   1.1   briggs #include <sys/malloc.h>
     46   1.1   briggs #include <sys/socket.h>
     47   1.1   briggs #include <sys/systm.h>
     48   1.1   briggs 
     49   1.1   briggs #include <net/if.h>
     50   1.1   briggs #include <net/if_ether.h>
     51   1.1   briggs 
     52   1.7      mrg #include <uvm/uvm_extern.h>
     53   1.1   briggs 
     54   1.1   briggs #include <machine/bus.h>
     55   1.1   briggs #include <machine/psc.h>
     56   1.1   briggs 
     57   1.5   scottr #include <mac68k/obio/obiovar.h>
     58   1.1   briggs #include <mac68k/dev/if_mcreg.h>
     59   1.1   briggs #include <mac68k/dev/if_mcvar.h>
     60   1.1   briggs 
     61   1.1   briggs #define MACE_REG_BASE	0x50F1C000
     62   1.1   briggs #define MACE_PROM_BASE	0x50F08000
     63   1.1   briggs 
     64  1.14      chs hide int	mc_obio_match(struct device *, struct cfdata *, void *);
     65  1.14      chs hide void	mc_obio_attach(struct device *, struct device *, void *);
     66  1.14      chs hide void	mc_obio_init(struct mc_softc *);
     67  1.14      chs hide void	mc_obio_put(struct mc_softc *, u_int);
     68  1.14      chs hide int	mc_dmaintr(void *);
     69  1.14      chs hide void	mc_reset_rxdma(struct mc_softc *);
     70  1.14      chs hide void	mc_reset_rxdma_set(struct mc_softc *, int);
     71  1.14      chs hide void	mc_reset_txdma(struct mc_softc *);
     72  1.14      chs hide int	mc_obio_getaddr(struct mc_softc *, u_int8_t *);
     73   1.1   briggs 
     74   1.9  thorpej CFATTACH_DECL(mc_obio, sizeof(struct mc_softc),
     75   1.9  thorpej     mc_obio_match, mc_obio_attach, NULL, NULL);
     76   1.1   briggs 
     77   1.1   briggs hide int
     78  1.14      chs mc_obio_match(struct device *parent, struct cfdata *cf, void *aux)
     79   1.1   briggs {
     80   1.1   briggs 	struct obio_attach_args *oa = aux;
     81   1.1   briggs 	bus_space_handle_t bsh;
     82   1.1   briggs 	int found = 0;
     83   1.1   briggs 
     84   1.2   briggs         if (current_mac_model->class != MACH_CLASSAV)
     85   1.1   briggs 		return 0;
     86   1.1   briggs 
     87   1.1   briggs 	if (bus_space_map(oa->oa_tag, MACE_REG_BASE, MC_REGSIZE, 0, &bsh))
     88   1.1   briggs 		return 0;
     89   1.1   briggs 
     90   1.1   briggs 	/*
     91   1.1   briggs 	 * Make sure the MACE's I/O space is readable, and if it is,
     92   1.1   briggs 	 * try to read the CHIPID register. A MACE will always have
     93   1.1   briggs 	 * 0x?940, where the ? depends on the chip version.
     94   1.1   briggs 	 */
     95   1.4   scottr 	if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0, 1)) {
     96   1.1   briggs 		if ((bus_space_read_1(
     97   1.1   briggs 			oa->oa_tag, bsh, MACE_REG(MACE_CHIPIDL)) == 0x40) &&
     98   1.1   briggs 		    ((bus_space_read_1(
     99   1.1   briggs 			oa->oa_tag, bsh, MACE_REG(MACE_CHIPIDH)) & 0xf) == 9))
    100   1.1   briggs 			found = 1;
    101   1.1   briggs 	}
    102   1.1   briggs 
    103   1.1   briggs 	bus_space_unmap(oa->oa_tag, bsh, MC_REGSIZE);
    104   1.1   briggs 
    105   1.1   briggs 	return found;
    106   1.1   briggs }
    107   1.1   briggs 
    108   1.1   briggs hide void
    109  1.14      chs mc_obio_attach(struct device *parent, struct device *self, void *aux)
    110   1.1   briggs {
    111   1.1   briggs 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    112   1.1   briggs 	struct mc_softc *sc = (void *)self;
    113   1.1   briggs 	u_int8_t myaddr[ETHER_ADDR_LEN];
    114  1.16   martin 	int rsegs;
    115   1.1   briggs 
    116   1.1   briggs 	sc->sc_regt = oa->oa_tag;
    117   1.1   briggs 	sc->sc_biucc = XMTSP_64;
    118   1.1   briggs 	sc->sc_fifocc = XMTFW_16 | RCVFW_64 | XMTFWU | RCVFWU |
    119   1.1   briggs 	    XMTBRST | RCVBRST;
    120   1.1   briggs 	sc->sc_plscc = PORTSEL_AUI;
    121   1.1   briggs 
    122   1.1   briggs 	if (bus_space_map(sc->sc_regt, MACE_REG_BASE, MC_REGSIZE, 0,
    123   1.1   briggs 	    &sc->sc_regh)) {
    124   1.1   briggs 		printf(": failed to map space for MACE regs.\n");
    125   1.1   briggs 		return;
    126   1.1   briggs 	}
    127   1.1   briggs 
    128   1.1   briggs 	if (mc_obio_getaddr(sc, myaddr)) {
    129   1.1   briggs 		printf(": failed to get MAC address.\n");
    130   1.1   briggs 		return;
    131   1.1   briggs 	}
    132   1.1   briggs 
    133  1.16   martin 	/* allocate memory for transmit and receive DMA buffers */
    134  1.16   martin 	sc->sc_dmat = oa->oa_dmat;
    135  1.16   martin 	if (bus_dmamem_alloc(sc->sc_dmat, 2 * 0x800, 0, 0, &sc->sc_dmasegs_tx,
    136  1.16   martin 		1, &rsegs, BUS_DMA_NOWAIT) != 0) {
    137  1.16   martin 		printf(": failed to allocate TX DMA buffers.\n");
    138  1.16   martin 		return;
    139  1.16   martin 	}
    140  1.16   martin 
    141  1.16   martin 	if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dmasegs_tx, rsegs, 2 * 0x800,
    142  1.17       he 		(void*)&sc->sc_txbuf, BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0) {
    143  1.16   martin 		printf(": failed to map TX DMA buffers.\n");
    144  1.16   martin 		return;
    145  1.16   martin 	}
    146  1.16   martin 
    147  1.16   martin 	if (bus_dmamem_alloc(sc->sc_dmat, MC_RXDMABUFS * 0x800, 0, 0,
    148  1.16   martin 		&sc->sc_dmasegs_rx, 1, &rsegs, BUS_DMA_NOWAIT) != 0) {
    149  1.16   martin 		printf(": failed to allocate RX DMA buffers.\n");
    150  1.16   martin 		return;
    151  1.16   martin 	}
    152  1.16   martin 
    153  1.16   martin 	if (bus_dmamem_map(sc->sc_dmat, &sc->sc_dmasegs_rx, rsegs,
    154  1.17       he 		MC_RXDMABUFS * 0x800, (void*)&sc->sc_rxbuf,
    155  1.16   martin 		BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0) {
    156  1.16   martin 		printf(": failed to map RX DMA buffers.\n");
    157  1.16   martin 		return;
    158  1.16   martin 	}
    159   1.1   briggs 
    160  1.16   martin 	if (bus_dmamap_create(sc->sc_dmat, 2 * 0x800, 1, 2 * 0x800, 0,
    161  1.16   martin 	    BUS_DMA_NOWAIT, &sc->sc_dmam_tx) != 0) {
    162  1.16   martin 		printf(": failed to allocate TX DMA map.\n");
    163  1.16   martin 		return;
    164  1.16   martin 	}
    165  1.16   martin 
    166  1.16   martin 	if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam_tx, sc->sc_txbuf,
    167  1.16   martin 		2 * 0x800, NULL, BUS_DMA_NOWAIT) != 0) {
    168  1.16   martin 		printf(": failed to map TX DMA mapping.\n");
    169  1.16   martin 		return;
    170   1.1   briggs 	}
    171   1.1   briggs 
    172  1.16   martin 	if (bus_dmamap_create(sc->sc_dmat, MC_RXDMABUFS * 0x800, 1,
    173  1.16   martin 		MC_RXDMABUFS * 0x800, 0, BUS_DMA_NOWAIT, &sc->sc_dmam_rx) != 0) {
    174  1.16   martin 		printf(": failed to allocate RX DMA map.\n");
    175  1.16   martin 		return;
    176  1.16   martin 	}
    177  1.16   martin 
    178  1.16   martin 	if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmam_rx, sc->sc_rxbuf,
    179  1.16   martin 		MC_RXDMABUFS * 0x800, NULL, BUS_DMA_NOWAIT) != 0) {
    180  1.16   martin 		printf(": failed to map RX DMA mapping.\n");
    181   1.1   briggs 		return;
    182   1.1   briggs 	}
    183   1.1   briggs 
    184  1.16   martin 	sc->sc_txbuf_phys = sc->sc_dmasegs_tx.ds_addr;
    185  1.16   martin 	sc->sc_rxbuf_phys = sc->sc_dmasegs_rx.ds_addr;
    186  1.16   martin 
    187   1.1   briggs 	sc->sc_bus_init = mc_obio_init;
    188   1.1   briggs 	sc->sc_putpacket = mc_obio_put;
    189   1.1   briggs 
    190   1.1   briggs 	/* disable receive DMA */
    191   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x8800;
    192   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x1000;
    193   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + PSC_SET0) = 0x1100;
    194   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + PSC_SET1) = 0x1100;
    195   1.1   briggs 
    196   1.1   briggs 	/* disable transmit DMA */
    197   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x8800;
    198   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x1000;
    199   1.1   briggs 	psc_reg2(PSC_ENETWR_CMD + PSC_SET0) = 0x1100;
    200   1.1   briggs 	psc_reg2(PSC_ENETWR_CMD + PSC_SET1) = 0x1100;
    201   1.1   briggs 
    202   1.1   briggs 	/* install interrupt handlers */
    203   1.1   briggs 	add_psc_lev4_intr(PSCINTR_ENET_DMA, mc_dmaintr, sc);
    204   1.1   briggs 	add_psc_lev3_intr(mcintr, sc);
    205   1.1   briggs 
    206   1.1   briggs 	/* enable MACE DMA interrupts */
    207   1.1   briggs 	psc_reg1(PSC_LEV4_IER) = 0x80 | (1 << PSCINTR_ENET_DMA);
    208   1.1   briggs 
    209   1.1   briggs 	/* don't know what this does */
    210   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x9000;
    211   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x9000;
    212   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x0400;
    213   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x0400;
    214   1.1   briggs 
    215   1.1   briggs 	/* enable MACE interrupts */
    216   1.1   briggs 	psc_reg1(PSC_LEV3_IER) = 0x80 | (1 << PSCINTR_ENET);
    217   1.1   briggs 
    218   1.1   briggs 	/* mcsetup returns 1 if something fails */
    219   1.1   briggs 	if (mcsetup(sc, myaddr)) {
    220   1.1   briggs 		/* disable interrupts */
    221   1.1   briggs 		psc_reg1(PSC_LEV4_IER) = (1 << PSCINTR_ENET_DMA);
    222   1.1   briggs 		psc_reg1(PSC_LEV3_IER) = (1 << PSCINTR_ENET);
    223   1.1   briggs 		/* remove interrupt handlers */
    224   1.1   briggs 		remove_psc_lev4_intr(PSCINTR_ENET_DMA);
    225   1.1   briggs 		remove_psc_lev3_intr();
    226   1.1   briggs 
    227   1.1   briggs 		bus_space_unmap(sc->sc_regt, sc->sc_regh, MC_REGSIZE);
    228   1.1   briggs 		return;
    229   1.1   briggs 	}
    230   1.1   briggs }
    231   1.1   briggs 
    232   1.1   briggs /* Bus-specific initialization */
    233   1.1   briggs hide void
    234  1.14      chs mc_obio_init(struct mc_softc *sc)
    235   1.1   briggs {
    236   1.1   briggs 	mc_reset_rxdma(sc);
    237   1.1   briggs 	mc_reset_txdma(sc);
    238   1.1   briggs }
    239   1.1   briggs 
    240   1.1   briggs hide void
    241  1.14      chs mc_obio_put(struct mc_softc *sc, u_int len)
    242   1.1   briggs {
    243  1.16   martin 	int offset = sc->sc_txset == 0 ? 0 : 0x800;
    244  1.16   martin 
    245  1.16   martin 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmam_tx, offset, 0x800,
    246  1.16   martin 	    BUS_DMASYNC_PREWRITE);
    247  1.16   martin 	psc_reg4(PSC_ENETWR_ADDR + sc->sc_txset) = sc->sc_txbuf_phys + offset;
    248   1.1   briggs 	psc_reg4(PSC_ENETWR_LEN + sc->sc_txset) = len;
    249   1.1   briggs 	psc_reg2(PSC_ENETWR_CMD + sc->sc_txset) = 0x9800;
    250  1.16   martin 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmam_tx, offset, 0x800,
    251  1.16   martin 	    BUS_DMASYNC_POSTWRITE);
    252   1.1   briggs 
    253   1.1   briggs 	sc->sc_txset ^= 0x10;
    254   1.1   briggs }
    255   1.1   briggs 
    256   1.1   briggs /*
    257   1.1   briggs  * Interrupt handler for the MACE DMA completion interrupts
    258   1.1   briggs  */
    259   1.1   briggs int
    260  1.14      chs mc_dmaintr(void *arg)
    261   1.1   briggs {
    262   1.1   briggs 	struct mc_softc *sc = arg;
    263   1.1   briggs 	u_int16_t status;
    264   1.1   briggs 	u_int32_t bufsleft, which;
    265   1.1   briggs 	int head;
    266   1.1   briggs 
    267   1.1   briggs 	/*
    268   1.1   briggs 	 * Not sure what this does... figure out if this interrupt is
    269   1.1   briggs 	 * really ours?
    270   1.1   briggs 	 */
    271   1.1   briggs 	while ((which = psc_reg4(0x804)) != psc_reg4(0x804))
    272   1.1   briggs 		;
    273   1.1   briggs 	if ((which & 0x60000000) == 0)
    274   1.1   briggs 		return 0;
    275   1.1   briggs 
    276   1.1   briggs 	/* Get the read channel status */
    277   1.1   briggs 	status = psc_reg2(PSC_ENETRD_CTL);
    278   1.1   briggs 	if (status & 0x2000) {
    279   1.1   briggs 		/* I think this is an exceptional condition. Reset the DMA */
    280   1.1   briggs 		mc_reset_rxdma(sc);
    281   1.1   briggs #ifdef MCDEBUG
    282   1.1   briggs 		printf("%s: resetting receive DMA channel (status 0x%04x)\n",
    283   1.1   briggs 		    sc->sc_dev.dv_xname, status);
    284   1.1   briggs #endif
    285   1.1   briggs 	} else if (status & 0x100) {
    286   1.1   briggs 		/* We've received some packets from the MACE */
    287   1.1   briggs 		int offset;
    288   1.1   briggs 
    289   1.1   briggs 		/* Clear the interrupt */
    290   1.1   briggs 		psc_reg2(PSC_ENETRD_CMD + sc->sc_rxset) = 0x1100;
    291   1.1   briggs 
    292   1.1   briggs 		/* See how may receive buffers are left */
    293   1.1   briggs 		bufsleft = psc_reg4(PSC_ENETRD_LEN + sc->sc_rxset);
    294   1.1   briggs 		head = MC_RXDMABUFS - bufsleft;
    295   1.1   briggs 
    296   1.1   briggs #if 0 /* I don't think this should ever happen */
    297   1.1   briggs 		if (head == sc->sc_tail) {
    298   1.1   briggs #ifdef MCDEBUG
    299   1.1   briggs 			printf("%s: head == tail: suspending DMA?\n",
    300   1.1   briggs 			    sc->sc_dev.dv_xname);
    301   1.1   briggs #endif
    302   1.1   briggs 			psc_reg2(PSC_ENETRD_CMD + sc->sc_rxset) = 0x9000;
    303   1.1   briggs 		}
    304   1.1   briggs #endif
    305   1.1   briggs 
    306   1.1   briggs 		/* Loop through, processing each of the packets */
    307   1.1   briggs 		for (; sc->sc_tail < head; sc->sc_tail++) {
    308   1.1   briggs 			offset = sc->sc_tail * 0x800;
    309  1.16   martin 
    310  1.16   martin 			bus_dmamap_sync(sc->sc_dmat, sc->sc_dmam_rx,
    311  1.16   martin 					PAGE_SIZE + offset, 0x800,
    312  1.16   martin 					BUS_DMASYNC_PREREAD);
    313  1.16   martin 
    314   1.1   briggs 			sc->sc_rxframe.rx_rcvcnt = sc->sc_rxbuf[offset];
    315   1.1   briggs 			sc->sc_rxframe.rx_rcvsts = sc->sc_rxbuf[offset+2];
    316   1.1   briggs 			sc->sc_rxframe.rx_rntpc = sc->sc_rxbuf[offset+4];
    317   1.1   briggs 			sc->sc_rxframe.rx_rcvcc = sc->sc_rxbuf[offset+6];
    318   1.1   briggs 			sc->sc_rxframe.rx_frame = sc->sc_rxbuf + offset + 16;
    319   1.1   briggs 
    320   1.1   briggs 			mc_rint(sc);
    321  1.16   martin 
    322  1.16   martin 			bus_dmamap_sync(sc->sc_dmat, sc->sc_dmam_rx,
    323  1.16   martin 					PAGE_SIZE + offset, 0x800,
    324  1.16   martin 					BUS_DMASYNC_POSTREAD);
    325   1.1   briggs 		}
    326   1.1   briggs 
    327   1.1   briggs 		/*
    328   1.1   briggs 		 * If we're out of buffers, reset this register set
    329   1.1   briggs 		 * and switch to the other one. Otherwise, reactivate
    330   1.1   briggs 		 * this set.
    331   1.1   briggs 		 */
    332   1.1   briggs 		if (bufsleft == 0) {
    333   1.1   briggs 			mc_reset_rxdma_set(sc, sc->sc_rxset);
    334   1.1   briggs 			sc->sc_rxset ^= 0x10;
    335   1.1   briggs 		} else
    336   1.1   briggs 			psc_reg2(PSC_ENETRD_CMD + sc->sc_rxset) = 0x9800;
    337   1.1   briggs 	}
    338   1.1   briggs 
    339   1.1   briggs 	/* Get the write channel status */
    340   1.1   briggs 	status = psc_reg2(PSC_ENETWR_CTL);
    341   1.1   briggs 	if (status & 0x2000) {
    342   1.1   briggs 		/* I think this is an exceptional condition. Reset the DMA */
    343   1.1   briggs 		mc_reset_txdma(sc);
    344   1.1   briggs #ifdef MCDEBUG
    345   1.1   briggs 		printf("%s: resetting transmit DMA channel (status 0x%04x)\n",
    346   1.1   briggs 			sc->sc_dev.dv_xname, status);
    347   1.1   briggs #endif
    348   1.1   briggs 	} else if (status & 0x100) {
    349   1.1   briggs 		/* Clear the interrupt and switch register sets */
    350   1.1   briggs 		psc_reg2(PSC_ENETWR_CMD + sc->sc_txseti) = 0x100;
    351   1.1   briggs 		sc->sc_txseti ^= 0x10;
    352   1.1   briggs 	}
    353   1.1   briggs 
    354   1.1   briggs 	return 1;
    355   1.1   briggs }
    356   1.1   briggs 
    357   1.1   briggs 
    358   1.1   briggs hide void
    359  1.14      chs mc_reset_rxdma(struct mc_softc *sc)
    360   1.1   briggs {
    361   1.1   briggs 	u_int8_t maccc;
    362   1.1   briggs 
    363   1.1   briggs 	/* Disable receiver, reset the DMA channels */
    364   1.1   briggs 	maccc = NIC_GET(sc, MACE_MACCC);
    365   1.1   briggs 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENRCV);
    366   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x8800;
    367   1.1   briggs 	mc_reset_rxdma_set(sc, 0);
    368   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x400;
    369   1.1   briggs 
    370   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x8800;
    371   1.1   briggs 	mc_reset_rxdma_set(sc, 0x10);
    372   1.1   briggs 	psc_reg2(PSC_ENETRD_CTL) = 0x400;
    373   1.1   briggs 
    374   1.1   briggs 	/* Reenable receiver, reenable DMA */
    375   1.1   briggs 	NIC_PUT(sc, MACE_MACCC, maccc);
    376   1.1   briggs 	sc->sc_rxset = 0;
    377   1.1   briggs 
    378   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + PSC_SET0) = 0x9800;
    379   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + PSC_SET1) = 0x9800;
    380   1.1   briggs }
    381   1.1   briggs 
    382   1.1   briggs hide void
    383  1.14      chs mc_reset_rxdma_set(struct mc_softc *sc, int set)
    384   1.1   briggs {
    385   1.1   briggs 	/* disable DMA while modifying the registers, then reenable DMA */
    386   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + set) = 0x0100;
    387   1.1   briggs 	psc_reg4(PSC_ENETRD_ADDR + set) = sc->sc_rxbuf_phys;
    388   1.1   briggs 	psc_reg4(PSC_ENETRD_LEN + set) = MC_RXDMABUFS;
    389   1.1   briggs 	psc_reg2(PSC_ENETRD_CMD + set) = 0x9800;
    390   1.1   briggs 	sc->sc_tail = 0;
    391   1.1   briggs }
    392   1.1   briggs 
    393   1.1   briggs hide void
    394  1.14      chs mc_reset_txdma(struct mc_softc *sc)
    395   1.1   briggs {
    396   1.1   briggs 	u_int8_t maccc;
    397   1.1   briggs 
    398   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x8800;
    399   1.1   briggs 	maccc = NIC_GET(sc, MACE_MACCC);
    400   1.1   briggs 	NIC_PUT(sc, MACE_MACCC, maccc & ~ENXMT);
    401   1.1   briggs 	sc->sc_txset = sc->sc_txseti = 0;
    402   1.1   briggs 	psc_reg2(PSC_ENETWR_CTL) = 0x400;
    403   1.1   briggs 	NIC_PUT(sc, MACE_MACCC, maccc);
    404   1.1   briggs }
    405   1.1   briggs 
    406   1.1   briggs hide int
    407  1.14      chs mc_obio_getaddr(struct mc_softc *sc, u_int8_t *lladdr)
    408   1.1   briggs {
    409   1.1   briggs 	bus_space_handle_t bsh;
    410   1.1   briggs 	u_char csum;
    411   1.1   briggs 
    412   1.1   briggs 	if (bus_space_map(sc->sc_regt, MACE_PROM_BASE, 8*16, 0, &bsh)) {
    413   1.1   briggs 		printf(": failed to map space to read MACE address.\n%s",
    414   1.1   briggs 		    sc->sc_dev.dv_xname);
    415   1.1   briggs 		return (-1);
    416   1.1   briggs 	}
    417   1.1   briggs 
    418   1.4   scottr 	if (!mac68k_bus_space_probe(sc->sc_regt, bsh, 0, 1)) {
    419   1.1   briggs 		bus_space_unmap(sc->sc_regt, bsh, 8*16);
    420   1.1   briggs 		return (-1);
    421   1.1   briggs 	}
    422   1.1   briggs 
    423   1.1   briggs 	csum = mc_get_enaddr(sc->sc_regt, bsh, 1, lladdr);
    424   1.1   briggs 	if (csum != 0xff)
    425   1.1   briggs 		printf(": ethernet PROM checksum failed (0x%x != 0xff)\n%s",
    426   1.1   briggs 		    (int)csum, sc->sc_dev.dv_xname);
    427   1.1   briggs 
    428   1.1   briggs 	bus_space_unmap(sc->sc_regt, bsh, 8*16);
    429   1.1   briggs 
    430   1.1   briggs 	return (csum == 0xff ? 0 : -1);
    431   1.1   briggs }
    432