1 /* $NetBSD: if_le.c,v 1.50 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.50 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/autoconf.h>
55 #include <machine/cpu.h>
56 #include <machine/dvma.h>
57 #include <machine/idprom.h>
59 #include <dev/ic/lancereg.h>
60 #include <dev/ic/lancevar.h>
61 #include <dev/ic/am7990reg.h>
62 #include <dev/ic/am7990var.h>
64 #define LE_MEMSIZE 0x4000 /* 16K */
68 * The real stuff is in dev/ic/am7990reg.h
71 volatile uint16_t ler1_rdp
; /* data port */
72 volatile uint16_t ler1_rap
; /* register select port */
76 * Ethernet software status per interface.
77 * The real stuff is in dev/ic/am7990var.h
80 struct am7990_softc sc_am7990
; /* glue to MI code */
82 struct lereg1
*sc_r1
; /* LANCE registers */
85 static int le_match(device_t
, cfdata_t
, void *);
86 static void le_attach(device_t
, device_t
, void *);
88 CFATTACH_DECL_NEW(le
, sizeof(struct le_softc
),
89 le_match
, le_attach
, NULL
, NULL
);
91 #if defined(_KERNEL_OPT)
99 #define integrate static inline
103 hide
void lewrcsr(struct lance_softc
*, uint16_t, uint16_t);
104 hide
uint16_t lerdcsr(struct lance_softc
*, uint16_t);
107 lewrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
109 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
111 ler1
->ler1_rap
= port
;
112 ler1
->ler1_rdp
= val
;
116 lerdcsr(struct lance_softc
*sc
, uint16_t port
)
118 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
121 ler1
->ler1_rap
= port
;
122 val
= ler1
->ler1_rdp
;
127 le_match(device_t parent
, cfdata_t cf
, void *aux
)
129 struct confargs
*ca
= aux
;
131 /* Make sure there is something there... */
132 if (bus_peek(ca
->ca_bustype
, ca
->ca_paddr
, 2) == -1)
135 /* Default interrupt priority. */
136 if (ca
->ca_intpri
== -1)
143 le_attach(device_t parent
, device_t self
, void *aux
)
145 struct le_softc
*lesc
= device_private(self
);
146 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
147 struct confargs
*ca
= aux
;
150 lesc
->sc_r1
= bus_mapin(ca
->ca_bustype
,
151 ca
->ca_paddr
, sizeof(struct lereg1
));
153 sc
->sc_memsize
= LE_MEMSIZE
;
154 sc
->sc_mem
= dvma_malloc(sc
->sc_memsize
);
155 sc
->sc_addr
= dvma_kvtopa(sc
->sc_mem
, ca
->ca_bustype
);
157 sc
->sc_conf3
= LE_C3_BSWP
| LE_C3_ACON
| LE_C3_BCON
;
159 sc
->sc_conf3
= LE_C3_BSWP
;
162 idprom_etheraddr(sc
->sc_enaddr
);
164 sc
->sc_copytodesc
= lance_copytobuf_contig
;
165 sc
->sc_copyfromdesc
= lance_copyfrombuf_contig
;
166 sc
->sc_copytobuf
= lance_copytobuf_contig
;
167 sc
->sc_copyfrombuf
= lance_copyfrombuf_contig
;
168 sc
->sc_zerobuf
= lance_zerobuf_contig
;
170 sc
->sc_rdcsr
= lerdcsr
;
171 sc
->sc_wrcsr
= lewrcsr
;
172 sc
->sc_hwinit
= NULL
;
174 am7990_config(&lesc
->sc_am7990
);
176 /* Install interrupt handler. */
177 isr_add_autovect(am7990_intr
, (void *)sc
, ca
->ca_intpri
);