xref: /netbsd/sys/arch/news68k/dev/if_le.c (revision c4a72b64)
1 /*	$NetBSD: if_le.c,v 1.5 2002/10/02 04:40:08 thorpej 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 CFATTACH_DECL(le, sizeof(struct le_softc),
93     le_match, le_attach, NULL, NULL);
94 
95 extern volatile u_char *lance_mem, *idrom_addr;
96 
97 #if defined(_KERNEL_OPT)
98 #include "opt_ddb.h"
99 #endif
100 
101 #ifdef DDB
102 #define	integrate
103 #define hide
104 #else
105 #define	integrate	static __inline
106 #define hide		static
107 #endif
108 
109 hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
110 hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
111 int leintr __P((int));
112 
113 hide void
114 lewrcsr(sc, port, val)
115 	struct lance_softc *sc;
116 	u_int16_t port, val;
117 {
118 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
119 
120 	ler1->ler1_rap = port;
121 	ler1->ler1_rdp = val;
122 }
123 
124 hide u_int16_t
125 lerdcsr(sc, port)
126 	struct lance_softc *sc;
127 	u_int16_t port;
128 {
129 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
130 	u_int16_t val;
131 
132 	ler1->ler1_rap = port;
133 	val = ler1->ler1_rdp;
134 	return (val);
135 }
136 
137 int
138 le_match(parent, cf, aux)
139 	struct device *parent;
140 	struct cfdata *cf;
141 	void *aux;
142 {
143 	struct hb_attach_args *ha = aux;
144 	int addr;
145 
146 	if (strcmp(ha->ha_name, "le"))
147 		return 0;
148 
149 	addr = IIOV(ha->ha_address);
150 
151 	if (badaddr((void *)addr, 1))
152 		return 0;
153 
154 	return 1;
155 }
156 
157 void
158 le_attach(parent, self, aux)
159 	struct device *parent, *self;
160 	void *aux;
161 {
162 	struct le_softc *lesc = (struct le_softc *)self;
163 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
164 	struct hb_attach_args *ha = aux;
165 	u_char *p;
166 
167 	lesc->sc_r1 = (void *)IIOV(ha->ha_address);
168 
169 	if (ISIIOPA(ha->ha_address)) {
170 		sc->sc_mem = (u_char *)lance_mem;
171 		p = (u_char *)(idrom_addr + 0x10);
172 	} else {
173 		sc->sc_mem = lesc->sc_r1 - 0x10000;
174 		p = (u_char *)(lesc->sc_r1 + 0x8010);
175 	}
176 
177 	sc->sc_memsize = 0x4000;	/* 16K */
178 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
179 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
180 
181 	sc->sc_enaddr[0] = (*p++ << 4);
182 	sc->sc_enaddr[0] |= *p++ & 0x0f;
183 	sc->sc_enaddr[1] = (*p++ << 4);
184 	sc->sc_enaddr[1] |= *p++ & 0x0f;
185 	sc->sc_enaddr[2] = (*p++ << 4);
186 	sc->sc_enaddr[2] |= *p++ & 0x0f;
187 	sc->sc_enaddr[3] = (*p++ << 4);
188 	sc->sc_enaddr[3] |= *p++ & 0x0f;
189 	sc->sc_enaddr[4] = (*p++ << 4);
190 	sc->sc_enaddr[4] |= *p++ & 0x0f;
191 	sc->sc_enaddr[5] = (*p++ << 4);
192 	sc->sc_enaddr[5] |= *p++ & 0x0f;
193 
194 	sc->sc_copytodesc = lance_copytobuf_contig;
195 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
196 	sc->sc_copytobuf = lance_copytobuf_contig;
197 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
198 	sc->sc_zerobuf = lance_zerobuf_contig;
199 
200 	sc->sc_rdcsr = lerdcsr;
201 	sc->sc_wrcsr = lewrcsr;
202 	sc->sc_hwinit = NULL;
203 
204 	am7990_config(&lesc->sc_am7990);
205 }
206 
207 int
208 leintr(unit)
209 	int unit;
210 {
211 	struct am7990_softc *sc;
212 	extern struct cfdriver le_cd;
213 
214 	if (unit >= le_cd.cd_ndevs)
215 		return 0;
216 
217 	sc = le_cd.cd_devs[unit];
218 	return am7990_intr(sc);
219 }
220