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