1 /* $NetBSD: if_le.c,v 1.4 2005/12/11 12:17:52 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell and Rick Macklem.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
38 * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
40 * This code is derived from software contributed to Berkeley by
41 * Ralph Campbell and Rick Macklem.
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
74 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
76 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.4 2005/12/11 12:17:52 christos Exp $");
81 #include <sys/param.h>
82 #include <sys/systm.h>
84 #include <sys/socket.h>
85 #include <sys/device.h>
88 #include <net/if_ether.h>
89 #include <net/if_media.h>
92 #include <netinet/in.h>
93 #include <netinet/if_inarp.h>
96 #include <machine/cpu.h>
97 #include <machine/autoconf.h>
99 #include <luna68k/luna68k/isr.h>
101 #include <dev/ic/lancereg.h>
102 #include <dev/ic/lancevar.h>
103 #include <dev/ic/am7990reg.h>
104 #include <dev/ic/am7990var.h>
112 volatile uint16_t ler1_rdp
; /* data port */
113 volatile uint16_t ler1_rap
; /* register select port */
117 * Ethernet software status per interface.
119 * Each interface is referenced by a network interface structure,
120 * arpcom.ac_if, which the routing code uses to locate the interface.
121 * This structure contains the output queue for the interface, its address, ...
124 struct am7990_softc sc_am7990
; /* glue to MI code */
126 struct lereg1
*sc_r1
; /* LANCE registers */
129 static int le_match(device_t
, cfdata_t
, void *);
130 static void le_attach(device_t
, device_t
, void *);
132 CFATTACH_DECL_NEW(le
, sizeof(struct le_softc
),
133 le_match
, le_attach
, NULL
, NULL
);
135 static void lesrcsr(struct lance_softc
*, uint16_t, uint16_t);
136 static uint16_t lerdcsr(struct lance_softc
*, uint16_t);
137 static void myetheraddr(uint8_t *);
140 lesrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
142 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
144 ler1
->ler1_rap
= port
;
145 ler1
->ler1_rdp
= val
;
149 lerdcsr(struct lance_softc
*sc
, uint16_t port
)
151 struct lereg1
*ler1
= ((struct le_softc
*)sc
)->sc_r1
;
154 ler1
->ler1_rap
= port
;
155 val
= ler1
->ler1_rdp
;
160 le_match(device_t parent
, cfdata_t cf
, void *aux
)
162 struct mainbus_attach_args
*ma
= aux
;
164 if (strcmp(ma
->ma_name
, le_cd
.cd_name
))
171 le_attach(device_t parent
, device_t self
, void *aux
)
173 struct le_softc
*lesc
= device_private(self
);
174 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
175 struct mainbus_attach_args
*ma
= aux
;
179 /* Map control registers. */
180 lesc
->sc_r1
= (struct lereg1
*)ma
->ma_addr
; /* LANCE */
182 sc
->sc_mem
= (void *)0x71010000; /* SRAM */
183 sc
->sc_conf3
= LE_C3_BSWP
;
184 sc
->sc_addr
= (u_long
)sc
->sc_mem
& 0xffffff;
185 sc
->sc_memsize
= 64 * 1024; /* 64KB */
187 myetheraddr(sc
->sc_enaddr
);
189 sc
->sc_copytodesc
= lance_copytobuf_contig
;
190 sc
->sc_copyfromdesc
= lance_copyfrombuf_contig
;
191 sc
->sc_copytobuf
= lance_copytobuf_contig
;
192 sc
->sc_copyfrombuf
= lance_copyfrombuf_contig
;
193 sc
->sc_zerobuf
= lance_zerobuf_contig
;
195 sc
->sc_rdcsr
= lerdcsr
;
196 sc
->sc_wrcsr
= lesrcsr
;
197 sc
->sc_hwinit
= NULL
;
199 am7990_config(&lesc
->sc_am7990
);
201 isrlink_autovec(am7990_intr
, (void *)sc
, ma
->ma_ilvl
, ISRPRI_NET
);
205 * LUNA-I has 1Mbit CPU ROM, which contains MAC address directly
206 * readable at 0x4100FFE0 as a sequence of 12 ASCII characters.
208 * LUNA-II has 16Kbit NVSRAM on its ethercard, whose contents are
209 * accessible 4bit-wise by ctl register operation. The register is
210 * mapped at 0xF1000004.
213 myetheraddr(uint8_t *ether
)
217 volatile struct { uint32_t ctl
; } *ds1220
;
221 ea
= (uint8_t *)0x4101FFE0;
222 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++) {
226 u
= (u
< 'A') ? u
& 0xf : u
- 'A' + 10;
228 l
= (l
< 'A') ? l
& 0xf : l
- 'A' + 10;
230 ether
[i
] = l
| (u
<< 4);
235 ds1220
= (void *)0xF1000004;
237 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++) {
238 unsigned int u
, l
, hex
;
240 ds1220
->ctl
= (loc
) << 16;
241 u
= 0xf0 & (ds1220
->ctl
>> 12);
242 ds1220
->ctl
= (loc
+ 1) << 16;
243 l
= 0x0f & (ds1220
->ctl
>> 16);
244 hex
= (u
< '9') ? l
: l
+ 9;
246 ds1220
->ctl
= (loc
+ 2) << 16;
247 u
= 0xf0 & (ds1220
->ctl
>> 12);
248 ds1220
->ctl
= (loc
+ 3) << 16;
249 l
= 0x0f & (ds1220
->ctl
>> 16);
251 ether
[i
] = ((u
< '9') ? l
: l
+ 9) | (hex
<< 4);
256 ether
[0] = 0x00; ether
[1] = 0x00; ether
[2] = 0x0a;
257 ether
[3] = 0xDE; ether
[4] = 0xAD; ether
[5] = 0x00;