1 /* $NetBSD: if_le.c,v 1.34 2009/03/18 17:06:47 cegger Exp $ */
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * Ralph Campbell and Rick Macklem.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.34 2009/03/18 17:06:47 cegger Exp $");
73 #include <sys/param.h>
74 #include <sys/syslog.h>
75 #include <sys/socket.h>
76 #include <sys/device.h>
77 #include <sys/reboot.h>
79 #include <uvm/uvm_extern.h>
82 #include <net/if_ether.h>
83 #include <net/if_media.h>
86 #include <netinet/in.h>
87 #include <netinet/if_inarp.h>
90 #include <machine/cpu.h>
91 #include <machine/nexus.h>
92 #include <machine/scb.h>
93 #include <machine/mainbus.h>
95 #include <dev/ic/lancereg.h>
96 #include <dev/ic/lancevar.h>
97 #include <dev/ic/am7990reg.h>
98 #include <dev/ic/am7990var.h>
102 #define LE_VEC 0xd4 /* Interrupt vector on 3300/3400 */
104 #define LE_CSR 0x20084400
105 #define LE_ROM 0x20084200
106 #define LE_RAM 0x20120000
109 struct am7990_softc sc_am7990
; /* Must be first */
110 struct evcnt sc_intrcnt
;
111 volatile uint16_t *sc_rap
;
112 volatile uint16_t *sc_rdp
;
115 static int le_mainbus_match(device_t
, cfdata_t
, void *);
116 static void le_mainbus_attach(device_t
, device_t
, void *);
117 static void lewrcsr(struct lance_softc
*, uint16_t, uint16_t);
118 static uint16_t lerdcsr(struct lance_softc
*, uint16_t);
119 static void lance_copytobuf_gap2(struct lance_softc
*, void *, int, int);
120 static void lance_copyfrombuf_gap2(struct lance_softc
*, void *, int, int);
121 static void lance_zerobuf_gap2(struct lance_softc
*, int, int);
123 CFATTACH_DECL_NEW(le_mainbus
, sizeof(struct le_softc
),
124 le_mainbus_match
, le_mainbus_attach
, NULL
, NULL
);
127 lewrcsr(struct lance_softc
*ls
, uint16_t port
, uint16_t val
)
129 struct le_softc
* const sc
= (void *)ls
;
136 lerdcsr(struct lance_softc
*ls
, uint16_t port
)
138 struct le_softc
* const sc
= (void *)ls
;
145 le_mainbus_match(device_t parent
, cfdata_t cf
, void *aux
)
147 struct mainbus_attach_args
* const ma
= aux
;
151 if (strcmp("lance", ma
->ma_type
))
154 va
= vax_map_physmem(LE_CSR
, 1);
155 found
= (badaddr((void *)va
, 2) == 0);
156 vax_unmap_physmem(va
, 1);
162 le_mainbus_attach(device_t parent
, device_t self
, void *aux
)
164 struct le_softc
* const sc
= device_private(self
);
168 sc
->sc_am7990
.lsc
.sc_dev
= self
;
169 sc
->sc_rdp
= (uint16_t *)vax_map_physmem(LE_CSR
, 1);
170 sc
->sc_rap
= sc
->sc_rdp
+ 2;
173 * Set interrupt vector, by forcing an interrupt.
175 scb_vecref(0, 0); /* Clear vector ref */
176 *sc
->sc_rap
= LE_CSR0
;
177 *sc
->sc_rdp
= LE_C0_STOP
;
179 *sc
->sc_rdp
= LE_C0_INIT
|LE_C0_INEA
;
181 i
= scb_vecref(&vec
, &br
);
182 if (i
== 0 || vec
== 0)
185 scb_vecalloc(vec
, (void (*)(void *))am7990_intr
, sc
,
186 SCB_ISTACK
, &sc
->sc_intrcnt
);
187 evcnt_attach_dynamic(&sc
->sc_intrcnt
, EVCNT_TYPE_INTR
, NULL
,
188 device_xname(self
), "intr");
190 aprint_normal(": vec %o ipl %x\n%s", vec
, br
, device_xname(self
));
194 sc
->sc_am7990
.lsc
.sc_rdcsr
= lerdcsr
;
195 sc
->sc_am7990
.lsc
.sc_wrcsr
= lewrcsr
;
196 sc
->sc_am7990
.lsc
.sc_nocarrier
= NULL
;
198 sc
->sc_am7990
.lsc
.sc_mem
=
199 (void *)uvm_km_alloc(kernel_map
, (128 * 1024), 0, UVM_KMF_VAONLY
);
200 if (sc
->sc_am7990
.lsc
.sc_mem
== 0)
203 ioaccess((vaddr_t
)sc
->sc_am7990
.lsc
.sc_mem
, LE_RAM
,
204 (128 * 1024) >> VAX_PGSHIFT
);
207 sc
->sc_am7990
.lsc
.sc_addr
= 0;
208 sc
->sc_am7990
.lsc
.sc_memsize
= (64 * 1024);
210 sc
->sc_am7990
.lsc
.sc_copytodesc
= lance_copytobuf_gap2
;
211 sc
->sc_am7990
.lsc
.sc_copyfromdesc
= lance_copyfrombuf_gap2
;
212 sc
->sc_am7990
.lsc
.sc_copytobuf
= lance_copytobuf_gap2
;
213 sc
->sc_am7990
.lsc
.sc_copyfrombuf
= lance_copyfrombuf_gap2
;
214 sc
->sc_am7990
.lsc
.sc_zerobuf
= lance_zerobuf_gap2
;
217 * Get the ethernet address out of rom
219 lance_addr
= (int *)vax_map_physmem(LE_ROM
, 1);
220 for (i
= 0; i
< 6; i
++)
221 sc
->sc_am7990
.lsc
.sc_enaddr
[i
] = (u_char
)lance_addr
[i
];
222 vax_unmap_physmem((vaddr_t
)lance_addr
, 1);
224 memcpy(sc
->sc_am7990
.lsc
.sc_ethercom
.ec_if
.if_xname
, device_xname(self
),
226 am7990_config(&sc
->sc_am7990
);
230 * gap2: two bytes of data followed by two bytes of pad.
232 * Buffers must be 4-byte aligned. The code doesn't worry about
233 * doing an extra byte.
237 lance_copytobuf_gap2(struct lance_softc
*sc
, void *fromv
, int boff
, int len
)
239 volatile void *buf
= sc
->sc_mem
;
241 volatile uint16_t *bptr
;
244 /* handle unaligned first byte */
245 bptr
= ((volatile uint16_t *)buf
) + (boff
- 1);
246 *bptr
= (*from
++ << 8) | (*bptr
& 0xff);
250 bptr
= ((volatile uint16_t *)buf
) + boff
;
252 *bptr
= (from
[1] << 8) | (from
[0] & 0xff);
258 *bptr
= (uint16_t)*from
;
262 lance_copyfrombuf_gap2(struct lance_softc
*sc
, void *tov
, int boff
, int len
)
264 volatile void *buf
= sc
->sc_mem
;
266 volatile uint16_t *bptr
;
270 /* handle unaligned first byte */
271 bptr
= ((volatile uint16_t *)buf
) + (boff
- 1);
272 *to
++ = (*bptr
>> 8) & 0xff;
276 bptr
= ((volatile uint16_t *)buf
) + boff
;
280 *to
++ = (tmp
>> 8) & 0xff;
289 lance_zerobuf_gap2(struct lance_softc
*sc
, int boff
, int len
)
291 volatile void *buf
= sc
->sc_mem
;
292 volatile uint16_t *bptr
;
294 if ((unsigned int)boff
& 0x1) {
295 bptr
= ((volatile uint16_t *)buf
) + (boff
- 1);
300 bptr
= ((volatile uint16_t *)buf
) + boff
;