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