if_le.c revision 1.2 1 /* $NetBSD: if_le.c,v 1.2 2000/02/08 16:17:31 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 /*
40 * news68k/dev/if_le.c - based on newsmips/dev/if_le.c
41 */
42
43 #include "opt_inet.h"
44 #include "bpfilter.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/mbuf.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/cpu.h>
62
63 #include <news68k/dev/hbvar.h>
64
65 #include <dev/ic/lancereg.h>
66 #include <dev/ic/lancevar.h>
67 #include <dev/ic/am7990reg.h>
68 #include <dev/ic/am7990var.h>
69
70 /*
71 * LANCE registers.
72 * The real stuff is in dev/ic/am7990reg.h
73 */
74 struct lereg1 {
75 volatile u_int16_t ler1_rdp; /* data port */
76 volatile u_int16_t ler1_rap; /* register select port */
77 };
78
79 /*
80 * Ethernet software status per interface.
81 * The real stuff is in dev/ic/am7990var.h
82 */
83 struct le_softc {
84 struct am7990_softc sc_am7990; /* glue to MI code */
85
86 struct lereg1 *sc_r1; /* LANCE registers */
87 };
88
89 static int le_match __P((struct device *, struct cfdata *, void *));
90 static void le_attach __P((struct device *, struct device *, void *));
91
92 struct cfattach le_ca = {
93 sizeof(struct le_softc), le_match, le_attach
94 };
95
96 extern volatile u_char *lance_mem, *idrom_addr;
97
98 #if defined(_KERNEL) && !defined(_LKM)
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 __P((struct lance_softc *, u_int16_t, u_int16_t));
111 hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
112 int leintr __P((int));
113
114 hide void
115 lewrcsr(sc, port, val)
116 struct lance_softc *sc;
117 u_int16_t port, val;
118 {
119 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
120
121 ler1->ler1_rap = port;
122 ler1->ler1_rdp = val;
123 }
124
125 hide u_int16_t
126 lerdcsr(sc, port)
127 struct lance_softc *sc;
128 u_int16_t port;
129 {
130 struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
131 u_int16_t val;
132
133 ler1->ler1_rap = port;
134 val = ler1->ler1_rdp;
135 return (val);
136 }
137
138 int
139 le_match(parent, cf, aux)
140 struct device *parent;
141 struct cfdata *cf;
142 void *aux;
143 {
144 struct hb_attach_args *ha = aux;
145 int addr;
146
147 if (strcmp(ha->ha_name, "le"))
148 return 0;
149
150 addr = IIOV(ha->ha_address);
151
152 if (badaddr((void *)addr, 1))
153 return 0;
154
155 return 1;
156 }
157
158 void
159 le_attach(parent, self, aux)
160 struct device *parent, *self;
161 void *aux;
162 {
163 struct le_softc *lesc = (struct le_softc *)self;
164 struct lance_softc *sc = &lesc->sc_am7990.lsc;
165 struct hb_attach_args *ha = aux;
166 u_char *p;
167
168 lesc->sc_r1 = (void *)IIOV(ha->ha_address);
169
170 if (ISIIOPA(ha->ha_address)) {
171 sc->sc_mem = (u_char *)lance_mem;
172 p = (u_char *)(idrom_addr + 0x10);
173 } else {
174 sc->sc_mem = lesc->sc_r1 - 0x10000;
175 p = (u_char *)(lesc->sc_r1 + 0x8010);
176 }
177
178 sc->sc_memsize = 0x4000; /* 16K */
179 sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
180 sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
181
182 sc->sc_enaddr[0] = (*p++ << 4);
183 sc->sc_enaddr[0] |= *p++ & 0x0f;
184 sc->sc_enaddr[1] = (*p++ << 4);
185 sc->sc_enaddr[1] |= *p++ & 0x0f;
186 sc->sc_enaddr[2] = (*p++ << 4);
187 sc->sc_enaddr[2] |= *p++ & 0x0f;
188 sc->sc_enaddr[3] = (*p++ << 4);
189 sc->sc_enaddr[3] |= *p++ & 0x0f;
190 sc->sc_enaddr[4] = (*p++ << 4);
191 sc->sc_enaddr[4] |= *p++ & 0x0f;
192 sc->sc_enaddr[5] = (*p++ << 4);
193 sc->sc_enaddr[5] |= *p++ & 0x0f;
194
195 sc->sc_copytodesc = lance_copytobuf_contig;
196 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
197 sc->sc_copytobuf = lance_copytobuf_contig;
198 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
199 sc->sc_zerobuf = lance_zerobuf_contig;
200
201 sc->sc_rdcsr = lerdcsr;
202 sc->sc_wrcsr = lewrcsr;
203 sc->sc_hwinit = NULL;
204
205 am7990_config(&lesc->sc_am7990);
206 }
207
208 int
209 leintr(unit)
210 int unit;
211 {
212 struct am7990_softc *sc;
213 extern struct cfdriver le_cd;
214
215 if (unit >= le_cd.cd_ndevs)
216 return 0;
217
218 sc = le_cd.cd_devs[unit];
219 return am7990_intr(sc);
220 }
221