Home | History | Annotate | Line # | Download | only in dev
if_xe.c revision 1.1
      1 /*	$NetBSD: if_xe.c,v 1.1 1998/06/09 07:53:05 dbj 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 "bpfilter.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/mbuf.h>
     37 #include <sys/syslog.h>
     38 #include <sys/socket.h>
     39 #include <sys/device.h>
     40 
     41 #include <net/if.h>
     42 #include <net/if_ether.h>
     43 #include <net/if_media.h>
     44 
     45 #ifdef INET
     46 #include <netinet/in.h>
     47 #include <netinet/if_inarp.h>
     48 #endif
     49 
     50 #include <machine/autoconf.h>
     51 #include <machine/cpu.h>
     52 #include <machine/intr.h>
     53 #include <machine/bus.h>
     54 
     55 #include <next68k/next68k/isr.h>
     56 
     57 #include <next68k/dev/mb8795reg.h>
     58 #include <next68k/dev/mb8795var.h>
     59 
     60 #include <next68k/dev/nextdmareg.h>
     61 #include <next68k/dev/nextdmavar.h>
     62 
     63 #include <next68k/dev/if_xevar.h>
     64 
     65 
     66 int	xe_match __P((struct device *, struct cfdata *, void *));
     67 void	xe_attach __P((struct device *, struct device *, void *));
     68 int	xe_tint __P((void *));
     69 int	xe_rint __P((void *));
     70 
     71 struct cfattach xe_ca = {
     72 	sizeof(struct xe_softc), xe_match, xe_attach
     73 };
     74 
     75 int
     76 xe_match(parent, match, aux)
     77 	struct device *parent;
     78 	struct cfdata *match;
     79 	void *aux;
     80 {
     81   /* should probably probe here */
     82   /* Should also probably set up data from config */
     83   return (1);
     84 }
     85 
     86 void
     87 xe_attach(parent, self, aux)
     88 	struct device *parent, *self;
     89 	void *aux;
     90 {
     91   struct xe_softc *xe_sc = (struct xe_softc *)self;
     92   struct mb8795_softc *sc = &xe_sc->sc_mb8795;
     93 
     94 
     95   {
     96     extern u_char rom_enetaddr[6];     /* kludge from machdep.c:next68k_bootargs() */
     97     int i;
     98     for(i=0;i<6;i++) {
     99       sc->sc_enaddr[i] = rom_enetaddr[i];
    100     }
    101   }
    102 
    103   printf("\n%s at MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
    104          sc->sc_dev.dv_xname,
    105          sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
    106          sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5]);
    107 
    108   /* @@@ This setup is really ugly.  Instead, we should be attaching
    109 	 * the DMA controller all by itself and glue things together
    110 	 * with config.
    111 	 * Darrin B. Jewell <dbj (at) netbsd.org>  Sat May 16 16:04:34 1998
    112 	 */
    113 
    114   sc->sc_bst = NEXT68K_INTIO_BUS_SPACE;
    115 
    116   if (bus_space_map(sc->sc_bst, NEXT_P_ENET,
    117                     sizeof(struct xe_regs), 0, &sc->sc_bsh)) {
    118     printf("\n%s: can't map mb8795 registers\n",
    119            sc->sc_dev.dv_xname);
    120     return;
    121   }
    122 
    123   /* initialize rx and tx dma channels */
    124 	xe_sc->sc_rxdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
    125 
    126 	if (bus_space_map(xe_sc->sc_rxdma.nd_bst, NEXT_P_ENETR_CSR,
    127 			sizeof(struct dma_dev), BUS_SPACE_MAP_LINEAR, &xe_sc->sc_rxdma.nd_bsh)) {
    128 		printf("\n%s: can't map ethernet receive DMA registers\n",
    129 				sc->sc_dev.dv_xname);
    130 		return;
    131 	}
    132   xe_sc->sc_rxdma.nd_intr = NEXT_I_ENETR_DMA;
    133 	xe_sc->sc_rxdma.nd_continue_cb = NULL;
    134 	xe_sc->sc_rxdma.nd_completed_cb = NULL;
    135 	xe_sc->sc_rxdma.nd_cb_arg = NULL;
    136   sc->sc_rx_dmat = &(xe_sc->sc_rxdma._nd_dmat);
    137 	sc->sc_rx_nd = &(xe_sc->sc_rxdma);
    138 	nextdma_config(sc->sc_rx_nd);
    139 
    140 	xe_sc->sc_txdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
    141 	if (bus_space_map(xe_sc->sc_txdma.nd_bst, NEXT_P_ENETX_CSR,
    142 			sizeof(struct dma_dev), BUS_SPACE_MAP_LINEAR, &xe_sc->sc_txdma.nd_bsh)) {
    143 		printf("\n%s: can't map ethernet transmit DMA registers\n",
    144 				sc->sc_dev.dv_xname);
    145 		return;
    146 	}
    147   xe_sc->sc_txdma.nd_intr = NEXT_I_ENETX_DMA;
    148 	xe_sc->sc_txdma.nd_continue_cb = NULL;
    149 	xe_sc->sc_txdma.nd_completed_cb = NULL;
    150 	xe_sc->sc_txdma.nd_cb_arg = NULL;
    151   sc->sc_tx_dmat = &(xe_sc->sc_txdma._nd_dmat);
    152 	sc->sc_tx_nd = &(xe_sc->sc_txdma);
    153 	nextdma_config(sc->sc_tx_nd);
    154 
    155   mb8795_config(sc);
    156 
    157   isrlink_autovec(xe_tint, sc, NEXT_I_IPL(NEXT_I_ENETX), 0);
    158   INTR_ENABLE(NEXT_I_ENETX);
    159   isrlink_autovec(xe_rint, sc, NEXT_I_IPL(NEXT_I_ENETR), 0);
    160   INTR_ENABLE(NEXT_I_ENETR);
    161 
    162   {
    163     extern struct device *booted_device;
    164     booted_device = &(sc->sc_dev);
    165   }
    166 }
    167 
    168 
    169 int
    170 xe_tint(arg)
    171      void *arg;
    172 {
    173   if (!INTR_OCCURRED(NEXT_I_ENETX)) return 0;
    174   mb8795_tint((struct mb8795_softc *)arg);
    175   return(1);
    176 }
    177 
    178 int
    179 xe_rint(arg)
    180      void *arg;
    181 {
    182   if (!INTR_OCCURRED(NEXT_I_ENETR)) return(0);
    183   mb8795_rint((struct mb8795_softc *)arg);
    184   return(1);
    185 }
    186