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