1 /* $NetBSD: if_le.c,v 1.16 2008/04/04 12:25:06 tsutsui Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.16 2008/04/04 12:25:06 tsutsui Exp $");
38 #include <sys/param.h>
39 #include <sys/systm.h>
41 #include <sys/syslog.h>
42 #include <sys/socket.h>
43 #include <sys/device.h>
46 #include <net/if_ether.h>
47 #include <net/if_media.h>
50 #include <netinet/in.h>
51 #include <netinet/if_inarp.h>
54 #include <machine/cpu.h>
55 #include <machine/adrsmap.h>
57 #include <dev/ic/lancereg.h>
58 #include <dev/ic/lancevar.h>
59 #include <dev/ic/am7990reg.h>
60 #include <dev/ic/am7990var.h>
62 #include <newsmips/dev/hbvar.h>
66 * The real stuff is in dev/ic/am7990reg.h
69 volatile uint16_t ler1_rdp
; /* data port */
70 volatile uint16_t ler1_rap
; /* register select port */
74 * Ethernet software status per interface.
75 * The real stuff is in dev/ic/am7990var.h
78 struct am7990_softc sc_am7990
; /* glue to MI code */
80 struct lereg1
*sc_r1
; /* LANCE registers */
83 static int le_match(device_t
, cfdata_t
, void *);
84 static void le_attach(device_t
, device_t
, void *);
86 CFATTACH_DECL_NEW(le
, sizeof(struct le_softc
),
87 le_match
, le_attach
, NULL
, NULL
);
89 #if defined(_KERNEL_OPT)
97 #define integrate static inline
101 hide
void lewrcsr(struct lance_softc
*, uint16_t, uint16_t);
102 hide
uint16_t lerdcsr(struct lance_softc
*, uint16_t);
105 lewrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
107 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
109 ler1
->ler1_rap
= port
;
110 ler1
->ler1_rdp
= val
;
114 lerdcsr(struct lance_softc
*sc
, uint16_t port
)
116 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
119 ler1
->ler1_rap
= port
;
120 val
= ler1
->ler1_rdp
;
125 le_match(device_t parent
, cfdata_t cf
, void *aux
)
127 struct hb_attach_args
*ha
= aux
;
129 if (strcmp(ha
->ha_name
, "le"))
132 if (hb_badaddr((void *)ha
->ha_addr
, 1)) /* XXX */
139 le_attach(device_t parent
, device_t self
, void *aux
)
141 struct le_softc
*lesc
= device_private(self
);
142 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
143 struct hb_attach_args
*ha
= aux
;
144 int intlevel
, intmask
;
148 intlevel
= ha
->ha_level
;
149 if (intlevel
== -1) {
150 aprint_error(": interrupt level not configured\n");
153 aprint_normal(" level %d", intlevel
);
155 switch (ha
->ha_addr
) {
158 sc
->sc_mem
= (void *)LANCE_MEMORY
;
159 p
= (uint8_t *)(ETHER_ID
+ 16);
160 intmask
= INTST1_LANCE
;
163 sc
->sc_mem
= (void *)LANCE_MEMORY1
;
164 p
= (uint8_t *)(ETHER_ID1
+ 16);
165 intmask
= INTST1_SLOT3
; /* XXX not tested */
168 sc
->sc_mem
= (void *)LANCE_MEMORY2
;
169 p
= (uint8_t *)(ETHER_ID2
+ 16);
170 intmask
= INTST1_SLOT3
; /* XXX not tested */
174 aprint_error(": unknown LANCE addr\n");
178 lesc
->sc_r1
= (void *)ha
->ha_addr
;
180 sc
->sc_memsize
= 0x4000; /* 16K */
181 sc
->sc_addr
= (int)sc
->sc_mem
& 0x00ffffff;
182 sc
->sc_conf3
= LE_C3_BSWP
|LE_C3_BCON
;
184 sc
->sc_enaddr
[0] = (*p
++ << 4);
185 sc
->sc_enaddr
[0] |= *p
++ & 0x0f;
186 sc
->sc_enaddr
[1] = (*p
++ << 4);
187 sc
->sc_enaddr
[1] |= *p
++ & 0x0f;
188 sc
->sc_enaddr
[2] = (*p
++ << 4);
189 sc
->sc_enaddr
[2] |= *p
++ & 0x0f;
190 sc
->sc_enaddr
[3] = (*p
++ << 4);
191 sc
->sc_enaddr
[3] |= *p
++ & 0x0f;
192 sc
->sc_enaddr
[4] = (*p
++ << 4);
193 sc
->sc_enaddr
[4] |= *p
++ & 0x0f;
194 sc
->sc_enaddr
[5] = (*p
++ << 4);
195 sc
->sc_enaddr
[5] |= *p
++ & 0x0f;
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
;
203 sc
->sc_rdcsr
= lerdcsr
;
204 sc
->sc_wrcsr
= lewrcsr
;
205 sc
->sc_hwinit
= NULL
;
207 am7990_config(&lesc
->sc_am7990
);
208 hb_intr_establish(intlevel
, intmask
, IPL_NET
, am7990_intr
, sc
);