if_le.c revision 1.25.8.2 1 1.25.8.2 nathanw /* $NetBSD: if_le.c,v 1.25.8.2 2002/10/18 02:38:57 nathanw Exp $ */
2 1.25.8.2 nathanw
3 1.25.8.2 nathanw /*-
4 1.25.8.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.25.8.2 nathanw * All rights reserved.
6 1.25.8.2 nathanw *
7 1.25.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.25.8.2 nathanw * by Charles M. Hannum.
9 1.25.8.2 nathanw *
10 1.25.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.25.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.25.8.2 nathanw * are met:
13 1.25.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.25.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.25.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.25.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.25.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.25.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.25.8.2 nathanw * must display the following acknowledgement:
20 1.25.8.2 nathanw * This product includes software developed by the NetBSD
21 1.25.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.25.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.25.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.25.8.2 nathanw * from this software without specific prior written permission.
25 1.25.8.2 nathanw *
26 1.25.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.25.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.25.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.25.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.25.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.25.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.25.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.25.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.25.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.25.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.25.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.25.8.2 nathanw */
38 1.25.8.2 nathanw
39 1.25.8.2 nathanw /*-
40 1.25.8.2 nathanw * Copyright (c) 1992, 1993
41 1.25.8.2 nathanw * The Regents of the University of California. All rights reserved.
42 1.25.8.2 nathanw *
43 1.25.8.2 nathanw * This code is derived from software contributed to Berkeley by
44 1.25.8.2 nathanw * Ralph Campbell and Rick Macklem.
45 1.25.8.2 nathanw *
46 1.25.8.2 nathanw * Redistribution and use in source and binary forms, with or without
47 1.25.8.2 nathanw * modification, are permitted provided that the following conditions
48 1.25.8.2 nathanw * are met:
49 1.25.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
50 1.25.8.2 nathanw * notice, this list of conditions and the following disclaimer.
51 1.25.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
52 1.25.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
53 1.25.8.2 nathanw * documentation and/or other materials provided with the distribution.
54 1.25.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
55 1.25.8.2 nathanw * must display the following acknowledgement:
56 1.25.8.2 nathanw * This product includes software developed by the University of
57 1.25.8.2 nathanw * California, Berkeley and its contributors.
58 1.25.8.2 nathanw * 4. Neither the name of the University nor the names of its contributors
59 1.25.8.2 nathanw * may be used to endorse or promote products derived from this software
60 1.25.8.2 nathanw * without specific prior written permission.
61 1.25.8.2 nathanw *
62 1.25.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.25.8.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.25.8.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.25.8.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.25.8.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.25.8.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.25.8.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.25.8.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.25.8.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.25.8.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.25.8.2 nathanw * SUCH DAMAGE.
73 1.25.8.2 nathanw *
74 1.25.8.2 nathanw * @(#)if_le.c 8.2 (Berkeley) 11/16/93
75 1.25.8.2 nathanw */
76 1.25.8.2 nathanw
77 1.25.8.2 nathanw #include "opt_inet.h"
78 1.25.8.2 nathanw #include "bpfilter.h"
79 1.25.8.2 nathanw
80 1.25.8.2 nathanw #include <sys/param.h>
81 1.25.8.2 nathanw #include <sys/systm.h>
82 1.25.8.2 nathanw #include <sys/mbuf.h>
83 1.25.8.2 nathanw #include <sys/syslog.h>
84 1.25.8.2 nathanw #include <sys/socket.h>
85 1.25.8.2 nathanw #include <sys/device.h>
86 1.25.8.2 nathanw
87 1.25.8.2 nathanw #include <net/if.h>
88 1.25.8.2 nathanw #include <net/if_ether.h>
89 1.25.8.2 nathanw #include <net/if_media.h>
90 1.25.8.2 nathanw
91 1.25.8.2 nathanw #ifdef INET
92 1.25.8.2 nathanw #include <netinet/in.h>
93 1.25.8.2 nathanw #include <netinet/if_inarp.h>
94 1.25.8.2 nathanw #endif
95 1.25.8.2 nathanw
96 1.25.8.2 nathanw #include <machine/autoconf.h>
97 1.25.8.2 nathanw #include <machine/cpu.h>
98 1.25.8.2 nathanw #include <machine/bus.h>
99 1.25.8.2 nathanw
100 1.25.8.2 nathanw #include <mvme68k/dev/pccreg.h>
101 1.25.8.2 nathanw #include <mvme68k/dev/pccvar.h>
102 1.25.8.2 nathanw
103 1.25.8.2 nathanw #include <dev/ic/lancereg.h>
104 1.25.8.2 nathanw #include <dev/ic/lancevar.h>
105 1.25.8.2 nathanw #include <dev/ic/am7990reg.h>
106 1.25.8.2 nathanw #include <dev/ic/am7990var.h>
107 1.25.8.2 nathanw
108 1.25.8.2 nathanw #include <mvme68k/dev/if_lereg.h>
109 1.25.8.2 nathanw #include <mvme68k/dev/if_levar.h>
110 1.25.8.2 nathanw
111 1.25.8.2 nathanw
112 1.25.8.2 nathanw int le_pcc_match __P((struct device *, struct cfdata *, void *));
113 1.25.8.2 nathanw void le_pcc_attach __P((struct device *, struct device *, void *));
114 1.25.8.2 nathanw
115 1.25.8.2 nathanw CFATTACH_DECL(le_pcc, sizeof(struct le_softc),
116 1.25.8.2 nathanw le_pcc_match, le_pcc_attach, NULL, NULL);
117 1.25.8.2 nathanw
118 1.25.8.2 nathanw extern struct cfdriver le_cd;
119 1.25.8.2 nathanw
120 1.25.8.2 nathanw #if defined(_KERNEL_OPT)
121 1.25.8.2 nathanw #include "opt_ddb.h"
122 1.25.8.2 nathanw #endif
123 1.25.8.2 nathanw
124 1.25.8.2 nathanw #ifdef DDB
125 1.25.8.2 nathanw #define hide
126 1.25.8.2 nathanw #else
127 1.25.8.2 nathanw #define hide static
128 1.25.8.2 nathanw #endif
129 1.25.8.2 nathanw
130 1.25.8.2 nathanw hide void le_pcc_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
131 1.25.8.2 nathanw hide u_int16_t le_pcc_rdcsr __P((struct lance_softc *, u_int16_t));
132 1.25.8.2 nathanw
133 1.25.8.2 nathanw hide void
134 1.25.8.2 nathanw le_pcc_wrcsr(sc, port, val)
135 1.25.8.2 nathanw struct lance_softc *sc;
136 1.25.8.2 nathanw u_int16_t port;
137 1.25.8.2 nathanw u_int16_t val;
138 1.25.8.2 nathanw {
139 1.25.8.2 nathanw struct le_softc *lsc;
140 1.25.8.2 nathanw
141 1.25.8.2 nathanw lsc = (struct le_softc *) sc;
142 1.25.8.2 nathanw bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
143 1.25.8.2 nathanw bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP, val);
144 1.25.8.2 nathanw }
145 1.25.8.2 nathanw
146 1.25.8.2 nathanw hide u_int16_t
147 1.25.8.2 nathanw le_pcc_rdcsr(sc, port)
148 1.25.8.2 nathanw struct lance_softc *sc;
149 1.25.8.2 nathanw u_int16_t port;
150 1.25.8.2 nathanw {
151 1.25.8.2 nathanw struct le_softc *lsc;
152 1.25.8.2 nathanw
153 1.25.8.2 nathanw lsc = (struct le_softc *) sc;
154 1.25.8.2 nathanw bus_space_write_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RAP, port);
155 1.25.8.2 nathanw return (bus_space_read_2(lsc->sc_bust, lsc->sc_bush, LEPCC_RDP));
156 1.25.8.2 nathanw }
157 1.25.8.2 nathanw
158 1.25.8.2 nathanw /* ARGSUSED */
159 1.25.8.2 nathanw int
160 1.25.8.2 nathanw le_pcc_match(parent, cf, aux)
161 1.25.8.2 nathanw struct device *parent;
162 1.25.8.2 nathanw struct cfdata *cf;
163 1.25.8.2 nathanw void *aux;
164 1.25.8.2 nathanw {
165 1.25.8.2 nathanw struct pcc_attach_args *pa = aux;
166 1.25.8.2 nathanw
167 1.25.8.2 nathanw if (strcmp(pa->pa_name, le_cd.cd_name))
168 1.25.8.2 nathanw return (0);
169 1.25.8.2 nathanw
170 1.25.8.2 nathanw pa->pa_ipl = cf->pcccf_ipl;
171 1.25.8.2 nathanw return (1);
172 1.25.8.2 nathanw }
173 1.25.8.2 nathanw
174 1.25.8.2 nathanw /* ARGSUSED */
175 1.25.8.2 nathanw void
176 1.25.8.2 nathanw le_pcc_attach(parent, self, aux)
177 1.25.8.2 nathanw struct device *parent;
178 1.25.8.2 nathanw struct device *self;
179 1.25.8.2 nathanw void *aux;
180 1.25.8.2 nathanw {
181 1.25.8.2 nathanw struct le_softc *lsc;
182 1.25.8.2 nathanw struct lance_softc *sc;
183 1.25.8.2 nathanw struct pcc_attach_args *pa;
184 1.25.8.2 nathanw bus_dma_segment_t seg;
185 1.25.8.2 nathanw int rseg;
186 1.25.8.2 nathanw
187 1.25.8.2 nathanw lsc = (struct le_softc *) self;
188 1.25.8.2 nathanw sc = &lsc->sc_am7990.lsc;
189 1.25.8.2 nathanw pa = aux;
190 1.25.8.2 nathanw
191 1.25.8.2 nathanw /* Map control registers. */
192 1.25.8.2 nathanw lsc->sc_bust = pa->pa_bust;
193 1.25.8.2 nathanw bus_space_map(pa->pa_bust, pa->pa_offset, 4, 0, &lsc->sc_bush);
194 1.25.8.2 nathanw
195 1.25.8.2 nathanw /* Get contiguous DMA-able memory for the lance */
196 1.25.8.2 nathanw if (bus_dmamem_alloc(pa->pa_dmat, ether_data_buff_size, NBPG, 0,
197 1.25.8.2 nathanw &seg, 1, &rseg,
198 1.25.8.2 nathanw BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT)) {
199 1.25.8.2 nathanw printf("%s: Failed to allocate ether buffer\n", self->dv_xname);
200 1.25.8.2 nathanw return;
201 1.25.8.2 nathanw }
202 1.25.8.2 nathanw if (bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
203 1.25.8.2 nathanw (caddr_t *) & sc->sc_mem, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
204 1.25.8.2 nathanw printf("%s: Failed to map ether buffer\n", self->dv_xname);
205 1.25.8.2 nathanw bus_dmamem_free(pa->pa_dmat, &seg, rseg);
206 1.25.8.2 nathanw return;
207 1.25.8.2 nathanw }
208 1.25.8.2 nathanw sc->sc_addr = seg.ds_addr;
209 1.25.8.2 nathanw sc->sc_memsize = ether_data_buff_size;
210 1.25.8.2 nathanw sc->sc_conf3 = LE_C3_BSWP;
211 1.25.8.2 nathanw
212 1.25.8.2 nathanw memcpy(sc->sc_enaddr, mvme_ea, ETHER_ADDR_LEN);
213 1.25.8.2 nathanw
214 1.25.8.2 nathanw sc->sc_copytodesc = lance_copytobuf_contig;
215 1.25.8.2 nathanw sc->sc_copyfromdesc = lance_copyfrombuf_contig;
216 1.25.8.2 nathanw sc->sc_copytobuf = lance_copytobuf_contig;
217 1.25.8.2 nathanw sc->sc_copyfrombuf = lance_copyfrombuf_contig;
218 1.25.8.2 nathanw sc->sc_zerobuf = lance_zerobuf_contig;
219 1.25.8.2 nathanw
220 1.25.8.2 nathanw sc->sc_rdcsr = le_pcc_rdcsr;
221 1.25.8.2 nathanw sc->sc_wrcsr = le_pcc_wrcsr;
222 1.25.8.2 nathanw sc->sc_hwinit = NULL;
223 1.25.8.2 nathanw
224 1.25.8.2 nathanw am7990_config(&lsc->sc_am7990);
225 1.25.8.2 nathanw
226 1.25.8.2 nathanw evcnt_attach_dynamic(&lsc->sc_evcnt, EVCNT_TYPE_INTR,
227 1.25.8.2 nathanw pccintr_evcnt(pa->pa_ipl), "ether", sc->sc_dev.dv_xname);
228 1.25.8.2 nathanw
229 1.25.8.2 nathanw pccintr_establish(PCCV_LE, am7990_intr, pa->pa_ipl, sc, &lsc->sc_evcnt);
230 1.25.8.2 nathanw
231 1.25.8.2 nathanw pcc_reg_write(sys_pcc, PCCREG_LANCE_INTR_CTRL,
232 1.25.8.2 nathanw pa->pa_ipl | PCC_IENABLE);
233 1.25.8.2 nathanw }
234