xref: /netbsd-src/sys/arch/newsmips/dev/if_le.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: if_le.c,v 1.15 2005/12/24 20:07:24 perry 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.15 2005/12/24 20:07:24 perry 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/cpu.h>
62 #include <machine/adrsmap.h>
63 
64 #include <dev/ic/lancereg.h>
65 #include <dev/ic/lancevar.h>
66 #include <dev/ic/am7990reg.h>
67 #include <dev/ic/am7990var.h>
68 
69 #include <newsmips/dev/hbvar.h>
70 
71 /*
72  * LANCE registers.
73  * The real stuff is in dev/ic/am7990reg.h
74  */
75 struct lereg1 {
76 	volatile uint16_t	ler1_rdp;	/* data port */
77 	volatile uint16_t	ler1_rap;	/* register select port */
78 };
79 
80 /*
81  * Ethernet software status per interface.
82  * The real stuff is in dev/ic/am7990var.h
83  */
84 struct	le_softc {
85 	struct	am7990_softc sc_am7990;	/* glue to MI code */
86 
87 	struct	lereg1 *sc_r1;		/* LANCE registers */
88 };
89 
90 static int	le_match(struct device *, struct cfdata *, void *);
91 static void	le_attach(struct device *, struct device *, void *);
92 
93 CFATTACH_DECL(le, sizeof(struct le_softc),
94     le_match, le_attach, NULL, NULL);
95 
96 #if defined(_KERNEL_OPT)
97 #include "opt_ddb.h"
98 #endif
99 
100 #ifdef DDB
101 #define	integrate
102 #define hide
103 #else
104 #define	integrate	static inline
105 #define hide		static
106 #endif
107 
108 hide void lewrcsr(struct lance_softc *, uint16_t, uint16_t);
109 hide uint16_t lerdcsr(struct lance_softc *, uint16_t);
110 
111 hide void
112 lewrcsr(struct lance_softc *sc, uint16_t port, uint16_t val)
113 {
114 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
115 
116 	ler1->ler1_rap = port;
117 	ler1->ler1_rdp = val;
118 }
119 
120 hide uint16_t
121 lerdcsr(struct lance_softc *sc, uint16_t port)
122 {
123 	struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
124 	uint16_t val;
125 
126 	ler1->ler1_rap = port;
127 	val = ler1->ler1_rdp;
128 	return val;
129 }
130 
131 int
132 le_match(struct device *parent, struct cfdata *cf, void *aux)
133 {
134 	struct hb_attach_args *ha = aux;
135 
136 	if (strcmp(ha->ha_name, "le"))
137 		return 0;
138 
139 	if (hb_badaddr((void *)ha->ha_addr, 1)) /* XXX */
140 		return 0;
141 
142 	return 1;
143 }
144 
145 void
146 le_attach(struct device *parent, struct device *self, void *aux)
147 {
148 	struct le_softc *lesc = (struct le_softc *)self;
149 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
150 	struct hb_attach_args *ha = aux;
151 	int intlevel, intmask;
152 	u_char *p;
153 
154 	intlevel = ha->ha_level;
155 	if (intlevel == -1) {
156 		printf(": interrupt level not configured\n");
157 		return;
158 	}
159 	printf(" level %d", intlevel);
160 
161 	switch (ha->ha_addr) {
162 
163 	case LANCE_PORT:
164 		sc->sc_mem = (void *)LANCE_MEMORY;
165 		p = (u_char *)(ETHER_ID + 16);
166 		intmask = INTST1_LANCE;
167 		break;
168 	case LANCE_PORT1:
169 		sc->sc_mem = (void *)LANCE_MEMORY1;
170 		p = (u_char *)(ETHER_ID1 + 16);
171 		intmask = INTST1_SLOT3; /* XXX not tested */
172 		break;
173 	case LANCE_PORT2:
174 		sc->sc_mem = (void *)LANCE_MEMORY2;
175 		p = (u_char *)(ETHER_ID2 + 16);
176 		intmask = INTST1_SLOT3; /* XXX not tested */
177 		break;
178 
179 	default:
180 		printf(": unknown LANCE addr\n");
181 		return;
182 	}
183 
184 	lesc->sc_r1 = (void *)ha->ha_addr;
185 
186 	sc->sc_memsize = 0x4000;	/* 16K */
187 	sc->sc_addr = (int)sc->sc_mem & 0x00ffffff;
188 	sc->sc_conf3 = LE_C3_BSWP|LE_C3_BCON;
189 
190 	sc->sc_enaddr[0] = (*p++ << 4);
191 	sc->sc_enaddr[0] |= *p++ & 0x0f;
192 	sc->sc_enaddr[1] = (*p++ << 4);
193 	sc->sc_enaddr[1] |= *p++ & 0x0f;
194 	sc->sc_enaddr[2] = (*p++ << 4);
195 	sc->sc_enaddr[2] |= *p++ & 0x0f;
196 	sc->sc_enaddr[3] = (*p++ << 4);
197 	sc->sc_enaddr[3] |= *p++ & 0x0f;
198 	sc->sc_enaddr[4] = (*p++ << 4);
199 	sc->sc_enaddr[4] |= *p++ & 0x0f;
200 	sc->sc_enaddr[5] = (*p++ << 4);
201 	sc->sc_enaddr[5] |= *p++ & 0x0f;
202 
203 	sc->sc_copytodesc = lance_copytobuf_contig;
204 	sc->sc_copyfromdesc = lance_copyfrombuf_contig;
205 	sc->sc_copytobuf = lance_copytobuf_contig;
206 	sc->sc_copyfrombuf = lance_copyfrombuf_contig;
207 	sc->sc_zerobuf = lance_zerobuf_contig;
208 
209 	sc->sc_rdcsr = lerdcsr;
210 	sc->sc_wrcsr = lewrcsr;
211 	sc->sc_hwinit = NULL;
212 
213 	am7990_config(&lesc->sc_am7990);
214 	hb_intr_establish(intlevel, intmask, IPL_NET, am7990_intr, sc);
215 }
216