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