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