xref: /netbsd-src/sys/arch/news68k/dev/if_le.c (revision fd5cb0acea84d278e04e640d37ca2398f894991f)
1 /*	$NetBSD: if_le.c,v 1.11 2004/12/11 03:32:27 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 <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.11 2004/12/11 03:32:27 tsutsui 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 #include "ioconf.h"
74 
75 /*
76  * LANCE registers.
77  * The real stuff is in dev/ic/am7990reg.h
78  */
79 struct lereg1 {
80 	volatile uint16_t	ler1_rdp;	/* data port */
81 	volatile uint16_t	ler1_rap;	/* register select port */
82 };
83 
84 /*
85  * Ethernet software status per interface.
86  * The real stuff is in dev/ic/am7990var.h
87  */
88 struct	le_softc {
89 	struct	am7990_softc sc_am7990;	/* glue to MI code */
90 
91 	struct	lereg1 *sc_r1;		/* LANCE registers */
92 };
93 
94 static int  le_match(struct device *, struct cfdata *, void *);
95 static void le_attach(struct device *, struct device *, void *);
96 
97 CFATTACH_DECL(le, sizeof(struct le_softc),
98     le_match, le_attach, NULL, NULL);
99 
100 extern volatile u_char *lance_mem, *idrom_addr;
101 
102 #if defined(_KERNEL_OPT)
103 #include "opt_ddb.h"
104 #endif
105 
106 #ifdef DDB
107 #define	integrate
108 #define hide
109 #else
110 #define	integrate	static __inline
111 #define hide		static
112 #endif
113 
114 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
115 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
116 int leintr(int);
117 
118 hide void
119 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t 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 uint16_t
128 lerdcsr(struct lance_softc *sc, uint16_t port)
129 {
130 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
131 	uint16_t val;
132 
133 	ler1->ler1_rap = port;
134 	val = ler1->ler1_rdp;
135 	return val;
136 }
137 
138 int
139 le_match(struct device *parent, struct cfdata *cf, void *aux)
140 {
141 	struct hb_attach_args *ha = aux;
142 	int addr;
143 
144 	if (strcmp(ha->ha_name, "le"))
145 		return 0;
146 
147 	addr = IIOV(ha->ha_address);
148 
149 	if (badaddr((void *)addr, 1))
150 		return 0;
151 
152 	return 1;
153 }
154 
155 void
156 le_attach(struct device *parent, struct device *self, void *aux)
157 {
158 	struct le_softc *lesc = (struct le_softc *)self;
159 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
160 	struct hb_attach_args *ha = aux;
161 	u_char *p;
162 
163 	lesc->sc_r1 = (void *)IIOV(ha->ha_address);
164 
165 	if (ISIIOPA(ha->ha_address)) {
166 		sc->sc_mem = (u_char *)lance_mem;
167 		p = (u_char *)(idrom_addr + 0x10);
168 	} else {
169 		sc->sc_mem = lesc->sc_r1 - 0x10000;
170 		p = (u_char *)(lesc->sc_r1 + 0x8010);
171 	}
172 
173 	sc->sc_memsize = 0x4000;	/* 16K */
174 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
175 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
176 
177 	sc->sc_enaddr[0] = (*p++ << 4);
178 	sc->sc_enaddr[0] |= *p++ & 0x0f;
179 	sc->sc_enaddr[1] = (*p++ << 4);
180 	sc->sc_enaddr[1] |= *p++ & 0x0f;
181 	sc->sc_enaddr[2] = (*p++ << 4);
182 	sc->sc_enaddr[2] |= *p++ & 0x0f;
183 	sc->sc_enaddr[3] = (*p++ << 4);
184 	sc->sc_enaddr[3] |= *p++ & 0x0f;
185 	sc->sc_enaddr[4] = (*p++ << 4);
186 	sc->sc_enaddr[4] |= *p++ & 0x0f;
187 	sc->sc_enaddr[5] = (*p++ << 4);
188 	sc->sc_enaddr[5] |= *p++ & 0x0f;
189 
190 	sc->sc_copytodesc = lance_copytobuf_contig;
191 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
192 	sc->sc_copytobuf = lance_copytobuf_contig;
193 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
194 	sc->sc_zerobuf = lance_zerobuf_contig;
195 
196 	sc->sc_rdcsr = lerdcsr;
197 	sc->sc_wrcsr = lewrcsr;
198 	sc->sc_hwinit = NULL;
199 
200 	am7990_config(&lesc->sc_am7990);
201 }
202 
203 int
204 leintr(int unit)
205 {
206 	struct am7990_softc *sc;
207 
208 	if (unit >= le_cd.cd_ndevs)
209 		return 0;
210 
211 	sc = le_cd.cd_devs[unit];
212 	return am7990_intr(sc);
213 }
214