if_le.c revision 1.8 1 /* $NetBSD: if_le.c,v 1.8 2003/07/15 02:59:26 lukem 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 /*
40 * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.8 2003/07/15 02:59:26 lukem Exp $");
45
46 #include "opt_inet.h"
47 #include "bpfilter.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <sys/device.h>
54
55 #include <net/if.h>
56 #include <net/if_ether.h>
57 #include <net/if_media.h>
58
59 #ifdef INET
60 #include <netinet/in.h>
61 #include <netinet/if_inarp.h>
62 #endif
63
64 #include <machine/cpu.h>
65
66 #include <news68k/dev/hbvar.h>
67
68 #include <dev/ic/lancereg.h>
69 #include <dev/ic/lancevar.h>
70 #include <dev/ic/am7990reg.h>
71 #include <dev/ic/am7990var.h>
72
73 /*
74 * LANCE registers.
75 * The real stuff is in dev/ic/am7990reg.h
76 */
77 struct lereg1 {
78 volatile u_int16_t ler1_rdp; /* data port */
79 volatile u_int16_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(struct device *, struct cfdata *, void *);
93 static void le_attach(struct device *, struct device *, void *);
94
95 CFATTACH_DECL(le, sizeof(struct le_softc),
96 le_match, le_attach, NULL, NULL);
97
98 extern volatile u_char *lance_mem, *idrom_addr;
99
100 #if defined(_KERNEL_OPT)
101 #include "opt_ddb.h"
102 #endif
103
104 #ifdef DDB
105 #define integrate
106 #define hide
107 #else
108 #define integrate static __inline
109 #define hide static
110 #endif
111
112 hide void lewrcsr(struct lance_softc *, u_int16_t, u_int16_t);
113 hide u_int16_t lerdcsr(struct lance_softc *, u_int16_t);
114 int leintr(int);
115
116 hide void
117 lewrcsr(sc, port, val)
118 struct lance_softc *sc;
119 u_int16_t port, val;
120 {
121 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
122
123 ler1->ler1_rap = port;
124 ler1->ler1_rdp = val;
125 }
126
127 hide u_int16_t
128 lerdcsr(sc, port)
129 struct lance_softc *sc;
130 u_int16_t port;
131 {
132 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
133 u_int16_t val;
134
135 ler1->ler1_rap = port;
136 val = ler1->ler1_rdp;
137 return (val);
138 }
139
140 int
141 le_match(parent, cf, aux)
142 struct device *parent;
143 struct cfdata *cf;
144 void *aux;
145 {
146 struct hb_attach_args *ha = aux;
147 int addr;
148
149 if (strcmp(ha->ha_name, "le"))
150 return 0;
151
152 addr = IIOV(ha->ha_address);
153
154 if (badaddr((void *)addr, 1))
155 return 0;
156
157 return 1;
158 }
159
160 void
161 le_attach(parent, self, aux)
162 struct device *parent, *self;
163 void *aux;
164 {
165 struct le_softc *lesc = (struct le_softc *)self;
166 struct lance_softc *sc = &lesc->sc_am7990.lsc;
167 struct hb_attach_args *ha = aux;
168 u_char *p;
169
170 lesc->sc_r1 = (void *)IIOV(ha->ha_address);
171
172 if (ISIIOPA(ha->ha_address)) {
173 sc->sc_mem = (u_char *)lance_mem;
174 p = (u_char *)(idrom_addr + 0x10);
175 } else {
176 sc->sc_mem = lesc->sc_r1 - 0x10000;
177 p = (u_char *)(lesc->sc_r1 + 0x8010);
178 }
179
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;
183
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;
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 = lerdcsr;
204 sc->sc_wrcsr = lewrcsr;
205 sc->sc_hwinit = NULL;
206
207 am7990_config(&lesc->sc_am7990);
208 }
209
210 int
211 leintr(unit)
212 int unit;
213 {
214 struct am7990_softc *sc;
215 extern struct cfdriver le_cd;
216
217 if (unit >= le_cd.cd_ndevs)
218 return 0;
219
220 sc = le_cd.cd_devs[unit];
221 return am7990_intr(sc);
222 }
223