1 /* $NetBSD: if_le.c,v 1.60 2008/04/04 12:25:06 tsutsui Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1992, 1993
34 * The Regents of the University of California. All rights reserved.
36 * This code is derived from software contributed to Berkeley by
37 * Ralph Campbell and Rick Macklem.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
66 #include <sys/cdefs.h>
67 __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.60 2008/04/04 12:25:06 tsutsui Exp $");
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/device.h>
77 #include <net/if_ether.h>
78 #include <net/if_media.h>
80 #include <dev/ic/lancereg.h>
81 #include <dev/ic/lancevar.h>
82 #include <dev/ic/am7990var.h>
84 #include <hp300/dev/diovar.h>
85 #include <hp300/dev/diodevs.h>
86 #include <hp300/dev/if_lereg.h>
88 #include "opt_useleds.h"
91 #include <hp300/hp300/leds.h>
95 struct am7990_softc sc_am7990
; /* glue to MI code */
97 bus_space_tag_t sc_bst
;
99 bus_space_handle_t sc_bsh0
; /* DIO registers */
100 bus_space_handle_t sc_bsh1
; /* LANCE registers */
101 bus_space_handle_t sc_bsh2
; /* buffer area */
104 static int lematch(device_t
, cfdata_t
, void *);
105 static void leattach(device_t
, device_t
, void *);
107 CFATTACH_DECL_NEW(le
, sizeof(struct le_softc
),
108 lematch
, leattach
, NULL
, NULL
);
110 static int leintr(void *);
112 #if defined(_KERNEL_OPT)
116 static void le_copytobuf(struct lance_softc
*, void *, int, int);
117 static void le_copyfrombuf(struct lance_softc
*, void *, int, int);
118 static void le_zerobuf(struct lance_softc
*, int, int);
120 /* offsets for: ID, REGS, MEM, NVRAM */
121 static const int lestd
[] = { 0, 0x4000, 0x8000, 0xC008 };
124 lewrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
126 struct le_softc
*lesc
= (struct le_softc
*)sc
;
127 bus_space_tag_t bst
= lesc
->sc_bst
;
128 bus_space_handle_t bsh0
= lesc
->sc_bsh0
;
129 bus_space_handle_t bsh1
= lesc
->sc_bsh1
;
132 bus_space_write_2(bst
, bsh1
, LER1_RAP
, port
);
133 } while ((bus_space_read_1(bst
, bsh0
, LER0_STATUS
) & LE_ACK
) == 0);
135 bus_space_write_2(bst
, bsh1
, LER1_RDP
, val
);
136 } while ((bus_space_read_1(bst
, bsh0
, LER0_STATUS
) & LE_ACK
) == 0);
140 lerdcsr(struct lance_softc
*sc
, uint16_t port
)
142 struct le_softc
*lesc
= (struct le_softc
*)sc
;
143 bus_space_tag_t bst
= lesc
->sc_bst
;
144 bus_space_handle_t bsh0
= lesc
->sc_bsh0
;
145 bus_space_handle_t bsh1
= lesc
->sc_bsh1
;
149 bus_space_write_2(bst
, bsh1
, LER1_RAP
, port
);
150 } while ((bus_space_read_1(bst
, bsh0
, LER0_STATUS
) & LE_ACK
) == 0);
152 val
= bus_space_read_2(bst
, bsh1
, LER1_RDP
);
153 } while ((bus_space_read_1(bst
, bsh0
, LER0_STATUS
) & LE_ACK
) == 0);
159 lematch(device_t parent
, cfdata_t cf
, void *aux
)
161 struct dio_attach_args
*da
= aux
;
163 if (da
->da_id
== DIO_DEVICE_ID_LAN
)
169 * Interface exists: make available by filling in network interface
170 * record. System will initialize the interface when it is ready
174 leattach(device_t parent
, device_t self
, void *aux
)
176 struct le_softc
*lesc
= device_private(self
);
177 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
178 struct dio_attach_args
*da
= aux
;
179 bus_space_tag_t bst
= da
->da_bst
;
180 bus_space_handle_t bsh0
, bsh1
, bsh2
;
186 if (bus_space_map(bst
, (bus_addr_t
)dio_scodetopa(da
->da_scode
),
187 da
->da_size
, 0, &bsh0
)) {
188 aprint_error(": can't map LANCE registers\n");
192 if (bus_space_subregion(bst
, bsh0
, lestd
[1], LER1_SIZE
, &bsh1
)) {
193 aprint_error(": can't subregion LANCE space\n");
197 if (bus_space_subregion(bst
, bsh0
, lestd
[2], LE_BUFSIZE
, &bsh2
)) {
198 aprint_error(": can't subregion buffer space\n");
203 lesc
->sc_bsh0
= bsh0
;
204 lesc
->sc_bsh1
= bsh1
;
205 lesc
->sc_bsh2
= bsh2
;
207 bus_space_write_1(bst
, bsh0
, LER0_ID
, 0xff);
210 sc
->sc_conf3
= LE_C3_BSWP
;
212 sc
->sc_memsize
= LE_BUFSIZE
;
215 * Read the ethernet address off the board, one nibble at a time.
218 for (i
= 0; i
< sizeof(sc
->sc_enaddr
); i
++) {
220 (bus_space_read_1(bst
, bsh0
, ++offset
) & 0xf) << 4;
223 (bus_space_read_1(bst
, bsh0
, ++offset
) & 0xf);
227 sc
->sc_copytodesc
= le_copytobuf
;
228 sc
->sc_copyfromdesc
= le_copyfrombuf
;
229 sc
->sc_copytobuf
= le_copytobuf
;
230 sc
->sc_copyfrombuf
= le_copyfrombuf
;
231 sc
->sc_zerobuf
= le_zerobuf
;
233 sc
->sc_rdcsr
= lerdcsr
;
234 sc
->sc_wrcsr
= lewrcsr
;
235 sc
->sc_hwinit
= NULL
;
237 am7990_config(&lesc
->sc_am7990
);
239 /* Establish the interrupt handler. */
240 (void) dio_intr_establish(leintr
, sc
, da
->da_ipl
, IPL_NET
);
241 bus_space_write_1(bst
, bsh0
, LER0_STATUS
, LE_IE
);
247 struct lance_softc
*sc
= arg
;
251 isr
= lerdcsr(sc
, LE_CSR0
);
253 if ((isr
& LE_C0_INTR
) == 0)
256 if (isr
& LE_C0_RINT
)
257 ledcontrol(0, 0, LED_LANRCV
);
259 if (isr
& LE_C0_TINT
)
260 ledcontrol(0, 0, LED_LANXMT
);
263 return am7990_intr(sc
);
267 le_copytobuf(struct lance_softc
*sc
, void *from
, int boff
, int len
)
269 struct le_softc
*lesc
= (struct le_softc
*)sc
;
271 bus_space_write_region_1(lesc
->sc_bst
, lesc
->sc_bsh2
, boff
, from
, len
);
275 le_copyfrombuf(struct lance_softc
*sc
, void *to
, int boff
, int len
)
277 struct le_softc
*lesc
= (struct le_softc
*)sc
;
279 bus_space_read_region_1(lesc
->sc_bst
, lesc
->sc_bsh2
, boff
, to
, len
);
283 le_zerobuf(struct lance_softc
*sc
, int boff
, int len
)
285 struct le_softc
*lesc
= (struct le_softc
*)sc
;
287 bus_space_set_region_1(lesc
->sc_bst
, lesc
->sc_bsh2
, boff
, 0, len
);