Home | History | Annotate | Line # | Download | only in dev
if_xe.c revision 1.2
      1 /*	$NetBSD: if_xe.c,v 1.2 1998/07/05 00:51:12 jonathan Exp $	*/
      2 /*
      3  * Copyright (c) 1998 Darrin B. Jewell
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Darrin B. Jewell
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include "opt_inet.h"
     33 #include "bpfilter.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/mbuf.h>
     38 #include <sys/syslog.h>
     39 #include <sys/socket.h>
     40 #include <sys/device.h>
     41 
     42 #include <net/if.h>
     43 #include <net/if_ether.h>
     44 #include <net/if_media.h>
     45 
     46 #ifdef INET
     47 #include <netinet/in.h>
     48 #include <netinet/if_inarp.h>
     49 #endif
     50 
     51 #include <machine/autoconf.h>
     52 #include <machine/cpu.h>
     53 #include <machine/intr.h>
     54 #include <machine/bus.h>
     55 
     56 #include <next68k/next68k/isr.h>
     57 
     58 #include <next68k/dev/mb8795reg.h>
     59 #include <next68k/dev/mb8795var.h>
     60 
     61 #include <next68k/dev/nextdmareg.h>
     62 #include <next68k/dev/nextdmavar.h>
     63 
     64 #include <next68k/dev/if_xevar.h>
     65 
     66 
     67 int	xe_match __P((struct device *, struct cfdata *, void *));
     68 void	xe_attach __P((struct device *, struct device *, void *));
     69 int	xe_tint __P((void *));
     70 int	xe_rint __P((void *));
     71 
     72 struct cfattach xe_ca = {
     73 	sizeof(struct xe_softc), xe_match, xe_attach
     74 };
     75 
     76 int
     77 xe_match(parent, match, aux)
     78 	struct device *parent;
     79 	struct cfdata *match;
     80 	void *aux;
     81 {
     82   /* should probably probe here */
     83   /* Should also probably set up data from config */
     84   return (1);
     85 }
     86 
     87 void
     88 xe_attach(parent, self, aux)
     89 	struct device *parent, *self;
     90 	void *aux;
     91 {
     92   struct xe_softc *xe_sc = (struct xe_softc *)self;
     93   struct mb8795_softc *sc = &xe_sc->sc_mb8795;
     94 
     95 
     96   {
     97     extern u_char rom_enetaddr[6];     /* kludge from machdep.c:next68k_bootargs() */
     98     int i;
     99     for(i=0;i<6;i++) {
    100       sc->sc_enaddr[i] = rom_enetaddr[i];
    101     }
    102   }
    103 
    104   printf("\n%s at MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
    105          sc->sc_dev.dv_xname,
    106          sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
    107          sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5]);
    108 
    109   /* @@@ This setup is really ugly.  Instead, we should be attaching
    110 	 * the DMA controller all by itself and glue things together
    111 	 * with config.
    112 	 * Darrin B. Jewell <dbj (at) netbsd.org>  Sat May 16 16:04:34 1998
    113 	 */
    114 
    115   sc->sc_bst = NEXT68K_INTIO_BUS_SPACE;
    116 
    117   if (bus_space_map(sc->sc_bst, NEXT_P_ENET,
    118                     sizeof(struct xe_regs), 0, &sc->sc_bsh)) {
    119     printf("\n%s: can't map mb8795 registers\n",
    120            sc->sc_dev.dv_xname);
    121     return;
    122   }
    123 
    124   /* initialize rx and tx dma channels */
    125 	xe_sc->sc_rxdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
    126 
    127 	if (bus_space_map(xe_sc->sc_rxdma.nd_bst, NEXT_P_ENETR_CSR,
    128 			sizeof(struct dma_dev), BUS_SPACE_MAP_LINEAR, &xe_sc->sc_rxdma.nd_bsh)) {
    129 		printf("\n%s: can't map ethernet receive DMA registers\n",
    130 				sc->sc_dev.dv_xname);
    131 		return;
    132 	}
    133   xe_sc->sc_rxdma.nd_intr = NEXT_I_ENETR_DMA;
    134 	xe_sc->sc_rxdma.nd_continue_cb = NULL;
    135 	xe_sc->sc_rxdma.nd_completed_cb = NULL;
    136 	xe_sc->sc_rxdma.nd_cb_arg = NULL;
    137   sc->sc_rx_dmat = &(xe_sc->sc_rxdma._nd_dmat);
    138 	sc->sc_rx_nd = &(xe_sc->sc_rxdma);
    139 	nextdma_config(sc->sc_rx_nd);
    140 
    141 	xe_sc->sc_txdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
    142 	if (bus_space_map(xe_sc->sc_txdma.nd_bst, NEXT_P_ENETX_CSR,
    143 			sizeof(struct dma_dev), BUS_SPACE_MAP_LINEAR, &xe_sc->sc_txdma.nd_bsh)) {
    144 		printf("\n%s: can't map ethernet transmit DMA registers\n",
    145 				sc->sc_dev.dv_xname);
    146 		return;
    147 	}
    148   xe_sc->sc_txdma.nd_intr = NEXT_I_ENETX_DMA;
    149 	xe_sc->sc_txdma.nd_continue_cb = NULL;
    150 	xe_sc->sc_txdma.nd_completed_cb = NULL;
    151 	xe_sc->sc_txdma.nd_cb_arg = NULL;
    152   sc->sc_tx_dmat = &(xe_sc->sc_txdma._nd_dmat);
    153 	sc->sc_tx_nd = &(xe_sc->sc_txdma);
    154 	nextdma_config(sc->sc_tx_nd);
    155 
    156   mb8795_config(sc);
    157 
    158   isrlink_autovec(xe_tint, sc, NEXT_I_IPL(NEXT_I_ENETX), 0);
    159   INTR_ENABLE(NEXT_I_ENETX);
    160   isrlink_autovec(xe_rint, sc, NEXT_I_IPL(NEXT_I_ENETR), 0);
    161   INTR_ENABLE(NEXT_I_ENETR);
    162 
    163   {
    164     extern struct device *booted_device;
    165     booted_device = &(sc->sc_dev);
    166   }
    167 }
    168 
    169 
    170 int
    171 xe_tint(arg)
    172      void *arg;
    173 {
    174   if (!INTR_OCCURRED(NEXT_I_ENETX)) return 0;
    175   mb8795_tint((struct mb8795_softc *)arg);
    176   return(1);
    177 }
    178 
    179 int
    180 xe_rint(arg)
    181      void *arg;
    182 {
    183   if (!INTR_OCCURRED(NEXT_I_ENETR)) return(0);
    184   mb8795_rint((struct mb8795_softc *)arg);
    185   return(1);
    186 }
    187