if_le.c revision 1.50 1 /* $NetBSD: if_le.c,v 1.50 2008/04/04 12:25:06 tsutsui Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.50 2008/04/04 12:25:06 tsutsui Exp $");
41
42 #include "opt_inet.h"
43 #include "bpfilter.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/mbuf.h>
48 #include <sys/syslog.h>
49 #include <sys/socket.h>
50 #include <sys/device.h>
51
52 #include <net/if.h>
53 #include <net/if_ether.h>
54 #include <net/if_media.h>
55
56 #ifdef INET
57 #include <netinet/in.h>
58 #include <netinet/if_inarp.h>
59 #endif
60
61 #include <machine/autoconf.h>
62 #include <machine/cpu.h>
63 #include <machine/dvma.h>
64 #include <machine/idprom.h>
65
66 #include <dev/ic/lancereg.h>
67 #include <dev/ic/lancevar.h>
68 #include <dev/ic/am7990reg.h>
69 #include <dev/ic/am7990var.h>
70
71 #define LE_MEMSIZE 0x4000 /* 16K */
72
73 /*
74 * LANCE registers.
75 * The real stuff is in dev/ic/am7990reg.h
76 */
77 struct lereg1 {
78 volatile uint16_t ler1_rdp; /* data port */
79 volatile uint16_t ler1_rap; /* register select port */
80 };
81
82 /*
83 * Ethernet software status per interface.
84 * The real stuff is in dev/ic/am7990var.h
85 */
86 struct le_softc {
87 struct am7990_softc sc_am7990; /* glue to MI code */
88
89 struct lereg1 *sc_r1; /* LANCE registers */
90 };
91
92 static int le_match(device_t, cfdata_t, void *);
93 static void le_attach(device_t, device_t, void *);
94
95 CFATTACH_DECL_NEW(le, sizeof(struct le_softc),
96 le_match, le_attach, NULL, NULL);
97
98 #if defined(_KERNEL_OPT)
99 #include "opt_ddb.h"
100 #endif
101
102 #ifdef DDB
103 #define integrate
104 #define hide
105 #else
106 #define integrate static inline
107 #define hide static
108 #endif
109
110 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
111 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
112
113 hide void
114 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
115 {
116 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
117
118 ler1->ler1_rap = port;
119 ler1->ler1_rdp = val;
120 }
121
122 hide uint16_t
123 lerdcsr(struct lance_softc *sc, uint16_t port)
124 {
125 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
126 uint16_t val;
127
128 ler1->ler1_rap = port;
129 val = ler1->ler1_rdp;
130 return (val);
131 }
132
133 int
134 le_match(device_t parent, cfdata_t cf, void *aux)
135 {
136 struct confargs *ca = aux;
137
138 /* Make sure there is something there... */
139 if (bus_peek(ca->ca_bustype, ca->ca_paddr, 2) == -1)
140 return (0);
141
142 /* Default interrupt priority. */
143 if (ca->ca_intpri == -1)
144 ca->ca_intpri = 3;
145
146 return (1);
147 }
148
149 void
150 le_attach(device_t parent, device_t self, void *aux)
151 {
152 struct le_softc *lesc = device_private(self);
153 struct lance_softc *sc = &lesc->sc_am7990.lsc;
154 struct confargs *ca = aux;
155
156 sc->sc_dev = self;
157 lesc->sc_r1 = bus_mapin(ca->ca_bustype,
158 ca->ca_paddr, sizeof(struct lereg1));
159
160 sc->sc_memsize = LE_MEMSIZE;
161 sc->sc_mem = dvma_malloc(sc->sc_memsize);
162 sc->sc_addr = dvma_kvtopa(sc->sc_mem, ca->ca_bustype);
163 #ifdef _SUN3X_
164 sc->sc_conf3 = LE_C3_BSWP | LE_C3_ACON | LE_C3_BCON;
165 #else
166 sc->sc_conf3 = LE_C3_BSWP;
167 #endif
168
169 idprom_etheraddr(sc->sc_enaddr);
170
171 sc->sc_copytodesc = lance_copytobuf_contig;
172 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
173 sc->sc_copytobuf = lance_copytobuf_contig;
174 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
175 sc->sc_zerobuf = lance_zerobuf_contig;
176
177 sc->sc_rdcsr = lerdcsr;
178 sc->sc_wrcsr = lewrcsr;
179 sc->sc_hwinit = NULL;
180
181 am7990_config(&lesc->sc_am7990);
182
183 /* Install interrupt handler. */
184 isr_add_autovect(am7990_intr, (void *)sc, ca->ca_intpri);
185 }
186