xref: /netbsd/sys/arch/next68k/dev/if_xe.c (revision bf9ec67e)
1 /*	$NetBSD: if_xe.c,v 1.5 2001/03/31 06:56:54 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 "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@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                     XE_SIZE, 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 			DD_SIZE, 0, &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_shutdown_cb = NULL;
137 	xe_sc->sc_rxdma.nd_cb_arg = NULL;
138   sc->sc_rx_dmat = &(xe_sc->sc_rxdma._nd_dmat);
139 	sc->sc_rx_nd = &(xe_sc->sc_rxdma);
140 	nextdma_config(sc->sc_rx_nd);
141 
142 	xe_sc->sc_txdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
143 	if (bus_space_map(xe_sc->sc_txdma.nd_bst, NEXT_P_ENETX_CSR,
144 			DD_SIZE, 0, &xe_sc->sc_txdma.nd_bsh)) {
145 		printf("\n%s: can't map ethernet transmit DMA registers\n",
146 				sc->sc_dev.dv_xname);
147 		return;
148 	}
149   xe_sc->sc_txdma.nd_intr = NEXT_I_ENETX_DMA;
150 	xe_sc->sc_txdma.nd_continue_cb = NULL;
151 	xe_sc->sc_txdma.nd_completed_cb = NULL;
152 	xe_sc->sc_txdma.nd_shutdown_cb = NULL;
153 	xe_sc->sc_txdma.nd_cb_arg = NULL;
154   sc->sc_tx_dmat = &(xe_sc->sc_txdma._nd_dmat);
155 	sc->sc_tx_nd = &(xe_sc->sc_txdma);
156 	nextdma_config(sc->sc_tx_nd);
157 
158   mb8795_config(sc);
159 
160   isrlink_autovec(xe_tint, sc, NEXT_I_IPL(NEXT_I_ENETX), 1);
161   INTR_ENABLE(NEXT_I_ENETX);
162   isrlink_autovec(xe_rint, sc, NEXT_I_IPL(NEXT_I_ENETR), 1);
163   INTR_ENABLE(NEXT_I_ENETR);
164 
165   booted_device = &(sc->sc_dev);
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