if_xe.c revision 1.5.16.1 1 /* $NetBSD: if_xe.c,v 1.5.16.1 2002/07/16 12:58:56 gehenna 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 #include <next68k/dev/bmapreg.h>
67
68 int xe_match __P((struct device *, struct cfdata *, void *));
69 void xe_attach __P((struct device *, struct device *, void *));
70 int xe_tint __P((void *));
71 int xe_rint __P((void *));
72
73 struct cfattach xe_ca = {
74 sizeof(struct xe_softc), xe_match, xe_attach
75 };
76
77 static int mb8795_medias[] = {
78 IFM_ETHER|IFM_AUTO,
79 IFM_ETHER|IFM_10_T,
80 IFM_ETHER|IFM_10_2,
81 };
82 static int nmb8795_medias = (sizeof(mb8795_medias)/sizeof(mb8795_medias[0]));
83
84 int
85 xe_match(parent, match, aux)
86 struct device *parent;
87 struct cfdata *match;
88 void *aux;
89 {
90 /* should probably probe here */
91 /* Should also probably set up data from config */
92 return (1);
93 }
94
95 void
96 xe_attach(parent, self, aux)
97 struct device *parent, *self;
98 void *aux;
99 {
100 struct xe_softc *xe_sc = (struct xe_softc *)self;
101 struct mb8795_softc *sc = &xe_sc->sc_mb8795;
102
103
104 {
105 extern u_char rom_enetaddr[6]; /* kludge from machdep.c:next68k_bootargs() */
106 int i;
107 for(i=0;i<6;i++) {
108 sc->sc_enaddr[i] = rom_enetaddr[i];
109 }
110 }
111
112 printf("\n%s at MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
113 sc->sc_dev.dv_xname,
114 sc->sc_enaddr[0],sc->sc_enaddr[1],sc->sc_enaddr[2],
115 sc->sc_enaddr[3],sc->sc_enaddr[4],sc->sc_enaddr[5]);
116
117 /* @@@ This setup is really ugly. Instead, we should be attaching
118 * the DMA controller all by itself and glue things together
119 * with config.
120 * Darrin B. Jewell <dbj (at) netbsd.org> Sat May 16 16:04:34 1998
121 */
122
123 sc->sc_bst = NEXT68K_INTIO_BUS_SPACE;
124
125 if (bus_space_map(sc->sc_bst, NEXT_P_ENET,
126 XE_SIZE, 0, &sc->sc_bsh)) {
127 printf("\n%s: can't map mb8795 registers\n",
128 sc->sc_dev.dv_xname);
129 return;
130 }
131
132 sc->sc_bmap_bst = NEXT68K_INTIO_BUS_SPACE;
133 if (bus_space_map(sc->sc_bmap_bst, NEXT_P_BMAP,
134 BMAP_SIZE, 0, &sc->sc_bmap_bsh)) {
135 printf("\n%s: can't map bmap registers\n",
136 sc->sc_dev.dv_xname);
137 return;
138 }
139
140 /* initialize rx and tx dma channels */
141 xe_sc->sc_rxdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
142
143 if (bus_space_map(xe_sc->sc_rxdma.nd_bst, NEXT_P_ENETR_CSR,
144 DD_SIZE, 0, &xe_sc->sc_rxdma.nd_bsh)) {
145 printf("\n%s: can't map ethernet receive DMA registers\n",
146 sc->sc_dev.dv_xname);
147 return;
148 }
149 xe_sc->sc_rxdma.nd_intr = NEXT_I_ENETR_DMA;
150 xe_sc->sc_rxdma.nd_continue_cb = NULL;
151 xe_sc->sc_rxdma.nd_completed_cb = NULL;
152 xe_sc->sc_rxdma.nd_shutdown_cb = NULL;
153 xe_sc->sc_rxdma.nd_cb_arg = NULL;
154 sc->sc_rx_dmat = &(xe_sc->sc_rxdma._nd_dmat);
155 sc->sc_rx_nd = &(xe_sc->sc_rxdma);
156 nextdma_config(sc->sc_rx_nd);
157
158 xe_sc->sc_txdma.nd_bst = NEXT68K_INTIO_BUS_SPACE;
159 if (bus_space_map(xe_sc->sc_txdma.nd_bst, NEXT_P_ENETX_CSR,
160 DD_SIZE, 0, &xe_sc->sc_txdma.nd_bsh)) {
161 printf("\n%s: can't map ethernet transmit DMA registers\n",
162 sc->sc_dev.dv_xname);
163 return;
164 }
165 xe_sc->sc_txdma.nd_intr = NEXT_I_ENETX_DMA;
166 xe_sc->sc_txdma.nd_continue_cb = NULL;
167 xe_sc->sc_txdma.nd_completed_cb = NULL;
168 xe_sc->sc_txdma.nd_shutdown_cb = NULL;
169 xe_sc->sc_txdma.nd_cb_arg = NULL;
170 sc->sc_tx_dmat = &(xe_sc->sc_txdma._nd_dmat);
171 sc->sc_tx_nd = &(xe_sc->sc_txdma);
172 nextdma_config(sc->sc_tx_nd);
173
174 mb8795_config(sc, mb8795_medias, nmb8795_medias, mb8795_medias[0]);
175
176 isrlink_autovec(xe_tint, sc, NEXT_I_IPL(NEXT_I_ENETX), 1);
177 INTR_ENABLE(NEXT_I_ENETX);
178 isrlink_autovec(xe_rint, sc, NEXT_I_IPL(NEXT_I_ENETR), 1);
179 INTR_ENABLE(NEXT_I_ENETR);
180 }
181
182
183 int
184 xe_tint(arg)
185 void *arg;
186 {
187 if (!INTR_OCCURRED(NEXT_I_ENETX)) return 0;
188 mb8795_tint((struct mb8795_softc *)arg);
189 return(1);
190 }
191
192 int
193 xe_rint(arg)
194 void *arg;
195 {
196 if (!INTR_OCCURRED(NEXT_I_ENETR)) return(0);
197 mb8795_rint((struct mb8795_softc *)arg);
198 return(1);
199 }
200